authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-06 00:02:03+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-10-16 19:33:04+02:00
logdef7190e845eab3e0bf0f746129b737c8000b2b8
tree999490c9fc119dc7ce36fe3a1199d3b63873689c
parentf4c1b1d9ad7c90266b1da1892e9bcd1d6143f7ea

elf: hook up common symbols handler


2 files changed, 21 insertions(+), 14 deletions(-)

src/link/Elf.zig+7
...@@ -1652,6 +1652,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node...@@ -1652,6 +1652,7 @@ pub fn flushModule(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node
1652 // symbol for potential resolution at load-time.1652 // symbol for potential resolution at load-time.
1653 self.resolveSymbols();1653 self.resolveSymbols();
1654 self.markEhFrameAtomsDead();1654 self.markEhFrameAtomsDead();
1655 try self.convertCommonSymbols();
1655 self.markImportsExports();1656 self.markImportsExports();
16561657
1657 // Look for entry address in objects if not set by the incremental compiler.1658 // Look for entry address in objects if not set by the incremental compiler.
...@@ -2166,6 +2167,12 @@ fn markEhFrameAtomsDead(self: *Elf) void {...@@ -2166,6 +2167,12 @@ fn markEhFrameAtomsDead(self: *Elf) void {
2166 }2167 }
2167}2168}
21682169
2170fn convertCommonSymbols(self: *Elf) !void {
2171 for (self.objects.items) |index| {
2172 try self.file(index).?.object.convertCommonSymbols(self);
2173 }
2174}
2175
2169fn markImportsExports(self: *Elf) void {2176fn markImportsExports(self: *Elf) void {
2170 const mark = struct {2177 const mark = struct {
2171 fn mark(elf_file: *Elf, file_index: File.Index) void {2178 fn mark(elf_file: *Elf, file_index: File.Index) void {
src/link/Elf/Object.zig+14-14
...@@ -563,14 +563,14 @@ pub fn convertCommonSymbols(self: *Object, elf_file: *Elf) !void {...@@ -563,14 +563,14 @@ pub fn convertCommonSymbols(self: *Object, elf_file: *Elf) !void {
563 if (this_sym.st_shndx != elf.SHN_COMMON) continue;563 if (this_sym.st_shndx != elf.SHN_COMMON) continue;
564564
565 const global = elf_file.symbol(index);565 const global = elf_file.symbol(index);
566 const global_file = global.getFile(elf_file).?;566 const global_file = global.file(elf_file).?;
567 if (global_file.getIndex() != self.index) {567 if (global_file.index() != self.index) {
568 if (elf_file.options.warn_common) {568 // if (elf_file.options.warn_common) {
569 elf_file.base.warn("{}: multiple common symbols: {s}", .{569 // elf_file.base.warn("{}: multiple common symbols: {s}", .{
570 self.fmtPath(),570 // self.fmtPath(),
571 global.getName(elf_file),571 // global.getName(elf_file),
572 });572 // });
573 }573 // }
574 continue;574 continue;
575 }575 }
576576
...@@ -579,13 +579,13 @@ pub fn convertCommonSymbols(self: *Object, elf_file: *Elf) !void {...@@ -579,13 +579,13 @@ pub fn convertCommonSymbols(self: *Object, elf_file: *Elf) !void {
579 const atom_index = try elf_file.addAtom();579 const atom_index = try elf_file.addAtom();
580 try self.atoms.append(gpa, atom_index);580 try self.atoms.append(gpa, atom_index);
581581
582 const is_tls = global.getType(elf_file) == elf.STT_TLS;582 const is_tls = global.type(elf_file) == elf.STT_TLS;
583 const name = if (is_tls) ".tbss" else ".bss";583 const name = if (is_tls) ".tls_common" else ".common";
584584
585 const atom = elf_file.atom(atom_index).?;585 const atom = elf_file.atom(atom_index).?;
586 atom.atom_index = atom_index;586 atom.atom_index = atom_index;
587 atom.name = try elf_file.strtab.insert(gpa, name);587 atom.name_offset = try elf_file.strtab.insert(gpa, name);
588 atom.file = self.index;588 atom.file_index = self.index;
589 atom.size = this_sym.st_size;589 atom.size = this_sym.st_size;
590 const alignment = this_sym.st_value;590 const alignment = this_sym.st_value;
591 atom.alignment = Alignment.fromNonzeroByteUnits(alignment);591 atom.alignment = Alignment.fromNonzeroByteUnits(alignment);
...@@ -606,10 +606,10 @@ pub fn convertCommonSymbols(self: *Object, elf_file: *Elf) !void {...@@ -606,10 +606,10 @@ pub fn convertCommonSymbols(self: *Object, elf_file: *Elf) !void {
606 .sh_addralign = alignment,606 .sh_addralign = alignment,
607 .sh_entsize = 0,607 .sh_entsize = 0,
608 };608 };
609 atom.shndx = shndx;609 atom.input_section_index = shndx;
610610
611 global.value = 0;611 global.value = 0;
612 global.atom = atom_index;612 global.atom_index = atom_index;
613 global.flags.weak = false;613 global.flags.weak = false;
614 }614 }
615}615}