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
16521652 // symbol for potential resolution at load-time.
16531653 self.resolveSymbols();
16541654 self.markEhFrameAtomsDead();
1655 try self.convertCommonSymbols();
16551656 self.markImportsExports();
16561657
16571658 // Look for entry address in objects if not set by the incremental compiler.
......@@ -2166,6 +2167,12 @@ fn markEhFrameAtomsDead(self: *Elf) void {
21662167 }
21672168}
21682169
2170fn convertCommonSymbols(self: *Elf) !void {
2171 for (self.objects.items) |index| {
2172 try self.file(index).?.object.convertCommonSymbols(self);
2173 }
2174}
2175
21692176fn markImportsExports(self: *Elf) void {
21702177 const mark = struct {
21712178 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 {
563563 if (this_sym.st_shndx != elf.SHN_COMMON) continue;
564564
565565 const global = elf_file.symbol(index);
566 const global_file = global.getFile(elf_file).?;
567 if (global_file.getIndex() != self.index) {
568 if (elf_file.options.warn_common) {
569 elf_file.base.warn("{}: multiple common symbols: {s}", .{
570 self.fmtPath(),
571 global.getName(elf_file),
572 });
573 }
566 const global_file = global.file(elf_file).?;
567 if (global_file.index() != self.index) {
568 // if (elf_file.options.warn_common) {
569 // elf_file.base.warn("{}: multiple common symbols: {s}", .{
570 // self.fmtPath(),
571 // global.getName(elf_file),
572 // });
573 // }
574574 continue;
575575 }
576576
......@@ -579,13 +579,13 @@ pub fn convertCommonSymbols(self: *Object, elf_file: *Elf) !void {
579579 const atom_index = try elf_file.addAtom();
580580 try self.atoms.append(gpa, atom_index);
581581
582 const is_tls = global.getType(elf_file) == elf.STT_TLS;
583 const name = if (is_tls) ".tbss" else ".bss";
582 const is_tls = global.type(elf_file) == elf.STT_TLS;
583 const name = if (is_tls) ".tls_common" else ".common";
584584
585585 const atom = elf_file.atom(atom_index).?;
586586 atom.atom_index = atom_index;
587 atom.name = try elf_file.strtab.insert(gpa, name);
588 atom.file = self.index;
587 atom.name_offset = try elf_file.strtab.insert(gpa, name);
588 atom.file_index = self.index;
589589 atom.size = this_sym.st_size;
590590 const alignment = this_sym.st_value;
591591 atom.alignment = Alignment.fromNonzeroByteUnits(alignment);
......@@ -606,10 +606,10 @@ pub fn convertCommonSymbols(self: *Object, elf_file: *Elf) !void {
606606 .sh_addralign = alignment,
607607 .sh_entsize = 0,
608608 };
609 atom.shndx = shndx;
609 atom.input_section_index = shndx;
610610
611611 global.value = 0;
612 global.atom = atom_index;
612 global.atom_index = atom_index;
613613 global.flags.weak = false;
614614 }
615615}