authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-12-27 10:34:55-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-01 19:49:07-07:00
log372b407740224ae20fad49647bbde56330b24967
tree2af818d959da7f7dce5b7a5ab28befa0614f72c8
parent435b74acd6384029588755ae87568d03911da5c2

move eh_frame_hdr from link.File to Compilation

since it's accessed by Compilation. fixes an invalid check of bin_file==null

3 files changed, 12 insertions(+), 13 deletions(-)

src/Compilation.zig+4-4
......@@ -85,6 +85,7 @@ skip_linker_dependencies: bool,
8585no_builtin: bool,
8686function_sections: bool,
8787data_sections: bool,
88link_eh_frame_hdr: bool,
8889native_system_include_paths: []const []const u8,
8990/// List of symbols forced as undefined in the symbol table
9091/// thus forcing their resolution by the linker.
......@@ -1509,6 +1510,7 @@ pub fn create(gpa: Allocator, options: CreateOptions) !*Compilation {
15091510 .native_system_include_paths = options.native_system_include_paths,
15101511 .wasi_emulated_libs = options.wasi_emulated_libs,
15111512 .force_undefined_symbols = options.force_undefined_symbols,
1513 .link_eh_frame_hdr = link_eh_frame_hdr,
15121514 };
15131515
15141516 // Prevent some footguns by making the "any" fields of config reflect
......@@ -1558,7 +1560,6 @@ pub fn create(gpa: Allocator, options: CreateOptions) !*Compilation {
15581560 .image_base = options.image_base,
15591561 .version_script = options.version_script,
15601562 .gc_sections = options.linker_gc_sections,
1561 .eh_frame_hdr = link_eh_frame_hdr,
15621563 .emit_relocs = options.link_emit_relocs,
15631564 .soname = options.soname,
15641565 .compatibility_version = options.compatibility_version,
......@@ -2457,6 +2458,7 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
24572458
24582459 man.hash.add(comp.skip_linker_dependencies);
24592460 man.hash.add(comp.include_compiler_rt);
2461 man.hash.add(comp.link_eh_frame_hdr);
24602462 if (comp.config.link_libc) {
24612463 man.hash.add(comp.libc_installation != null);
24622464 const target = comp.root_mod.resolved_target.result;
......@@ -2490,7 +2492,6 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
24902492 switch (lf.tag) {
24912493 .elf => {
24922494 const elf = lf.cast(link.File.Elf).?;
2493 man.hash.add(elf.eh_frame_hdr);
24942495 man.hash.add(elf.image_base);
24952496 man.hash.add(elf.emit_relocs);
24962497 man.hash.add(elf.z_nodelete);
......@@ -6213,8 +6214,7 @@ fn buildOutputFromZig(
62136214
62146215 assert(output_mode != .Exe);
62156216
6216 const lf = comp.bin_file.?;
6217 const unwind_tables = if (lf.cast(link.File.Elf)) |elf| elf.eh_frame_hdr else false;
6217 const unwind_tables = comp.link_eh_frame_hdr;
62186218 const strip = comp.compilerRtStrip();
62196219 const optimize_mode = comp.compilerRtOptMode();
62206220
src/link.zig-1
......@@ -85,7 +85,6 @@ pub const File = struct {
8585 entry_addr: ?u64,
8686 stack_size: ?u64,
8787 image_base: ?u64,
88 eh_frame_hdr: bool,
8988 emit_relocs: bool,
9089 z_nodelete: bool,
9190 z_notext: bool,
src/link/Elf.zig+8-8
......@@ -1,6 +1,5 @@
11base: link.File,
22image_base: u64,
3eh_frame_hdr: bool,
43emit_relocs: bool,
54z_nodelete: bool,
65z_notext: bool,
......@@ -306,7 +305,6 @@ pub fn createEmpty(
306305 };
307306 },
308307
309 .eh_frame_hdr = options.eh_frame_hdr,
310308 .emit_relocs = options.emit_relocs,
311309 .z_nodelete = options.z_nodelete,
312310 .z_notext = options.z_notext,
......@@ -1726,7 +1724,7 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {
17261724 try argv.append("--print-gc-sections");
17271725 }
17281726
1729 if (self.eh_frame_hdr) {
1727 if (comp.link_eh_frame_hdr) {
17301728 try argv.append("--eh-frame-hdr");
17311729 }
17321730
......@@ -2437,7 +2435,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
24372435 man.hash.add(self.image_base);
24382436 man.hash.add(self.base.gc_sections);
24392437 man.hash.addOptional(self.sort_section);
2440 man.hash.add(self.eh_frame_hdr);
2438 man.hash.add(comp.link_eh_frame_hdr);
24412439 man.hash.add(self.emit_relocs);
24422440 man.hash.add(comp.config.rdynamic);
24432441 man.hash.addListOfBytes(self.lib_dirs);
......@@ -2633,7 +2631,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
26332631 try argv.append("--print-map");
26342632 }
26352633
2636 if (self.eh_frame_hdr) {
2634 if (comp.link_eh_frame_hdr) {
26372635 try argv.append("--eh-frame-hdr");
26382636 }
26392637
......@@ -3317,6 +3315,9 @@ pub fn deleteDeclExport(
33173315}
33183316
33193317fn addLinkerDefinedSymbols(self: *Elf) !void {
3318 const comp = self.base.comp;
3319 const gpa = comp.gpa;
3320
33203321 const linker_defined_index = self.linker_defined_index orelse return;
33213322 const linker_defined = self.file(linker_defined_index).?.linker_defined;
33223323 self.dynamic_index = try linker_defined.addGlobal("_DYNAMIC", self);
......@@ -3331,7 +3332,7 @@ fn addLinkerDefinedSymbols(self: *Elf) !void {
33313332 self.plt_index = try linker_defined.addGlobal("_PROCEDURE_LINKAGE_TABLE_", self);
33323333 self.end_index = try linker_defined.addGlobal("_end", self);
33333334
3334 if (self.eh_frame_hdr) {
3335 if (comp.link_eh_frame_hdr) {
33353336 self.gnu_eh_frame_hdr_index = try linker_defined.addGlobal("__GNU_EH_FRAME_HDR", self);
33363337 }
33373338
......@@ -3345,7 +3346,6 @@ fn addLinkerDefinedSymbols(self: *Elf) !void {
33453346
33463347 for (self.shdrs.items) |shdr| {
33473348 if (self.getStartStopBasename(shdr)) |name| {
3348 const gpa = self.base.comp.gpa;
33493349 try self.start_stop_indexes.ensureUnusedCapacity(gpa, 2);
33503350
33513351 const start = try std.fmt.allocPrintZ(gpa, "__start_{s}", .{name});
......@@ -3510,7 +3510,7 @@ fn initSyntheticSections(self: *Elf) !void {
35103510 .offset = std.math.maxInt(u64),
35113511 });
35123512
3513 if (self.eh_frame_hdr) {
3513 if (comp.link_eh_frame_hdr) {
35143514 self.eh_frame_hdr_section_index = try self.addSection(.{
35153515 .name = ".eh_frame_hdr",
35163516 .type = elf.SHT_PROGBITS,