| author | |
| committer | |
| log | 8c232922bdf21d9936db94447da21ac0dd9ec319 |
| tree | 4f6b54398e61b197a9e24295fcf8d6a0878506be |
| parent | d83a3f1746c81026d1cf0244156513c9b5a2a9f6 |
| parent | e0acf432482efba4c92029a7dd18037f1607fc27 |
| signature |
elf: misc fixes4 files changed, 15 insertions(+), 17 deletions(-)
src/link/Elf/LinkerDefined.zig+5-4| ... | @@ -47,7 +47,7 @@ fn newSymbolAssumeCapacity(self: *LinkerDefined, name_off: u32, elf_file: *Elf) | ... | @@ -47,7 +47,7 @@ fn newSymbolAssumeCapacity(self: *LinkerDefined, name_off: u32, elf_file: *Elf) |
| 47 | const esym = self.symtab.addOneAssumeCapacity(); | 47 | const esym = self.symtab.addOneAssumeCapacity(); |
| 48 | esym.* = .{ | 48 | esym.* = .{ |
| 49 | .st_name = name_off, | 49 | .st_name = name_off, |
| 50 | .st_info = elf.STB_GLOBAL << 4, | 50 | .st_info = elf.STB_WEAK << 4, |
| 51 | .st_other = @intFromEnum(elf.STV.HIDDEN), | 51 | .st_other = @intFromEnum(elf.STV.HIDDEN), |
| 52 | .st_shndx = elf.SHN_ABS, | 52 | .st_shndx = elf.SHN_ABS, |
| 53 | .st_value = 0, | 53 | .st_value = 0, |
| ... | @@ -158,7 +158,6 @@ pub fn initStartStopSymbols(self: *LinkerDefined, elf_file: *Elf) !void { | ... | @@ -158,7 +158,6 @@ pub fn initStartStopSymbols(self: *LinkerDefined, elf_file: *Elf) !void { |
| 158 | .index = index, | 158 | .index = index, |
| 159 | .file = self.index, | 159 | .file = self.index, |
| 160 | }, elf_file); | 160 | }, elf_file); |
| 161 | assert(!gop.found_existing); | ||
| 162 | gop.ref.* = .{ .index = index, .file = self.index }; | 161 | gop.ref.* = .{ .index = index, .file = self.index }; |
| 163 | self.symbols_resolver.appendAssumeCapacity(gop.index); | 162 | self.symbols_resolver.appendAssumeCapacity(gop.index); |
| 164 | } | 163 | } |
| ... | @@ -255,8 +254,10 @@ pub fn allocateSymbols(self: *LinkerDefined, elf_file: *Elf) void { | ... | @@ -255,8 +254,10 @@ pub fn allocateSymbols(self: *LinkerDefined, elf_file: *Elf) void { |
| 255 | 254 | ||
| 256 | // __dso_handle | 255 | // __dso_handle |
| 257 | if (self.dso_handle_index) |index| { | 256 | if (self.dso_handle_index) |index| { |
| 258 | const shdr = shdrs[1]; | 257 | if (self.resolveSymbol(index, elf_file).file == self.index) { |
| 259 | allocSymbol(self, index, shdr.sh_addr, 0, elf_file); | 258 | const shdr = shdrs[1]; |
| 259 | allocSymbol(self, index, shdr.sh_addr, 0, elf_file); | ||
| 260 | } | ||
| 260 | } | 261 | } |
| 261 | 262 | ||
| 262 | // __GNU_EH_FRAME_HDR | 263 | // __GNU_EH_FRAME_HDR |
src/link/Elf/Object.zig+5-6| ... | @@ -524,12 +524,6 @@ pub fn resolveSymbols(self: *Object, elf_file: *Elf) !void { | ... | @@ -524,12 +524,6 @@ pub fn resolveSymbols(self: *Object, elf_file: *Elf) !void { |
| 524 | const first_global = self.first_global orelse return; | 524 | const first_global = self.first_global orelse return; |
| 525 | for (self.globals(), first_global..) |_, i| { | 525 | for (self.globals(), first_global..) |_, i| { |
| 526 | const esym = self.symtab.items[i]; | 526 | const esym = self.symtab.items[i]; |
| 527 | if (esym.st_shndx != elf.SHN_ABS and esym.st_shndx != elf.SHN_COMMON and esym.st_shndx != elf.SHN_UNDEF) { | ||
| 528 | const atom_index = self.atoms_indexes.items[esym.st_shndx]; | ||
| 529 | const atom_ptr = self.atom(atom_index) orelse continue; | ||
| 530 | if (!atom_ptr.alive) continue; | ||
| 531 | } | ||
| 532 | |||
| 533 | const resolv = &self.symbols_resolver.items[i - first_global]; | 527 | const resolv = &self.symbols_resolver.items[i - first_global]; |
| 534 | const gop = try elf_file.resolver.getOrPut(gpa, .{ | 528 | const gop = try elf_file.resolver.getOrPut(gpa, .{ |
| 535 | .index = @intCast(i), | 529 | .index = @intCast(i), |
| ... | @@ -541,6 +535,11 @@ pub fn resolveSymbols(self: *Object, elf_file: *Elf) !void { | ... | @@ -541,6 +535,11 @@ pub fn resolveSymbols(self: *Object, elf_file: *Elf) !void { |
| 541 | resolv.* = gop.index; | 535 | resolv.* = gop.index; |
| 542 | 536 | ||
| 543 | if (esym.st_shndx == elf.SHN_UNDEF) continue; | 537 | if (esym.st_shndx == elf.SHN_UNDEF) continue; |
| 538 | if (esym.st_shndx != elf.SHN_ABS and esym.st_shndx != elf.SHN_COMMON) { | ||
| 539 | const atom_index = self.atoms_indexes.items[esym.st_shndx]; | ||
| 540 | const atom_ptr = self.atom(atom_index) orelse continue; | ||
| 541 | if (!atom_ptr.alive) continue; | ||
| 542 | } | ||
| 544 | if (elf_file.symbol(gop.ref.*) == null) { | 543 | if (elf_file.symbol(gop.ref.*) == null) { |
| 545 | gop.ref.* = .{ .index = @intCast(i), .file = self.index }; | 544 | gop.ref.* = .{ .index = @intCast(i), .file = self.index }; |
| 546 | continue; | 545 | continue; |
src/link/Elf/Symbol.zig-1| ... | @@ -471,7 +471,6 @@ pub const Extra = struct { | ... | @@ -471,7 +471,6 @@ pub const Extra = struct { |
| 471 | tlsgd: u32 = 0, | 471 | tlsgd: u32 = 0, |
| 472 | gottp: u32 = 0, | 472 | gottp: u32 = 0, |
| 473 | tlsdesc: u32 = 0, | 473 | tlsdesc: u32 = 0, |
| 474 | merge_section: u32 = 0, | ||
| 475 | trampoline: u32 = 0, | 474 | trampoline: u32 = 0, |
| 476 | }; | 475 | }; |
| 477 | 476 |
src/link/Elf/ZigObject.zig+5-6| ... | @@ -603,12 +603,6 @@ pub fn resolveSymbols(self: *ZigObject, elf_file: *Elf) !void { | ... | @@ -603,12 +603,6 @@ pub fn resolveSymbols(self: *ZigObject, elf_file: *Elf) !void { |
| 603 | const global = &self.symbols.items[index]; | 603 | const global = &self.symbols.items[index]; |
| 604 | const esym = global.elfSym(elf_file); | 604 | const esym = global.elfSym(elf_file); |
| 605 | const shndx = self.symtab.items(.shndx)[global.esym_index]; | 605 | const shndx = self.symtab.items(.shndx)[global.esym_index]; |
| 606 | if (esym.st_shndx != elf.SHN_ABS and esym.st_shndx != elf.SHN_COMMON and esym.st_shndx != elf.SHN_UNDEF) { | ||
| 607 | assert(esym.st_shndx == SHN_ATOM); | ||
| 608 | const atom_ptr = self.atom(shndx) orelse continue; | ||
| 609 | if (!atom_ptr.alive) continue; | ||
| 610 | } | ||
| 611 | |||
| 612 | const resolv = &self.symbols_resolver.items[i]; | 606 | const resolv = &self.symbols_resolver.items[i]; |
| 613 | const gop = try elf_file.resolver.getOrPut(gpa, .{ | 607 | const gop = try elf_file.resolver.getOrPut(gpa, .{ |
| 614 | .index = @intCast(i | global_symbol_bit), | 608 | .index = @intCast(i | global_symbol_bit), |
| ... | @@ -620,6 +614,11 @@ pub fn resolveSymbols(self: *ZigObject, elf_file: *Elf) !void { | ... | @@ -620,6 +614,11 @@ pub fn resolveSymbols(self: *ZigObject, elf_file: *Elf) !void { |
| 620 | resolv.* = gop.index; | 614 | resolv.* = gop.index; |
| 621 | 615 | ||
| 622 | if (esym.st_shndx == elf.SHN_UNDEF) continue; | 616 | if (esym.st_shndx == elf.SHN_UNDEF) continue; |
| 617 | if (esym.st_shndx != elf.SHN_ABS and esym.st_shndx != elf.SHN_COMMON) { | ||
| 618 | assert(esym.st_shndx == SHN_ATOM); | ||
| 619 | const atom_ptr = self.atom(shndx) orelse continue; | ||
| 620 | if (!atom_ptr.alive) continue; | ||
| 621 | } | ||
| 623 | if (elf_file.symbol(gop.ref.*) == null) { | 622 | if (elf_file.symbol(gop.ref.*) == null) { |
| 624 | gop.ref.* = .{ .index = @intCast(i | global_symbol_bit), .file = self.index }; | 623 | gop.ref.* = .{ .index = @intCast(i | global_symbol_bit), .file = self.index }; |
| 625 | continue; | 624 | continue; |