| author | |
| committer | |
| log | ab8a5bfe83848c0d0ceb7ac08fe7f535783e1605 |
| tree | 4105c2c6a1082a7e819244cb37dcd766b5844abf |
| parent | 8960df0c013f83a8adf05ce2ae9a9667d58ef41d |
3 files changed, 18 insertions(+), 1 deletions(-)
src/link/Elf.zig+1| ... | ... | @@ -1493,6 +1493,7 @@ fn resolveSymbols(self: *Elf) error{Overflow}!void { |
| 1493 | 1493 | /// This routine will prune unneeded objects extracted from archives and |
| 1494 | 1494 | /// unneeded shared objects. |
| 1495 | 1495 | fn markLive(self: *Elf) void { |
| 1496 | if (self.zig_module_index) |index| self.file(index).?.markLive(self); | |
| 1496 | 1497 | for (self.objects.items) |index| { |
| 1497 | 1498 | const file_ptr = self.file(index).?; |
| 1498 | 1499 | if (file_ptr.isAlive()) file_ptr.markLive(self); |
src/link/Elf/ZigModule.zig+16| ... | ... | @@ -155,6 +155,22 @@ pub fn resetGlobals(self: *ZigModule, elf_file: *Elf) void { |
| 155 | 155 | } |
| 156 | 156 | } |
| 157 | 157 | |
| 158 | pub fn markLive(self: *ZigModule, elf_file: *Elf) void { | |
| 159 | for (self.globals(), 0..) |index, i| { | |
| 160 | const esym = self.global_esyms.items[i]; | |
| 161 | if (esym.st_bind() == elf.STB_WEAK) continue; | |
| 162 | ||
| 163 | const global = elf_file.symbol(index); | |
| 164 | const file = global.file(elf_file) orelse continue; | |
| 165 | const should_keep = esym.st_shndx == elf.SHN_UNDEF or | |
| 166 | (esym.st_shndx == elf.SHN_COMMON and global.elfSym(elf_file).st_shndx != elf.SHN_COMMON); | |
| 167 | if (should_keep and !file.isAlive()) { | |
| 168 | file.setAlive(); | |
| 169 | file.markLive(elf_file); | |
| 170 | } | |
| 171 | } | |
| 172 | } | |
| 173 | ||
| 158 | 174 | pub fn updateSymtabSize(self: *ZigModule, elf_file: *Elf) void { |
| 159 | 175 | for (self.locals()) |local_index| { |
| 160 | 176 | const local = elf_file.symbol(local_index); |
src/link/Elf/file.zig+1-1| ... | ... | @@ -84,7 +84,7 @@ pub const File = union(enum) { |
| 84 | 84 | |
| 85 | 85 | pub fn markLive(file: File, elf_file: *Elf) void { |
| 86 | 86 | switch (file) { |
| 87 | .zig_module, .linker_defined => unreachable, | |
| 87 | .linker_defined => unreachable, | |
| 88 | 88 | inline else => |x| x.markLive(elf_file), |
| 89 | 89 | } |
| 90 | 90 | } |