diff --git a/src/Compilation.zig b/src/Compilation.zig index d42d731188..85ad6a2649 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -85,6 +85,7 @@ skip_linker_dependencies: bool, no_builtin: bool, function_sections: bool, data_sections: bool, +link_eh_frame_hdr: bool, native_system_include_paths: []const []const u8, /// List of symbols forced as undefined in the symbol table /// thus forcing their resolution by the linker. @@ -1509,6 +1510,7 @@ pub fn create(gpa: Allocator, options: CreateOptions) !*Compilation { .native_system_include_paths = options.native_system_include_paths, .wasi_emulated_libs = options.wasi_emulated_libs, .force_undefined_symbols = options.force_undefined_symbols, + .link_eh_frame_hdr = link_eh_frame_hdr, }; // Prevent some footguns by making the "any" fields of config reflect @@ -1558,7 +1560,6 @@ pub fn create(gpa: Allocator, options: CreateOptions) !*Compilation { .image_base = options.image_base, .version_script = options.version_script, .gc_sections = options.linker_gc_sections, - .eh_frame_hdr = link_eh_frame_hdr, .emit_relocs = options.link_emit_relocs, .soname = options.soname, .compatibility_version = options.compatibility_version, @@ -2457,6 +2458,7 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes man.hash.add(comp.skip_linker_dependencies); man.hash.add(comp.include_compiler_rt); + man.hash.add(comp.link_eh_frame_hdr); if (comp.config.link_libc) { man.hash.add(comp.libc_installation != null); const target = comp.root_mod.resolved_target.result; @@ -2490,7 +2492,6 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes switch (lf.tag) { .elf => { const elf = lf.cast(link.File.Elf).?; - man.hash.add(elf.eh_frame_hdr); man.hash.add(elf.image_base); man.hash.add(elf.emit_relocs); man.hash.add(elf.z_nodelete); @@ -6213,8 +6214,7 @@ fn buildOutputFromZig( assert(output_mode != .Exe); - const lf = comp.bin_file.?; - const unwind_tables = if (lf.cast(link.File.Elf)) |elf| elf.eh_frame_hdr else false; + const unwind_tables = comp.link_eh_frame_hdr; const strip = comp.compilerRtStrip(); const optimize_mode = comp.compilerRtOptMode(); diff --git a/src/link.zig b/src/link.zig index 6729f00ea9..065779177e 100644 --- a/src/link.zig +++ b/src/link.zig @@ -85,7 +85,6 @@ pub const File = struct { entry_addr: ?u64, stack_size: ?u64, image_base: ?u64, - eh_frame_hdr: bool, emit_relocs: bool, z_nodelete: bool, z_notext: bool, diff --git a/src/link/Elf.zig b/src/link/Elf.zig index 085522d67b..f20282a802 100644 --- a/src/link/Elf.zig +++ b/src/link/Elf.zig @@ -1,6 +1,5 @@ base: link.File, image_base: u64, -eh_frame_hdr: bool, emit_relocs: bool, z_nodelete: bool, z_notext: bool, @@ -306,7 +305,6 @@ pub fn createEmpty( }; }, - .eh_frame_hdr = options.eh_frame_hdr, .emit_relocs = options.emit_relocs, .z_nodelete = options.z_nodelete, .z_notext = options.z_notext, @@ -1726,7 +1724,7 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void { try argv.append("--print-gc-sections"); } - if (self.eh_frame_hdr) { + if (comp.link_eh_frame_hdr) { try argv.append("--eh-frame-hdr"); } @@ -2437,7 +2435,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v man.hash.add(self.image_base); man.hash.add(self.base.gc_sections); man.hash.addOptional(self.sort_section); - man.hash.add(self.eh_frame_hdr); + man.hash.add(comp.link_eh_frame_hdr); man.hash.add(self.emit_relocs); man.hash.add(comp.config.rdynamic); man.hash.addListOfBytes(self.lib_dirs); @@ -2633,7 +2631,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v try argv.append("--print-map"); } - if (self.eh_frame_hdr) { + if (comp.link_eh_frame_hdr) { try argv.append("--eh-frame-hdr"); } @@ -3317,6 +3315,9 @@ pub fn deleteDeclExport( } fn addLinkerDefinedSymbols(self: *Elf) !void { + const comp = self.base.comp; + const gpa = comp.gpa; + const linker_defined_index = self.linker_defined_index orelse return; const linker_defined = self.file(linker_defined_index).?.linker_defined; self.dynamic_index = try linker_defined.addGlobal("_DYNAMIC", self); @@ -3331,7 +3332,7 @@ fn addLinkerDefinedSymbols(self: *Elf) !void { self.plt_index = try linker_defined.addGlobal("_PROCEDURE_LINKAGE_TABLE_", self); self.end_index = try linker_defined.addGlobal("_end", self); - if (self.eh_frame_hdr) { + if (comp.link_eh_frame_hdr) { self.gnu_eh_frame_hdr_index = try linker_defined.addGlobal("__GNU_EH_FRAME_HDR", self); } @@ -3345,7 +3346,6 @@ fn addLinkerDefinedSymbols(self: *Elf) !void { for (self.shdrs.items) |shdr| { if (self.getStartStopBasename(shdr)) |name| { - const gpa = self.base.comp.gpa; try self.start_stop_indexes.ensureUnusedCapacity(gpa, 2); const start = try std.fmt.allocPrintZ(gpa, "__start_{s}", .{name}); @@ -3510,7 +3510,7 @@ fn initSyntheticSections(self: *Elf) !void { .offset = std.math.maxInt(u64), }); - if (self.eh_frame_hdr) { + if (comp.link_eh_frame_hdr) { self.eh_frame_hdr_section_index = try self.addSection(.{ .name = ".eh_frame_hdr", .type = elf.SHT_PROGBITS,