| author | |
| committer | |
| log | 96c20adeee84dbd86a7036cce49ef0c58870bdce |
| tree | 47dc611108a5b29db163554ac90104b65d027b73 |
| parent | c575e3daa4cdb39e38cc0b32fc8fe4a917947d34 |
8 files changed, 62 insertions(+), 74 deletions(-)
src/link/Elf.zig+4-4| ... | ... | @@ -1371,7 +1371,7 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod |
| 1371 | 1371 | var has_reloc_errors = false; |
| 1372 | 1372 | for (zo.atoms_indexes.items) |atom_index| { |
| 1373 | 1373 | const atom_ptr = zo.atom(atom_index) orelse continue; |
| 1374 | if (!atom_ptr.flags.alive) continue; | |
| 1374 | if (!atom_ptr.alive) continue; | |
| 1375 | 1375 | const out_shndx = atom_ptr.outputShndx() orelse continue; |
| 1376 | 1376 | const shdr = &self.shdrs.items[out_shndx]; |
| 1377 | 1377 | if (shdr.sh_type == elf.SHT_NOBITS) continue; |
| ... | ... | @@ -4130,7 +4130,7 @@ fn resetShdrIndexes(self: *Elf, backlinks: []const u32) !void { |
| 4130 | 4130 | for (zo.globals()) |global_index| { |
| 4131 | 4131 | const global = self.symbol(global_index); |
| 4132 | 4132 | const atom_ptr = global.atom(self) orelse continue; |
| 4133 | if (!atom_ptr.flags.alive) continue; | |
| 4133 | if (!atom_ptr.alive) continue; | |
| 4134 | 4134 | // TODO claim unresolved for objects |
| 4135 | 4135 | if (global.file(self).?.index() != zo.index) continue; |
| 4136 | 4136 | const out_shndx = global.outputShndx() orelse continue; |
| ... | ... | @@ -4157,7 +4157,7 @@ fn updateSectionSizes(self: *Elf) !void { |
| 4157 | 4157 | if (self.requiresThunks() and shdr.sh_flags & elf.SHF_EXECINSTR != 0) continue; |
| 4158 | 4158 | for (atom_list.items) |ref| { |
| 4159 | 4159 | const atom_ptr = self.atom(ref) orelse continue; |
| 4160 | if (!atom_ptr.flags.alive) continue; | |
| 4160 | if (!atom_ptr.alive) continue; | |
| 4161 | 4161 | const offset = atom_ptr.alignment.forward(shdr.sh_size); |
| 4162 | 4162 | const padding = offset - shdr.sh_size; |
| 4163 | 4163 | atom_ptr.value = @intCast(offset); |
| ... | ... | @@ -4641,7 +4641,7 @@ fn writeAtoms(self: *Elf) !void { |
| 4641 | 4641 | |
| 4642 | 4642 | for (atom_list.items) |ref| { |
| 4643 | 4643 | const atom_ptr = self.atom(ref).?; |
| 4644 | assert(atom_ptr.flags.alive); | |
| 4644 | assert(atom_ptr.alive); | |
| 4645 | 4645 | |
| 4646 | 4646 | const offset = math.cast(usize, atom_ptr.value - @as(i64, @intCast(base_offset))) orelse |
| 4647 | 4647 | return error.Overflow; |
src/link/Elf/Atom.zig+14-24| ... | ... | @@ -30,8 +30,11 @@ atom_index: Index = 0, |
| 30 | 30 | prev_index: Index = 0, |
| 31 | 31 | next_index: Index = 0, |
| 32 | 32 | |
| 33 | /// Flags we use for state tracking. | |
| 34 | flags: Flags = .{}, | |
| 33 | /// Specifies whether this atom is alive or has been garbage collected. | |
| 34 | alive: bool = true, | |
| 35 | ||
| 36 | /// Specifies if the atom has been visited during garbage collection. | |
| 37 | visited: bool = false, | |
| 35 | 38 | |
| 36 | 39 | extra_index: u32 = 0, |
| 37 | 40 | |
| ... | ... | @@ -55,7 +58,7 @@ pub fn debugTombstoneValue(self: Atom, target: Symbol, elf_file: *Elf) ?u64 { |
| 55 | 58 | if (msub.alive) return null; |
| 56 | 59 | } |
| 57 | 60 | if (target.atom(elf_file)) |atom_ptr| { |
| 58 | if (atom_ptr.flags.alive) return null; | |
| 61 | if (atom_ptr.alive) return null; | |
| 59 | 62 | } |
| 60 | 63 | const atom_name = self.name(elf_file); |
| 61 | 64 | if (!mem.startsWith(u8, atom_name, ".debug")) return null; |
| ... | ... | @@ -67,7 +70,6 @@ pub fn file(self: Atom, elf_file: *Elf) ?File { |
| 67 | 70 | } |
| 68 | 71 | |
| 69 | 72 | pub fn thunk(self: Atom, elf_file: *Elf) *Thunk { |
| 70 | assert(self.flags.thunk); | |
| 71 | 73 | const extras = self.extra(elf_file); |
| 72 | 74 | return elf_file.thunk(extras.thunk); |
| 73 | 75 | } |
| ... | ... | @@ -237,7 +239,7 @@ pub fn allocate(self: *Atom, elf_file: *Elf) !void { |
| 237 | 239 | _ = free_list.swapRemove(i); |
| 238 | 240 | } |
| 239 | 241 | |
| 240 | self.flags.alive = true; | |
| 242 | self.alive = true; | |
| 241 | 243 | } |
| 242 | 244 | |
| 243 | 245 | pub fn shrink(self: *Atom, elf_file: *Elf) void { |
| ... | ... | @@ -373,10 +375,12 @@ pub fn writeRelocs(self: Atom, elf_file: *Elf, out_relocs: *std.ArrayList(elf.El |
| 373 | 375 | } |
| 374 | 376 | |
| 375 | 377 | pub fn fdes(self: Atom, elf_file: *Elf) []Fde { |
| 376 | if (!self.flags.fde) return &[0]Fde{}; | |
| 377 | 378 | const extras = self.extra(elf_file); |
| 378 | const object = self.file(elf_file).?.object; | |
| 379 | return object.fdes.items[extras.fde_start..][0..extras.fde_count]; | |
| 379 | return switch (self.file(elf_file).?) { | |
| 380 | .shared_object => unreachable, | |
| 381 | .linker_defined, .zig_object => &[0]Fde{}, | |
| 382 | .object => |x| x.fdes.items[extras.fde_start..][0..extras.fde_count], | |
| 383 | }; | |
| 380 | 384 | } |
| 381 | 385 | |
| 382 | 386 | pub fn markFdesDead(self: Atom, elf_file: *Elf) void { |
| ... | ... | @@ -1066,7 +1070,7 @@ fn format2( |
| 1066 | 1070 | atom.atom_index, atom.name(elf_file), atom.address(elf_file), |
| 1067 | 1071 | atom.output_section_index, atom.alignment, atom.size, |
| 1068 | 1072 | }); |
| 1069 | if (atom.flags.fde) { | |
| 1073 | if (atom.fdes(elf_file).len > 0) { | |
| 1070 | 1074 | try writer.writeAll(" : fdes{ "); |
| 1071 | 1075 | const extras = atom.extra(elf_file); |
| 1072 | 1076 | for (atom.fdes(elf_file), extras.fde_start..) |fde, i| { |
| ... | ... | @@ -1076,27 +1080,13 @@ fn format2( |
| 1076 | 1080 | } |
| 1077 | 1081 | try writer.writeAll(" }"); |
| 1078 | 1082 | } |
| 1079 | if (!atom.flags.alive) { | |
| 1083 | if (!atom.alive) { | |
| 1080 | 1084 | try writer.writeAll(" : [*]"); |
| 1081 | 1085 | } |
| 1082 | 1086 | } |
| 1083 | 1087 | |
| 1084 | 1088 | pub const Index = u32; |
| 1085 | 1089 | |
| 1086 | pub const Flags = packed struct { | |
| 1087 | /// Specifies whether this atom is alive or has been garbage collected. | |
| 1088 | alive: bool = true, | |
| 1089 | ||
| 1090 | /// Specifies if the atom has been visited during garbage collection. | |
| 1091 | visited: bool = false, | |
| 1092 | ||
| 1093 | /// Whether this atom has a range extension thunk. | |
| 1094 | thunk: bool = false, | |
| 1095 | ||
| 1096 | /// Whether this atom has FDE records. | |
| 1097 | fde: bool = false, | |
| 1098 | }; | |
| 1099 | ||
| 1100 | 1090 | const x86_64 = struct { |
| 1101 | 1091 | fn scanReloc( |
| 1102 | 1092 | atom: Atom, |
src/link/Elf/Object.zig+16-17| ... | ... | @@ -84,7 +84,7 @@ pub fn parse(self: *Object, elf_file: *Elf) !void { |
| 84 | 84 | |
| 85 | 85 | for (self.shdrs.items, 0..) |shdr, i| { |
| 86 | 86 | const atom_ptr = self.atom(self.atoms_indexes.items[i]) orelse continue; |
| 87 | if (!atom_ptr.flags.alive) continue; | |
| 87 | if (!atom_ptr.alive) continue; | |
| 88 | 88 | if ((cpu_arch == .x86_64 and shdr.sh_type == elf.SHT_X86_64_UNWIND) or |
| 89 | 89 | mem.eql(u8, atom_ptr.name(elf_file), ".eh_frame")) |
| 90 | 90 | { |
| ... | ... | @@ -484,7 +484,6 @@ fn parseEhFrame(self: *Object, allocator: Allocator, handle: std.fs.File, shndx: |
| 484 | 484 | if (atom_ptr.atom_index != next_fde.atom(elf_file).atom_index) break; |
| 485 | 485 | } |
| 486 | 486 | atom_ptr.addExtra(.{ .fde_start = start, .fde_count = i - start }, elf_file); |
| 487 | atom_ptr.flags.fde = true; | |
| 488 | 487 | } |
| 489 | 488 | } |
| 490 | 489 | |
| ... | ... | @@ -529,7 +528,7 @@ pub fn scanRelocs(self: *Object, elf_file: *Elf, undefs: anytype) !void { |
| 529 | 528 | const gpa = comp.gpa; |
| 530 | 529 | for (self.atoms_indexes.items) |atom_index| { |
| 531 | 530 | const atom_ptr = self.atom(atom_index) orelse continue; |
| 532 | if (!atom_ptr.flags.alive) continue; | |
| 531 | if (!atom_ptr.alive) continue; | |
| 533 | 532 | const shdr = atom_ptr.inputShdr(elf_file); |
| 534 | 533 | if (shdr.sh_flags & elf.SHF_ALLOC == 0) continue; |
| 535 | 534 | if (shdr.sh_type == elf.SHT_NOBITS) continue; |
| ... | ... | @@ -569,7 +568,7 @@ pub fn resolveSymbols(self: *Object, elf_file: *Elf) void { |
| 569 | 568 | if (esym.st_shndx != elf.SHN_ABS and esym.st_shndx != elf.SHN_COMMON) { |
| 570 | 569 | const atom_index = self.atoms_indexes.items[esym.st_shndx]; |
| 571 | 570 | const atom_ptr = self.atom(atom_index) orelse continue; |
| 572 | if (!atom_ptr.flags.alive) continue; | |
| 571 | if (!atom_ptr.alive) continue; | |
| 573 | 572 | } |
| 574 | 573 | |
| 575 | 574 | const global = elf_file.symbol(index); |
| ... | ... | @@ -661,7 +660,7 @@ pub fn markEhFrameAtomsDead(self: *Object, elf_file: *Elf) void { |
| 661 | 660 | const atom_ptr = self.atom(atom_index) orelse continue; |
| 662 | 661 | const is_eh_frame = (cpu_arch == .x86_64 and atom_ptr.inputShdr(elf_file).sh_type == elf.SHT_X86_64_UNWIND) or |
| 663 | 662 | mem.eql(u8, atom_ptr.name(elf_file), ".eh_frame"); |
| 664 | if (atom_ptr.flags.alive and is_eh_frame) atom_ptr.flags.alive = false; | |
| 663 | if (atom_ptr.alive and is_eh_frame) atom_ptr.alive = false; | |
| 665 | 664 | } |
| 666 | 665 | } |
| 667 | 666 | |
| ... | ... | @@ -681,7 +680,7 @@ pub fn checkDuplicates(self: *Object, dupes: anytype, elf_file: *Elf) error{OutO |
| 681 | 680 | if (sym.st_shndx != elf.SHN_ABS) { |
| 682 | 681 | const atom_index = self.atoms_indexes.items[sym.st_shndx]; |
| 683 | 682 | const atom_ptr = self.atom(atom_index) orelse continue; |
| 684 | if (!atom_ptr.flags.alive) continue; | |
| 683 | if (!atom_ptr.alive) continue; | |
| 685 | 684 | } |
| 686 | 685 | |
| 687 | 686 | const gop = try dupes.getOrPut(index); |
| ... | ... | @@ -704,7 +703,7 @@ pub fn initMergeSections(self: *Object, elf_file: *Elf) !void { |
| 704 | 703 | |
| 705 | 704 | const atom_index = self.atoms_indexes.items[shndx]; |
| 706 | 705 | const atom_ptr = self.atom(atom_index) orelse continue; |
| 707 | if (!atom_ptr.flags.alive) continue; | |
| 706 | if (!atom_ptr.alive) continue; | |
| 708 | 707 | if (atom_ptr.relocs(elf_file).len > 0) continue; |
| 709 | 708 | |
| 710 | 709 | const imsec_idx = try self.addInputMergeSection(gpa); |
| ... | ... | @@ -766,7 +765,7 @@ pub fn initMergeSections(self: *Object, elf_file: *Elf) !void { |
| 766 | 765 | } |
| 767 | 766 | } |
| 768 | 767 | |
| 769 | atom_ptr.flags.alive = false; | |
| 768 | atom_ptr.alive = false; | |
| 770 | 769 | } |
| 771 | 770 | } |
| 772 | 771 | |
| ... | ... | @@ -826,7 +825,7 @@ pub fn resolveMergeSubsections(self: *Object, elf_file: *Elf) !void { |
| 826 | 825 | |
| 827 | 826 | for (self.atoms_indexes.items) |atom_index| { |
| 828 | 827 | const atom_ptr = self.atom(atom_index) orelse continue; |
| 829 | if (!atom_ptr.flags.alive) continue; | |
| 828 | if (!atom_ptr.alive) continue; | |
| 830 | 829 | const extras = atom_ptr.extra(elf_file); |
| 831 | 830 | const relocs = self.relocs.items[extras.rel_index..][0..extras.rel_count]; |
| 832 | 831 | for (relocs) |*rel| { |
| ... | ... | @@ -950,7 +949,7 @@ pub fn markComdatGroupsDead(self: *Object, elf_file: *Elf) void { |
| 950 | 949 | for (cg.comdatGroupMembers(elf_file)) |shndx| { |
| 951 | 950 | const atom_index = self.atoms_indexes.items[shndx]; |
| 952 | 951 | if (self.atom(atom_index)) |atom_ptr| { |
| 953 | atom_ptr.flags.alive = false; | |
| 952 | atom_ptr.alive = false; | |
| 954 | 953 | atom_ptr.markFdesDead(elf_file); |
| 955 | 954 | } |
| 956 | 955 | } |
| ... | ... | @@ -960,7 +959,7 @@ pub fn markComdatGroupsDead(self: *Object, elf_file: *Elf) void { |
| 960 | 959 | pub fn initOutputSections(self: *Object, elf_file: *Elf) !void { |
| 961 | 960 | for (self.atoms_indexes.items) |atom_index| { |
| 962 | 961 | const atom_ptr = self.atom(atom_index) orelse continue; |
| 963 | if (!atom_ptr.flags.alive) continue; | |
| 962 | if (!atom_ptr.alive) continue; | |
| 964 | 963 | const shdr = atom_ptr.inputShdr(elf_file); |
| 965 | 964 | _ = try self.initOutputSection(elf_file, shdr); |
| 966 | 965 | } |
| ... | ... | @@ -969,7 +968,7 @@ pub fn initOutputSections(self: *Object, elf_file: *Elf) !void { |
| 969 | 968 | pub fn addAtomsToOutputSections(self: *Object, elf_file: *Elf) !void { |
| 970 | 969 | for (self.atoms_indexes.items) |atom_index| { |
| 971 | 970 | const atom_ptr = self.atom(atom_index) orelse continue; |
| 972 | if (!atom_ptr.flags.alive) continue; | |
| 971 | if (!atom_ptr.alive) continue; | |
| 973 | 972 | const shdr = atom_ptr.inputShdr(elf_file); |
| 974 | 973 | atom_ptr.output_section_index = self.initOutputSection(elf_file, shdr) catch unreachable; |
| 975 | 974 | |
| ... | ... | @@ -988,7 +987,7 @@ pub fn addAtomsToOutputSections(self: *Object, elf_file: *Elf) !void { |
| 988 | 987 | continue; |
| 989 | 988 | } |
| 990 | 989 | const atom_ptr = local.atom(elf_file) orelse continue; |
| 991 | if (!atom_ptr.flags.alive) continue; | |
| 990 | if (!atom_ptr.alive) continue; | |
| 992 | 991 | local.output_section_index = atom_ptr.output_section_index; |
| 993 | 992 | } |
| 994 | 993 | |
| ... | ... | @@ -1001,7 +1000,7 @@ pub fn addAtomsToOutputSections(self: *Object, elf_file: *Elf) !void { |
| 1001 | 1000 | continue; |
| 1002 | 1001 | } |
| 1003 | 1002 | const atom_ptr = global.atom(elf_file) orelse continue; |
| 1004 | if (!atom_ptr.flags.alive) continue; | |
| 1003 | if (!atom_ptr.alive) continue; | |
| 1005 | 1004 | global.output_section_index = atom_ptr.output_section_index; |
| 1006 | 1005 | } |
| 1007 | 1006 | |
| ... | ... | @@ -1016,7 +1015,7 @@ pub fn addAtomsToOutputSections(self: *Object, elf_file: *Elf) !void { |
| 1016 | 1015 | pub fn initRelaSections(self: *Object, elf_file: *Elf) !void { |
| 1017 | 1016 | for (self.atoms_indexes.items) |atom_index| { |
| 1018 | 1017 | const atom_ptr = self.atom(atom_index) orelse continue; |
| 1019 | if (!atom_ptr.flags.alive) continue; | |
| 1018 | if (!atom_ptr.alive) continue; | |
| 1020 | 1019 | const shndx = atom_ptr.relocsShndx() orelse continue; |
| 1021 | 1020 | const shdr = self.shdrs.items[shndx]; |
| 1022 | 1021 | const out_shndx = try self.initOutputSection(elf_file, shdr); |
| ... | ... | @@ -1030,7 +1029,7 @@ pub fn initRelaSections(self: *Object, elf_file: *Elf) !void { |
| 1030 | 1029 | pub fn addAtomsToRelaSections(self: *Object, elf_file: *Elf) !void { |
| 1031 | 1030 | for (self.atoms_indexes.items) |atom_index| { |
| 1032 | 1031 | const atom_ptr = self.atom(atom_index) orelse continue; |
| 1033 | if (!atom_ptr.flags.alive) continue; | |
| 1032 | if (!atom_ptr.alive) continue; | |
| 1034 | 1033 | const shndx = blk: { |
| 1035 | 1034 | const shndx = atom_ptr.relocsShndx() orelse continue; |
| 1036 | 1035 | const shdr = self.shdrs.items[shndx]; |
| ... | ... | @@ -1100,7 +1099,7 @@ pub fn updateSymtabSize(self: *Object, elf_file: *Elf) !void { |
| 1100 | 1099 | const isAlive = struct { |
| 1101 | 1100 | fn isAlive(sym: *const Symbol, ctx: *Elf) bool { |
| 1102 | 1101 | if (sym.mergeSubsection(ctx)) |msub| return msub.alive; |
| 1103 | if (sym.atom(ctx)) |atom_ptr| return atom_ptr.flags.alive; | |
| 1102 | if (sym.atom(ctx)) |atom_ptr| return atom_ptr.alive; | |
| 1104 | 1103 | return true; |
| 1105 | 1104 | } |
| 1106 | 1105 | }.isAlive; |
src/link/Elf/Symbol.zig+1-1| ... | ... | @@ -116,7 +116,7 @@ pub fn address(symbol: Symbol, opts: struct { plt: bool = true }, elf_file: *Elf |
| 116 | 116 | return symbol.pltAddress(elf_file); |
| 117 | 117 | } |
| 118 | 118 | if (symbol.atom(elf_file)) |atom_ptr| { |
| 119 | if (!atom_ptr.flags.alive) { | |
| 119 | if (!atom_ptr.alive) { | |
| 120 | 120 | if (mem.eql(u8, atom_ptr.name(elf_file), ".eh_frame")) { |
| 121 | 121 | const sym_name = symbol.name(elf_file); |
| 122 | 122 | const sh_addr, const sh_size = blk: { |
src/link/Elf/ZigObject.zig+10-10| ... | ... | @@ -331,7 +331,7 @@ pub fn resolveSymbols(self: *ZigObject, elf_file: *Elf) void { |
| 331 | 331 | if (esym.st_shndx != elf.SHN_ABS and esym.st_shndx != elf.SHN_COMMON) { |
| 332 | 332 | assert(esym.st_shndx == SHN_ATOM); |
| 333 | 333 | const atom_ptr = self.atom(shndx) orelse continue; |
| 334 | if (!atom_ptr.flags.alive) continue; | |
| 334 | if (!atom_ptr.alive) continue; | |
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | const global = elf_file.symbol(index); |
| ... | ... | @@ -407,7 +407,7 @@ pub fn scanRelocs(self: *ZigObject, elf_file: *Elf, undefs: anytype) !void { |
| 407 | 407 | const gpa = elf_file.base.comp.gpa; |
| 408 | 408 | for (self.atoms_indexes.items) |atom_index| { |
| 409 | 409 | const atom_ptr = self.atom(atom_index) orelse continue; |
| 410 | if (!atom_ptr.flags.alive) continue; | |
| 410 | if (!atom_ptr.alive) continue; | |
| 411 | 411 | const shdr = atom_ptr.inputShdr(elf_file); |
| 412 | 412 | if (shdr.sh_type == elf.SHT_NOBITS) continue; |
| 413 | 413 | if (atom_ptr.scanRelocsRequiresCode(elf_file)) { |
| ... | ... | @@ -451,7 +451,7 @@ pub fn checkDuplicates(self: *ZigObject, dupes: anytype, elf_file: *Elf) error{O |
| 451 | 451 | |
| 452 | 452 | if (esym.st_shndx == SHN_ATOM) { |
| 453 | 453 | const atom_ptr = self.atom(shndx) orelse continue; |
| 454 | if (!atom_ptr.flags.alive) continue; | |
| 454 | if (!atom_ptr.alive) continue; | |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | const gop = try dupes.getOrPut(index); |
| ... | ... | @@ -519,7 +519,7 @@ pub fn writeAr(self: ZigObject, writer: anytype) !void { |
| 519 | 519 | pub fn addAtomsToRelaSections(self: *ZigObject, elf_file: *Elf) !void { |
| 520 | 520 | for (self.atoms_indexes.items) |atom_index| { |
| 521 | 521 | const atom_ptr = self.atom(atom_index) orelse continue; |
| 522 | if (!atom_ptr.flags.alive) continue; | |
| 522 | if (!atom_ptr.alive) continue; | |
| 523 | 523 | const rela_shndx = atom_ptr.relocsShndx() orelse continue; |
| 524 | 524 | // TODO this check will become obsolete when we rework our relocs mechanism at the ZigObject level |
| 525 | 525 | if (self.relocs.items[rela_shndx].items.len == 0) continue; |
| ... | ... | @@ -560,7 +560,7 @@ pub fn globals(self: ZigObject) []const Symbol.Index { |
| 560 | 560 | pub fn updateSymtabSize(self: *ZigObject, elf_file: *Elf) !void { |
| 561 | 561 | for (self.locals()) |local_index| { |
| 562 | 562 | const local = elf_file.symbol(local_index); |
| 563 | if (local.atom(elf_file)) |atom_ptr| if (!atom_ptr.flags.alive) continue; | |
| 563 | if (local.atom(elf_file)) |atom_ptr| if (!atom_ptr.alive) continue; | |
| 564 | 564 | const esym = local.elfSym(elf_file); |
| 565 | 565 | switch (esym.st_type()) { |
| 566 | 566 | elf.STT_SECTION, elf.STT_NOTYPE => continue, |
| ... | ... | @@ -576,7 +576,7 @@ pub fn updateSymtabSize(self: *ZigObject, elf_file: *Elf) !void { |
| 576 | 576 | const global = elf_file.symbol(global_index); |
| 577 | 577 | const file_ptr = global.file(elf_file) orelse continue; |
| 578 | 578 | if (file_ptr.index() != self.index) continue; |
| 579 | if (global.atom(elf_file)) |atom_ptr| if (!atom_ptr.flags.alive) continue; | |
| 579 | if (global.atom(elf_file)) |atom_ptr| if (!atom_ptr.alive) continue; | |
| 580 | 580 | global.flags.output_symtab = true; |
| 581 | 581 | if (global.isLocal(elf_file)) { |
| 582 | 582 | try global.addExtra(.{ .symtab = self.output_symtab_ctx.nlocals }, elf_file); |
| ... | ... | @@ -922,7 +922,7 @@ fn updateDeclCode( |
| 922 | 922 | atom_ptr.output_section_index = shdr_index; |
| 923 | 923 | |
| 924 | 924 | sym.name_offset = try self.strtab.insert(gpa, decl.fqn.toSlice(ip)); |
| 925 | atom_ptr.flags.alive = true; | |
| 925 | atom_ptr.alive = true; | |
| 926 | 926 | atom_ptr.name_offset = sym.name_offset; |
| 927 | 927 | esym.st_name = sym.name_offset; |
| 928 | 928 | esym.st_info |= stt_bits; |
| ... | ... | @@ -1022,7 +1022,7 @@ fn updateTlv( |
| 1022 | 1022 | atom_ptr.output_section_index = shndx; |
| 1023 | 1023 | |
| 1024 | 1024 | sym.name_offset = try self.strtab.insert(gpa, decl.fqn.toSlice(ip)); |
| 1025 | atom_ptr.flags.alive = true; | |
| 1025 | atom_ptr.alive = true; | |
| 1026 | 1026 | atom_ptr.name_offset = sym.name_offset; |
| 1027 | 1027 | esym.st_value = 0; |
| 1028 | 1028 | esym.st_name = sym.name_offset; |
| ... | ... | @@ -1246,7 +1246,7 @@ fn updateLazySymbol( |
| 1246 | 1246 | local_esym.st_info |= elf.STT_OBJECT; |
| 1247 | 1247 | local_esym.st_size = code.len; |
| 1248 | 1248 | const atom_ptr = local_sym.atom(elf_file).?; |
| 1249 | atom_ptr.flags.alive = true; | |
| 1249 | atom_ptr.alive = true; | |
| 1250 | 1250 | atom_ptr.name_offset = name_str_index; |
| 1251 | 1251 | atom_ptr.alignment = required_alignment; |
| 1252 | 1252 | atom_ptr.size = code.len; |
| ... | ... | @@ -1354,7 +1354,7 @@ fn lowerConst( |
| 1354 | 1354 | local_esym.st_info |= elf.STT_OBJECT; |
| 1355 | 1355 | local_esym.st_size = code.len; |
| 1356 | 1356 | const atom_ptr = local_sym.atom(elf_file).?; |
| 1357 | atom_ptr.flags.alive = true; | |
| 1357 | atom_ptr.alive = true; | |
| 1358 | 1358 | atom_ptr.name_offset = name_str_index; |
| 1359 | 1359 | atom_ptr.alignment = required_alignment; |
| 1360 | 1360 | atom_ptr.size = code.len; |
src/link/Elf/gc.zig+11-11| ... | ... | @@ -36,7 +36,7 @@ fn collectRoots(roots: *std.ArrayList(*Atom), files: []const File.Index, elf_fil |
| 36 | 36 | |
| 37 | 37 | for (file.atoms()) |atom_index| { |
| 38 | 38 | const atom = file.atom(atom_index) orelse continue; |
| 39 | if (!atom.flags.alive) continue; | |
| 39 | if (!atom.alive) continue; | |
| 40 | 40 | |
| 41 | 41 | const shdr = atom.inputShdr(elf_file); |
| 42 | 42 | const name = atom.name(elf_file); |
| ... | ... | @@ -54,7 +54,7 @@ fn collectRoots(roots: *std.ArrayList(*Atom), files: []const File.Index, elf_fil |
| 54 | 54 | break :blk false; |
| 55 | 55 | }; |
| 56 | 56 | if (is_gc_root and markAtom(atom)) try roots.append(atom); |
| 57 | if (shdr.sh_flags & elf.SHF_ALLOC == 0) atom.flags.visited = true; | |
| 57 | if (shdr.sh_flags & elf.SHF_ALLOC == 0) atom.visited = true; | |
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | // Mark every atom referenced by CIE as alive. |
| ... | ... | @@ -77,22 +77,22 @@ fn markSymbol(sym: *Symbol, roots: *std.ArrayList(*Atom), elf_file: *Elf) !void |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | fn markAtom(atom: *Atom) bool { |
| 80 | const already_visited = atom.flags.visited; | |
| 81 | atom.flags.visited = true; | |
| 82 | return atom.flags.alive and !already_visited; | |
| 80 | const already_visited = atom.visited; | |
| 81 | atom.visited = true; | |
| 82 | return atom.alive and !already_visited; | |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | fn markLive(atom: *Atom, elf_file: *Elf) void { |
| 86 | 86 | if (@import("build_options").enable_logging) track_live_level.incr(); |
| 87 | 87 | |
| 88 | assert(atom.flags.visited); | |
| 88 | assert(atom.visited); | |
| 89 | 89 | const file = atom.file(elf_file).?; |
| 90 | 90 | |
| 91 | 91 | for (atom.fdes(elf_file)) |fde| { |
| 92 | 92 | for (fde.relocs(elf_file)[1..]) |rel| { |
| 93 | 93 | const target_sym = elf_file.symbol(file.symbol(rel.r_sym())); |
| 94 | 94 | const target_atom = target_sym.atom(elf_file) orelse continue; |
| 95 | target_atom.flags.alive = true; | |
| 95 | target_atom.alive = true; | |
| 96 | 96 | gc_track_live_log.debug("{}marking live atom({d})", .{ track_live_level, target_atom.atom_index }); |
| 97 | 97 | if (markAtom(target_atom)) markLive(target_atom, elf_file); |
| 98 | 98 | } |
| ... | ... | @@ -105,7 +105,7 @@ fn markLive(atom: *Atom, elf_file: *Elf) void { |
| 105 | 105 | continue; |
| 106 | 106 | } |
| 107 | 107 | const target_atom = target_sym.atom(elf_file) orelse continue; |
| 108 | target_atom.flags.alive = true; | |
| 108 | target_atom.alive = true; | |
| 109 | 109 | gc_track_live_log.debug("{}marking live atom({d})", .{ track_live_level, target_atom.atom_index }); |
| 110 | 110 | if (markAtom(target_atom)) markLive(target_atom, elf_file); |
| 111 | 111 | } |
| ... | ... | @@ -123,8 +123,8 @@ fn prune(files: []const File.Index, elf_file: *Elf) void { |
| 123 | 123 | const file = elf_file.file(index).?; |
| 124 | 124 | for (file.atoms()) |atom_index| { |
| 125 | 125 | const atom = file.atom(atom_index) orelse continue; |
| 126 | if (atom.flags.alive and !atom.flags.visited) { | |
| 127 | atom.flags.alive = false; | |
| 126 | if (atom.alive and !atom.visited) { | |
| 127 | atom.alive = false; | |
| 128 | 128 | atom.markFdesDead(elf_file); |
| 129 | 129 | } |
| 130 | 130 | } |
| ... | ... | @@ -137,7 +137,7 @@ pub fn dumpPrunedAtoms(elf_file: *Elf) !void { |
| 137 | 137 | const file = elf_file.file(index).?; |
| 138 | 138 | for (file.atoms()) |atom_index| { |
| 139 | 139 | const atom = file.atom(atom_index) orelse continue; |
| 140 | if (!atom.flags.alive) | |
| 140 | if (!atom.alive) | |
| 141 | 141 | // TODO should we simply print to stderr? |
| 142 | 142 | try stderr.print("link: removing unused section '{s}' in file '{}'\n", .{ |
| 143 | 143 | atom.name(elf_file), |
src/link/Elf/relocatable.zig+4-4| ... | ... | @@ -340,7 +340,7 @@ fn updateSectionSizes(elf_file: *Elf) !void { |
| 340 | 340 | const shdr = &elf_file.shdrs.items[shndx]; |
| 341 | 341 | for (atom_list.items) |ref| { |
| 342 | 342 | const atom_ptr = elf_file.atom(ref) orelse continue; |
| 343 | if (!atom_ptr.flags.alive) continue; | |
| 343 | if (!atom_ptr.alive) continue; | |
| 344 | 344 | const offset = atom_ptr.alignment.forward(shdr.sh_size); |
| 345 | 345 | const padding = offset - shdr.sh_size; |
| 346 | 346 | atom_ptr.value = @intCast(offset); |
| ... | ... | @@ -353,7 +353,7 @@ fn updateSectionSizes(elf_file: *Elf) !void { |
| 353 | 353 | const shdr = &elf_file.shdrs.items[sec.shndx]; |
| 354 | 354 | for (sec.atom_list.items) |ref| { |
| 355 | 355 | const atom_ptr = elf_file.atom(ref) orelse continue; |
| 356 | if (!atom_ptr.flags.alive) continue; | |
| 356 | if (!atom_ptr.alive) continue; | |
| 357 | 357 | const relocs = atom_ptr.relocs(elf_file); |
| 358 | 358 | shdr.sh_size += shdr.sh_entsize * relocs.len; |
| 359 | 359 | } |
| ... | ... | @@ -447,7 +447,7 @@ fn writeAtoms(elf_file: *Elf) !void { |
| 447 | 447 | |
| 448 | 448 | for (atom_list.items) |ref| { |
| 449 | 449 | const atom_ptr = elf_file.atom(ref).?; |
| 450 | assert(atom_ptr.flags.alive); | |
| 450 | assert(atom_ptr.alive); | |
| 451 | 451 | |
| 452 | 452 | const offset = math.cast(usize, atom_ptr.value - @as(i64, @intCast(shdr.sh_addr - base_offset))) orelse |
| 453 | 453 | return error.Overflow; |
| ... | ... | @@ -489,7 +489,7 @@ fn writeSyntheticSections(elf_file: *Elf) !void { |
| 489 | 489 | |
| 490 | 490 | for (sec.atom_list.items) |ref| { |
| 491 | 491 | const atom_ptr = elf_file.atom(ref) orelse continue; |
| 492 | if (!atom_ptr.flags.alive) continue; | |
| 492 | if (!atom_ptr.alive) continue; | |
| 493 | 493 | try atom_ptr.writeRelocs(elf_file, &relocs); |
| 494 | 494 | } |
| 495 | 495 | assert(relocs.items.len == num_relocs); |
src/link/Elf/thunks.zig+2-3| ... | ... | @@ -14,13 +14,13 @@ pub fn createThunks(shndx: u32, elf_file: *Elf) !void { |
| 14 | 14 | while (i < atoms.len) { |
| 15 | 15 | const start = i; |
| 16 | 16 | const start_atom = elf_file.atom(atoms[start]).?; |
| 17 | assert(start_atom.flags.alive); | |
| 17 | assert(start_atom.alive); | |
| 18 | 18 | start_atom.value = try advance(shdr, start_atom.size, start_atom.alignment); |
| 19 | 19 | i += 1; |
| 20 | 20 | |
| 21 | 21 | while (i < atoms.len) : (i += 1) { |
| 22 | 22 | const atom = elf_file.atom(atoms[i]).?; |
| 23 | assert(atom.flags.alive); | |
| 23 | assert(atom.alive); | |
| 24 | 24 | if (@as(i64, @intCast(atom.alignment.forward(shdr.sh_size))) - start_atom.value >= max_distance) |
| 25 | 25 | break; |
| 26 | 26 | atom.value = try advance(shdr, atom.size, atom.alignment); |
| ... | ... | @@ -51,7 +51,6 @@ pub fn createThunks(shndx: u32, elf_file: *Elf) !void { |
| 51 | 51 | try thunk.symbols.put(gpa, target, {}); |
| 52 | 52 | } |
| 53 | 53 | atom.addExtra(.{ .thunk = thunk_index }, elf_file); |
| 54 | atom.flags.thunk = true; | |
| 55 | 54 | } |
| 56 | 55 | |
| 57 | 56 | thunk.value = try advance(shdr, thunk.size(elf_file), Atom.Alignment.fromNonzeroByteUnits(2)); |