authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-10-08 15:10:38+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-10-09 12:38:53-07:00
loge9d819a29e928d1f9069e12609806dacb558bb3f
treefb61219ed5e8efecd5da7704c40a010a8f4ef3ed
parente448fb960137e5aa83a1e7c2e6cbbf688f4fce05

elf: clean up how we create un-allocated sections


3 files changed, 1 insertions(+), 44 deletions(-)

src/link/Elf.zig+1-24
......@@ -1801,7 +1801,6 @@ pub fn initOutputSection(self: *Elf, args: struct {
18011801 .type = @"type",
18021802 .flags = flags,
18031803 .name = try self.insertShString(name),
1804 .offset = std.math.maxInt(u64),
18051804 });
18061805 return out_shndx;
18071806}
......@@ -2867,7 +2866,6 @@ fn initSyntheticSections(self: *Elf) !void {
28672866 elf.SHT_PROGBITS,
28682867 .flags = elf.SHF_ALLOC,
28692868 .addralign = ptr_size,
2870 .offset = std.math.maxInt(u64),
28712869 });
28722870 }
28732871 if (comp.link_eh_frame_hdr and self.eh_frame_hdr_section_index == null) {
......@@ -2876,7 +2874,6 @@ fn initSyntheticSections(self: *Elf) !void {
28762874 .type = elf.SHT_PROGBITS,
28772875 .flags = elf.SHF_ALLOC,
28782876 .addralign = 4,
2879 .offset = std.math.maxInt(u64),
28802877 });
28812878 }
28822879 }
......@@ -2887,7 +2884,6 @@ fn initSyntheticSections(self: *Elf) !void {
28872884 .type = elf.SHT_PROGBITS,
28882885 .flags = elf.SHF_ALLOC | elf.SHF_WRITE,
28892886 .addralign = ptr_size,
2890 .offset = std.math.maxInt(u64),
28912887 });
28922888 }
28932889
......@@ -2897,7 +2893,6 @@ fn initSyntheticSections(self: *Elf) !void {
28972893 .type = elf.SHT_PROGBITS,
28982894 .flags = elf.SHF_ALLOC | elf.SHF_WRITE,
28992895 .addralign = @alignOf(u64),
2900 .offset = std.math.maxInt(u64),
29012896 });
29022897 }
29032898
......@@ -2919,7 +2914,6 @@ fn initSyntheticSections(self: *Elf) !void {
29192914 .flags = elf.SHF_ALLOC,
29202915 .addralign = @alignOf(elf.Elf64_Rela),
29212916 .entsize = @sizeOf(elf.Elf64_Rela),
2922 .offset = std.math.maxInt(u64),
29232917 });
29242918 }
29252919
......@@ -2930,7 +2924,6 @@ fn initSyntheticSections(self: *Elf) !void {
29302924 .type = elf.SHT_PROGBITS,
29312925 .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR,
29322926 .addralign = 16,
2933 .offset = std.math.maxInt(u64),
29342927 });
29352928 }
29362929 if (self.rela_plt_section_index == null) {
......@@ -2940,7 +2933,6 @@ fn initSyntheticSections(self: *Elf) !void {
29402933 .flags = elf.SHF_ALLOC,
29412934 .addralign = @alignOf(elf.Elf64_Rela),
29422935 .entsize = @sizeOf(elf.Elf64_Rela),
2943 .offset = std.math.maxInt(u64),
29442936 });
29452937 }
29462938 }
......@@ -2951,7 +2943,6 @@ fn initSyntheticSections(self: *Elf) !void {
29512943 .type = elf.SHT_PROGBITS,
29522944 .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR,
29532945 .addralign = 16,
2954 .offset = std.math.maxInt(u64),
29552946 });
29562947 }
29572948
......@@ -2960,7 +2951,6 @@ fn initSyntheticSections(self: *Elf) !void {
29602951 .name = try self.insertShString(".copyrel"),
29612952 .type = elf.SHT_NOBITS,
29622953 .flags = elf.SHF_ALLOC | elf.SHF_WRITE,
2963 .offset = std.math.maxInt(u64),
29642954 });
29652955 }
29662956
......@@ -2979,7 +2969,6 @@ fn initSyntheticSections(self: *Elf) !void {
29792969 .type = elf.SHT_PROGBITS,
29802970 .flags = elf.SHF_ALLOC,
29812971 .addralign = 1,
2982 .offset = std.math.maxInt(u64),
29832972 });
29842973 }
29852974
......@@ -2991,7 +2980,6 @@ fn initSyntheticSections(self: *Elf) !void {
29912980 .type = elf.SHT_STRTAB,
29922981 .entsize = 1,
29932982 .addralign = 1,
2994 .offset = std.math.maxInt(u64),
29952983 });
29962984 }
29972985 if (self.dynamic_section_index == null) {
......@@ -3001,7 +2989,6 @@ fn initSyntheticSections(self: *Elf) !void {
30012989 .type = elf.SHT_DYNAMIC,
30022990 .entsize = @sizeOf(elf.Elf64_Dyn),
30032991 .addralign = @alignOf(elf.Elf64_Dyn),
3004 .offset = std.math.maxInt(u64),
30052992 });
30062993 }
30072994 if (self.dynsymtab_section_index == null) {
......@@ -3012,7 +2999,6 @@ fn initSyntheticSections(self: *Elf) !void {
30122999 .addralign = @alignOf(elf.Elf64_Sym),
30133000 .entsize = @sizeOf(elf.Elf64_Sym),
30143001 .info = 1,
3015 .offset = std.math.maxInt(u64),
30163002 });
30173003 }
30183004 if (self.hash_section_index == null) {
......@@ -3022,7 +3008,6 @@ fn initSyntheticSections(self: *Elf) !void {
30223008 .type = elf.SHT_HASH,
30233009 .addralign = 4,
30243010 .entsize = 4,
3025 .offset = std.math.maxInt(u64),
30263011 });
30273012 }
30283013 if (self.gnu_hash_section_index == null) {
......@@ -3031,7 +3016,6 @@ fn initSyntheticSections(self: *Elf) !void {
30313016 .flags = elf.SHF_ALLOC,
30323017 .type = elf.SHT_GNU_HASH,
30333018 .addralign = 8,
3034 .offset = std.math.maxInt(u64),
30353019 });
30363020 }
30373021
......@@ -3047,7 +3031,6 @@ fn initSyntheticSections(self: *Elf) !void {
30473031 .type = elf.SHT_GNU_VERSYM,
30483032 .addralign = @alignOf(elf.Elf64_Versym),
30493033 .entsize = @sizeOf(elf.Elf64_Versym),
3050 .offset = std.math.maxInt(u64),
30513034 });
30523035 }
30533036 if (self.verneed_section_index == null) {
......@@ -3056,7 +3039,6 @@ fn initSyntheticSections(self: *Elf) !void {
30563039 .flags = elf.SHF_ALLOC,
30573040 .type = elf.SHT_GNU_VERNEED,
30583041 .addralign = @alignOf(elf.Elf64_Verneed),
3059 .offset = std.math.maxInt(u64),
30603042 });
30613043 }
30623044 }
......@@ -3077,7 +3059,6 @@ pub fn initSymtab(self: *Elf) !void {
30773059 .type = elf.SHT_SYMTAB,
30783060 .addralign = if (small_ptr) @alignOf(elf.Elf32_Sym) else @alignOf(elf.Elf64_Sym),
30793061 .entsize = if (small_ptr) @sizeOf(elf.Elf32_Sym) else @sizeOf(elf.Elf64_Sym),
3080 .offset = std.math.maxInt(u64),
30813062 });
30823063 }
30833064 if (self.strtab_section_index == null) {
......@@ -3086,7 +3067,6 @@ pub fn initSymtab(self: *Elf) !void {
30863067 .type = elf.SHT_STRTAB,
30873068 .entsize = 1,
30883069 .addralign = 1,
3089 .offset = std.math.maxInt(u64),
30903070 });
30913071 }
30923072}
......@@ -3098,7 +3078,6 @@ pub fn initShStrtab(self: *Elf) !void {
30983078 .type = elf.SHT_STRTAB,
30993079 .entsize = 1,
31003080 .addralign = 1,
3101 .offset = std.math.maxInt(u64),
31023081 });
31033082 }
31043083}
......@@ -4760,7 +4739,6 @@ pub fn addRelaShdr(self: *Elf, name: u32, shndx: u32) !u32 {
47604739 .entsize = entsize,
47614740 .info = shndx,
47624741 .addralign = addralign,
4763 .offset = std.math.maxInt(u64),
47644742 });
47654743}
47664744
......@@ -4772,7 +4750,6 @@ pub const AddSectionOpts = struct {
47724750 info: u32 = 0,
47734751 addralign: u64 = 0,
47744752 entsize: u64 = 0,
4775 offset: u64 = 0,
47764753};
47774754
47784755pub fn addSection(self: *Elf, opts: AddSectionOpts) !u32 {
......@@ -4784,7 +4761,7 @@ pub fn addSection(self: *Elf, opts: AddSectionOpts) !u32 {
47844761 .sh_type = opts.type,
47854762 .sh_flags = opts.flags,
47864763 .sh_addr = 0,
4787 .sh_offset = opts.offset,
4764 .sh_offset = 0,
47884765 .sh_size = 0,
47894766 .sh_link = opts.link,
47904767 .sh_info = opts.info,
src/link/Elf/ZigObject.zig-18
......@@ -130,7 +130,6 @@ pub fn init(self: *ZigObject, elf_file: *Elf, options: InitOptions) !void {
130130 .entsize = 1,
131131 .type = elf.SHT_PROGBITS,
132132 .addralign = 1,
133 .offset = std.math.maxInt(u64),
134133 });
135134 self.debug_str_section_dirty = true;
136135 self.debug_str_index = try addSectionSymbolWithAtom(self, gpa, ".debug_str", .@"1", osec);
......@@ -141,7 +140,6 @@ pub fn init(self: *ZigObject, elf_file: *Elf, options: InitOptions) !void {
141140 .name = try elf_file.insertShString(".debug_info"),
142141 .type = elf.SHT_PROGBITS,
143142 .addralign = 1,
144 .offset = std.math.maxInt(u64),
145143 });
146144 self.debug_info_section_dirty = true;
147145 self.debug_info_index = try addSectionSymbolWithAtom(self, gpa, ".debug_info", .@"1", osec);
......@@ -152,7 +150,6 @@ pub fn init(self: *ZigObject, elf_file: *Elf, options: InitOptions) !void {
152150 .name = try elf_file.insertShString(".debug_abbrev"),
153151 .type = elf.SHT_PROGBITS,
154152 .addralign = 1,
155 .offset = std.math.maxInt(u64),
156153 });
157154 self.debug_abbrev_section_dirty = true;
158155 self.debug_abbrev_index = try addSectionSymbolWithAtom(self, gpa, ".debug_abbrev", .@"1", osec);
......@@ -163,7 +160,6 @@ pub fn init(self: *ZigObject, elf_file: *Elf, options: InitOptions) !void {
163160 .name = try elf_file.insertShString(".debug_aranges"),
164161 .type = elf.SHT_PROGBITS,
165162 .addralign = 16,
166 .offset = std.math.maxInt(u64),
167163 });
168164 self.debug_aranges_section_dirty = true;
169165 self.debug_aranges_index = try addSectionSymbolWithAtom(self, gpa, ".debug_aranges", .@"16", osec);
......@@ -174,7 +170,6 @@ pub fn init(self: *ZigObject, elf_file: *Elf, options: InitOptions) !void {
174170 .name = try elf_file.insertShString(".debug_line"),
175171 .type = elf.SHT_PROGBITS,
176172 .addralign = 1,
177 .offset = std.math.maxInt(u64),
178173 });
179174 self.debug_line_section_dirty = true;
180175 self.debug_line_index = try addSectionSymbolWithAtom(self, gpa, ".debug_line", .@"1", osec);
......@@ -187,7 +182,6 @@ pub fn init(self: *ZigObject, elf_file: *Elf, options: InitOptions) !void {
187182 .entsize = 1,
188183 .type = elf.SHT_PROGBITS,
189184 .addralign = 1,
190 .offset = std.math.maxInt(u64),
191185 });
192186 self.debug_line_str_section_dirty = true;
193187 self.debug_line_str_index = try addSectionSymbolWithAtom(self, gpa, ".debug_line_str", .@"1", osec);
......@@ -198,7 +192,6 @@ pub fn init(self: *ZigObject, elf_file: *Elf, options: InitOptions) !void {
198192 .name = try elf_file.insertShString(".debug_loclists"),
199193 .type = elf.SHT_PROGBITS,
200194 .addralign = 1,
201 .offset = std.math.maxInt(u64),
202195 });
203196 self.debug_loclists_section_dirty = true;
204197 self.debug_loclists_index = try addSectionSymbolWithAtom(self, gpa, ".debug_loclists", .@"1", osec);
......@@ -209,7 +202,6 @@ pub fn init(self: *ZigObject, elf_file: *Elf, options: InitOptions) !void {
209202 .name = try elf_file.insertShString(".debug_rnglists"),
210203 .type = elf.SHT_PROGBITS,
211204 .addralign = 1,
212 .offset = std.math.maxInt(u64),
213205 });
214206 self.debug_rnglists_section_dirty = true;
215207 self.debug_rnglists_index = try addSectionSymbolWithAtom(self, gpa, ".debug_rnglists", .@"1", osec);
......@@ -224,7 +216,6 @@ pub fn init(self: *ZigObject, elf_file: *Elf, options: InitOptions) !void {
224216 elf.SHT_PROGBITS,
225217 .flags = elf.SHF_ALLOC,
226218 .addralign = ptr_size,
227 .offset = std.math.maxInt(u64),
228219 });
229220 self.eh_frame_section_dirty = true;
230221 self.eh_frame_index = try addSectionSymbolWithAtom(self, gpa, ".eh_frame", Atom.Alignment.fromNonzeroByteUnits(ptr_size), osec);
......@@ -1026,7 +1017,6 @@ pub fn lowerUav(
10261017 .type = elf.SHT_PROGBITS,
10271018 .addralign = 1,
10281019 .flags = elf.SHF_ALLOC | elf.SHF_WRITE,
1029 .offset = std.math.maxInt(u64),
10301020 });
10311021 self.data_relro_index = try self.addSectionSymbol(gpa, try self.addString(gpa, ".data.rel.ro"), osec);
10321022 break :osec osec;
......@@ -1166,7 +1156,6 @@ fn getNavShdrIndex(
11661156 .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR,
11671157 .name = try elf_file.insertShString(".text"),
11681158 .addralign = 1,
1169 .offset = std.math.maxInt(u64),
11701159 });
11711160 self.text_index = try self.addSectionSymbol(gpa, try self.addString(gpa, ".text"), osec);
11721161 return osec;
......@@ -1200,7 +1189,6 @@ fn getNavShdrIndex(
12001189 .flags = elf.SHF_ALLOC | elf.SHF_WRITE | elf.SHF_TLS,
12011190 .name = try elf_file.insertShString(".tdata"),
12021191 .addralign = 1,
1203 .offset = std.math.maxInt(u64),
12041192 });
12051193 self.tdata_index = try self.addSectionSymbol(gpa, try self.addString(gpa, ".tdata"), osec);
12061194 return osec;
......@@ -1213,7 +1201,6 @@ fn getNavShdrIndex(
12131201 .type = elf.SHT_PROGBITS,
12141202 .addralign = 1,
12151203 .flags = elf.SHF_ALLOC | elf.SHF_WRITE,
1216 .offset = std.math.maxInt(u64),
12171204 });
12181205 self.data_relro_index = try self.addSectionSymbol(gpa, try self.addString(gpa, ".data.rel.ro"), osec);
12191206 return osec;
......@@ -1228,7 +1215,6 @@ fn getNavShdrIndex(
12281215 .type = elf.SHT_PROGBITS,
12291216 .addralign = ptr_size,
12301217 .flags = elf.SHF_ALLOC | elf.SHF_WRITE,
1231 .offset = std.math.maxInt(u64),
12321218 });
12331219 self.data_index = try self.addSectionSymbol(gpa, try self.addString(gpa, ".data"), osec);
12341220 return osec;
......@@ -1268,7 +1254,6 @@ fn getNavShdrIndex(
12681254 .type = elf.SHT_PROGBITS,
12691255 .addralign = ptr_size,
12701256 .flags = elf.SHF_ALLOC | elf.SHF_WRITE,
1271 .offset = std.math.maxInt(u64),
12721257 });
12731258 self.data_index = try self.addSectionSymbol(gpa, try self.addString(gpa, ".data"), osec);
12741259 return osec;
......@@ -1521,7 +1506,6 @@ pub fn updateFunc(
15211506 .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR,
15221507 .type = elf.SHT_PROGBITS,
15231508 .addralign = 1,
1524 .offset = std.math.maxInt(u64),
15251509 });
15261510 self.text_index = try self.addSectionSymbol(gpa, try self.addString(gpa, ".text"), osec);
15271511 break :osec osec;
......@@ -1697,7 +1681,6 @@ fn updateLazySymbol(
16971681 .type = elf.SHT_PROGBITS,
16981682 .addralign = 1,
16991683 .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR,
1700 .offset = std.math.maxInt(u64),
17011684 });
17021685 self.text_index = try self.addSectionSymbol(gpa, try self.addString(gpa, ".text"), osec);
17031686 break :osec osec;
......@@ -1710,7 +1693,6 @@ fn updateLazySymbol(
17101693 .type = elf.SHT_PROGBITS,
17111694 .addralign = 1,
17121695 .flags = elf.SHF_ALLOC,
1713 .offset = std.math.maxInt(u64),
17141696 });
17151697 self.rodata_index = try self.addSectionSymbol(gpa, try self.addString(gpa, ".rodata"), osec);
17161698 break :osec osec;
src/link/Elf/relocatable.zig-2
......@@ -295,7 +295,6 @@ fn initSections(elf_file: *Elf) !void {
295295 elf.SHT_PROGBITS,
296296 .flags = elf.SHF_ALLOC,
297297 .addralign = elf_file.ptrWidthBytes(),
298 .offset = std.math.maxInt(u64),
299298 });
300299 }
301300 elf_file.eh_frame_rela_section_index = elf_file.sectionByName(".rela.eh_frame") orelse
......@@ -324,7 +323,6 @@ fn initComdatGroups(elf_file: *Elf) !void {
324323 .type = elf.SHT_GROUP,
325324 .entsize = @sizeOf(u32),
326325 .addralign = @alignOf(u32),
327 .offset = std.math.maxInt(u64),
328326 }),
329327 .cg_ref = .{ .index = @intCast(cg_index), .file = index },
330328 };