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.
This commit is contained in:
Kenta Iwasaki 2021-12-20 00:30:49 +09:00 committed by Andrew Kelley
parent 16b7535497
commit 5c7f2ab011
4 changed files with 11 additions and 1 deletions

View file

@ -118,6 +118,11 @@ const sys_can_stack_trace = switch (builtin.cpu.arch) {
.wasm64,
=> builtin.os.tag == .emscripten,
// `@returnAddress()` is unsupported in LLVM 13.
.bpfel,
.bpfeb,
=> false,
else => true,
};
const default_test_stack_trace_frames: usize = if (builtin.is_test) 8 else 4;

View file

@ -6208,7 +6208,7 @@ static LLVMValueRef ir_render_breakpoint(CodeGen *g, Stage1Air *executable, Stag
static LLVMValueRef ir_render_return_address(CodeGen *g, Stage1Air *executable,
Stage1AirInstReturnAddress *instruction)
{
if (target_is_wasm(g->zig_target) && g->zig_target->os != OsEmscripten) {
if ((target_is_wasm(g->zig_target) && g->zig_target->os != OsEmscripten) || target_is_bpf(g->zig_target)) {
// I got this error from LLVM 10:
// "Non-Emscripten WebAssembly hasn't implemented __builtin_return_address"
return LLVMConstNull(get_llvm_type(g, instruction->base.value->type));

View file

@ -940,6 +940,10 @@ bool target_is_wasm(const ZigTarget *target) {
return target->arch == ZigLLVM_wasm32 || target->arch == ZigLLVM_wasm64;
}
bool target_is_bpf(const ZigTarget *target) {
return target->arch == ZigLLVM_bpfel || target->arch == ZigLLVM_bpfeb;
}
ZigLLVM_EnvironmentType target_default_abi(ZigLLVM_ArchType arch, Os os) {
if (arch == ZigLLVM_wasm32 || arch == ZigLLVM_wasm64) {
return ZigLLVM_Musl;

View file

@ -75,6 +75,7 @@ bool target_allows_addr_zero(const ZigTarget *target);
bool target_has_valgrind_support(const ZigTarget *target);
bool target_os_is_darwin(Os os);
bool target_is_wasm(const ZigTarget *target);
bool target_is_bpf(const ZigTarget *target);
bool target_is_riscv(const ZigTarget *target);
bool target_is_sparc(const ZigTarget *target);
bool target_is_android(const ZigTarget *target);