commit 7c2abff1e13f6172771c3fe36aa580cdaa56b11e (tree)
parent 6929a5f44026cec8162fe713668b02e0e02bdfcc
Author: Jakub Konka <kubkon@jakubkonka.com>
Date: Mon, 23 Sep 2024 07:01:30 +0200
elf: only allocate __dso_handle symbol if not found in any object
Diffstat:
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/src/link/Elf/LinkerDefined.zig b/src/link/Elf/LinkerDefined.zig
@@ -47,7 +47,7 @@ fn newSymbolAssumeCapacity(self: *LinkerDefined, name_off: u32, elf_file: *Elf)
const esym = self.symtab.addOneAssumeCapacity();
esym.* = .{
.st_name = name_off,
- .st_info = elf.STB_GLOBAL << 4,
+ .st_info = elf.STB_WEAK << 4,
.st_other = @intFromEnum(elf.STV.HIDDEN),
.st_shndx = elf.SHN_ABS,
.st_value = 0,
@@ -255,8 +255,10 @@ pub fn allocateSymbols(self: *LinkerDefined, elf_file: *Elf) void {
// __dso_handle
if (self.dso_handle_index) |index| {
- const shdr = shdrs[1];
- allocSymbol(self, index, shdr.sh_addr, 0, elf_file);
+ if (self.resolveSymbol(index, elf_file).file == self.index) {
+ const shdr = shdrs[1];
+ allocSymbol(self, index, shdr.sh_addr, 0, elf_file);
+ }
}
// __GNU_EH_FRAME_HDR