authorgravatar for kenta@lithdew.netKenta Iwasaki <kenta@lithdew.net> 2021-12-20 00:30:49+09:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-12-19 23:22:05-08:00
log5c7f2ab011f9c1cd522ab76a674d0acc5f397041
treea1f974af9f30bc09f32f82e189b58f6f73653c14
parent16b753549702e2fc662491a468dd3323e8a51042

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.

4 files changed, 11 insertions(+), 1 deletions(-)

lib/std/heap/general_purpose_allocator.zig+5
...@@ -118,6 +118,11 @@ const sys_can_stack_trace = switch (builtin.cpu.arch) {...@@ -118,6 +118,11 @@ const sys_can_stack_trace = switch (builtin.cpu.arch) {
118 .wasm64,118 .wasm64,
119 => builtin.os.tag == .emscripten,119 => builtin.os.tag == .emscripten,
120120
121 // `@returnAddress()` is unsupported in LLVM 13.
122 .bpfel,
123 .bpfeb,
124 => false,
125
121 else => true,126 else => true,
122};127};
123const default_test_stack_trace_frames: usize = if (builtin.is_test) 8 else 4;128const default_test_stack_trace_frames: usize = if (builtin.is_test) 8 else 4;
src/stage1/codegen.cpp+1-1
...@@ -6208,7 +6208,7 @@ static LLVMValueRef ir_render_breakpoint(CodeGen *g, Stage1Air *executable, Stag...@@ -6208,7 +6208,7 @@ static LLVMValueRef ir_render_breakpoint(CodeGen *g, Stage1Air *executable, Stag
6208static LLVMValueRef ir_render_return_address(CodeGen *g, Stage1Air *executable,6208static LLVMValueRef ir_render_return_address(CodeGen *g, Stage1Air *executable,
6209 Stage1AirInstReturnAddress *instruction)6209 Stage1AirInstReturnAddress *instruction)
6210{6210{
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)) {
6212 // I got this error from LLVM 10:6212 // I got this error from LLVM 10:
6213 // "Non-Emscripten WebAssembly hasn't implemented __builtin_return_address"6213 // "Non-Emscripten WebAssembly hasn't implemented __builtin_return_address"
6214 return LLVMConstNull(get_llvm_type(g, instruction->base.value->type));6214 return LLVMConstNull(get_llvm_type(g, instruction->base.value->type));
src/stage1/target.cpp+4
...@@ -940,6 +940,10 @@ bool target_is_wasm(const ZigTarget *target) {...@@ -940,6 +940,10 @@ bool target_is_wasm(const ZigTarget *target) {
940 return target->arch == ZigLLVM_wasm32 || target->arch == ZigLLVM_wasm64;940 return target->arch == ZigLLVM_wasm32 || target->arch == ZigLLVM_wasm64;
941}941}
942942
943bool target_is_bpf(const ZigTarget *target) {
944 return target->arch == ZigLLVM_bpfel || target->arch == ZigLLVM_bpfeb;
945}
946
943ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {947ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {
944 if (arch == ZigLLVM_wasm32 || arch == ZigLLVM_wasm64) {948 if (arch == ZigLLVM_wasm32 || arch == ZigLLVM_wasm64) {
945 return ZigLLVM_Musl;949 return ZigLLVM_Musl;
src/stage1/target.hpp+1
...@@ -75,6 +75,7 @@ bool target_allows_addr_zero(const ZigTarget *target);...@@ -75,6 +75,7 @@ bool target_allows_addr_zero(const ZigTarget *target);
75bool target_has_valgrind_support(const ZigTarget *target);75bool target_has_valgrind_support(const ZigTarget *target);
76bool target_os_is_darwin(Os os);76bool target_os_is_darwin(Os os);
77bool target_is_wasm(const ZigTarget *target);77bool target_is_wasm(const ZigTarget *target);
78bool target_is_bpf(const ZigTarget *target);
78bool target_is_riscv(const ZigTarget *target);79bool target_is_riscv(const ZigTarget *target);
79bool target_is_sparc(const ZigTarget *target);80bool target_is_sparc(const ZigTarget *target);
80bool target_is_android(const ZigTarget *target);81bool target_is_android(const ZigTarget *target);