aboutsummaryrefslogtreecommitdiff
path: root/src/link/Elf/ZigObject.zig
diff options
context:
space:
mode:
authorJakub Konka <kubkon@jakubkonka.com>2024-01-15 07:37:09 +0100
committerGitHub <noreply@github.com>2024-01-15 07:37:09 +0100
commit3dddb881bfefbcd64aae7775ed72c42e37503674 (patch)
treed3a8523750581848381b796a3de59fc05b66c64f /src/link/Elf/ZigObject.zig
parent852e7e24b5f15b489463bdabb0039e2a424e5ee6 (diff)
parentb1ffc2b8b353f64362c27df2ecc44436db234a29 (diff)
downloadzig-3dddb881bfefbcd64aae7775ed72c42e37503674.tar.gz
zig-3dddb881bfefbcd64aae7775ed72c42e37503674.zip
Merge pull request #18560 from ziglang/elf-report-dupes
elf: report duplicate symbol definitions
Diffstat (limited to 'src/link/Elf/ZigObject.zig')
-rw-r--r--src/link/Elf/ZigObject.zig26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/link/Elf/ZigObject.zig b/src/link/Elf/ZigObject.zig
index a29c3ab69c..ef8509e915 100644
--- a/src/link/Elf/ZigObject.zig
+++ b/src/link/Elf/ZigObject.zig
@@ -451,6 +451,32 @@ pub fn markLive(self: *ZigObject, elf_file: *Elf) void {
}
}
+pub fn checkDuplicates(self: *ZigObject, dupes: anytype, elf_file: *Elf) error{OutOfMemory}!void {
+ for (self.globals(), 0..) |index, i| {
+ const esym = self.global_esyms.items(.elf_sym)[i];
+ const shndx = self.global_esyms.items(.shndx)[i];
+ const global = elf_file.symbol(index);
+ const global_file = global.file(elf_file) orelse continue;
+
+ if (self.index == global_file.index() or
+ esym.st_shndx == elf.SHN_UNDEF or
+ esym.st_bind() == elf.STB_WEAK or
+ esym.st_shndx == elf.SHN_COMMON) continue;
+
+ if (esym.st_shndx == SHN_ATOM) {
+ const atom_index = self.atoms.items[shndx];
+ const atom = elf_file.atom(atom_index) orelse continue;
+ if (!atom.flags.alive) continue;
+ }
+
+ const gop = try dupes.getOrPut(index);
+ if (!gop.found_existing) {
+ gop.value_ptr.* = .{};
+ }
+ try gop.value_ptr.append(elf_file.base.comp.gpa, self.index);
+ }
+}
+
/// This is just a temporary helper function that allows us to re-read what we wrote to file into a buffer.
/// We need this so that we can write to an archive.
/// TODO implement writing ZigObject data directly to a buffer instead.