Open
Description
Zig Version
0.15.0-dev.375+8f8f37fb0
Steps to Reproduce and Observed Behavior
pub fn main() void {
// `var` to work around #23623
var weak: ?*const fn () callconv(.c) void = undefined;
weak = @extern(*const fn () callconv(.c) void, .{ .name = "does_not_exist", .linkage = .weak });
if (weak) |f| {
f();
}
}
$ zig run repro.zig -fno-llvm
error: undefined symbol: does_not_exist
note: referenced by repro.o:repro.main
Expected Behavior
A successful compilation and execution with no output, as happens when using LLVM:
$ zig run repro.zig -fllvm
$
If you build-obj
and then nm
the object file, you can see that the ELF linker just isn't marking the symbol as weak, whereas the LLVM backend does:
$ zig build-obj repro.zig -fllvm
$ nm repro.o | grep does_not_exist
w does_not_exist
$ zig build-obj repro.zig -fno-llvm
$ nm repro.o | grep does_not_exist
U does_not_exist