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