Skip to content

Commit 5c7f2ab

Browse files
lithdewandrewrk
authored andcommitted
stage1: deal with BPF not supporting @returnaddress()
Make `@returnAddress()` return for the BPF target, as the BPF target for the time being does not support probing for the return address. Stack traces for the general purpose allocator for the BPF target is also set to not be captured.
1 parent 16b7535 commit 5c7f2ab

File tree

4 files changed

+11
-1
lines changed

4 files changed

+11
-1
lines changed

lib/std/heap/general_purpose_allocator.zig

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ const sys_can_stack_trace = switch (builtin.cpu.arch) {
118118
.wasm64,
119119
=> builtin.os.tag == .emscripten,
120120

121+
// `@returnAddress()` is unsupported in LLVM 13.
122+
.bpfel,
123+
.bpfeb,
124+
=> false,
125+
121126
else => true,
122127
};
123128
const default_test_stack_trace_frames: usize = if (builtin.is_test) 8 else 4;

src/stage1/codegen.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6208,7 +6208,7 @@ static LLVMValueRef ir_render_breakpoint(CodeGen *g, Stage1Air *executable, Stag
62086208
static LLVMValueRef ir_render_return_address(CodeGen *g, Stage1Air *executable,
62096209
Stage1AirInstReturnAddress *instruction)
62106210
{
6211-
if (target_is_wasm(g->zig_target) && g->zig_target->os != OsEmscripten) {
6211+
if ((target_is_wasm(g->zig_target) && g->zig_target->os != OsEmscripten) || target_is_bpf(g->zig_target)) {
62126212
// I got this error from LLVM 10:
62136213
// "Non-Emscripten WebAssembly hasn't implemented __builtin_return_address"
62146214
return LLVMConstNull(get_llvm_type(g, instruction->base.value->type));

src/stage1/target.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -940,6 +940,10 @@ bool target_is_wasm(const ZigTarget *target) {
940940
return target->arch == ZigLLVM_wasm32 || target->arch == ZigLLVM_wasm64;
941941
}
942942

943+
bool target_is_bpf(const ZigTarget *target) {
944+
return target->arch == ZigLLVM_bpfel || target->arch == ZigLLVM_bpfeb;
945+
}
946+
943947
ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {
944948
if (arch == ZigLLVM_wasm32 || arch == ZigLLVM_wasm64) {
945949
return ZigLLVM_Musl;

src/stage1/target.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ bool target_allows_addr_zero(const ZigTarget *target);
7575
bool target_has_valgrind_support(const ZigTarget *target);
7676
bool target_os_is_darwin(Os os);
7777
bool target_is_wasm(const ZigTarget *target);
78+
bool target_is_bpf(const ZigTarget *target);
7879
bool target_is_riscv(const ZigTarget *target);
7980
bool target_is_sparc(const ZigTarget *target);
8081
bool target_is_android(const ZigTarget *target);

0 commit comments

Comments
 (0)