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) {
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};
123128const 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
62086208static 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+4
......@@ -940,6 +940,10 @@ bool target_is_wasm(const ZigTarget *target) {
940940 return target->arch == ZigLLVM_wasm32 || target->arch == ZigLLVM_wasm64;
941941}
942942
943bool target_is_bpf(const ZigTarget *target) {
944 return target->arch == ZigLLVM_bpfel || target->arch == ZigLLVM_bpfeb;
945}
946
943947ZigLLVM_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+1
......@@ -75,6 +75,7 @@ bool target_allows_addr_zero(const ZigTarget *target);
7575bool target_has_valgrind_support(const ZigTarget *target);
7676bool target_os_is_darwin(Os os);
7777bool target_is_wasm(const ZigTarget *target);
78bool target_is_bpf(const ZigTarget *target);
7879bool target_is_riscv(const ZigTarget *target);
7980bool target_is_sparc(const ZigTarget *target);
8081bool target_is_android(const ZigTarget *target);