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,...@@ -85,6 +85,7 @@ skip_linker_dependencies: bool,
85no_builtin: bool,85no_builtin: bool,
86function_sections: bool,86function_sections: bool,
87data_sections: bool,87data_sections: bool,
88link_eh_frame_hdr: bool,
88native_system_include_paths: []const []const u8,89native_system_include_paths: []const []const u8,
89/// List of symbols forced as undefined in the symbol table90/// List of symbols forced as undefined in the symbol table
90/// thus forcing their resolution by the linker.91/// thus forcing their resolution by the linker.
...@@ -1509,6 +1510,7 @@ pub fn create(gpa: Allocator, options: CreateOptions) !*Compilation {...@@ -1509,6 +1510,7 @@ pub fn create(gpa: Allocator, options: CreateOptions) !*Compilation {
1509 .native_system_include_paths = options.native_system_include_paths,1510 .native_system_include_paths = options.native_system_include_paths,
1510 .wasi_emulated_libs = options.wasi_emulated_libs,1511 .wasi_emulated_libs = options.wasi_emulated_libs,
1511 .force_undefined_symbols = options.force_undefined_symbols,1512 .force_undefined_symbols = options.force_undefined_symbols,
1513 .link_eh_frame_hdr = link_eh_frame_hdr,
1512 };1514 };
15131515
1514 // Prevent some footguns by making the "any" fields of config reflect1516 // Prevent some footguns by making the "any" fields of config reflect
...@@ -1558,7 +1560,6 @@ pub fn create(gpa: Allocator, options: CreateOptions) !*Compilation {...@@ -1558,7 +1560,6 @@ pub fn create(gpa: Allocator, options: CreateOptions) !*Compilation {
1558 .image_base = options.image_base,1560 .image_base = options.image_base,
1559 .version_script = options.version_script,1561 .version_script = options.version_script,
1560 .gc_sections = options.linker_gc_sections,1562 .gc_sections = options.linker_gc_sections,
1561 .eh_frame_hdr = link_eh_frame_hdr,
1562 .emit_relocs = options.link_emit_relocs,1563 .emit_relocs = options.link_emit_relocs,
1563 .soname = options.soname,1564 .soname = options.soname,
1564 .compatibility_version = options.compatibility_version,1565 .compatibility_version = options.compatibility_version,
...@@ -2457,6 +2458,7 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes...@@ -2457,6 +2458,7 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
24572458
2458 man.hash.add(comp.skip_linker_dependencies);2459 man.hash.add(comp.skip_linker_dependencies);
2459 man.hash.add(comp.include_compiler_rt);2460 man.hash.add(comp.include_compiler_rt);
2461 man.hash.add(comp.link_eh_frame_hdr);
2460 if (comp.config.link_libc) {2462 if (comp.config.link_libc) {
2461 man.hash.add(comp.libc_installation != null);2463 man.hash.add(comp.libc_installation != null);
2462 const target = comp.root_mod.resolved_target.result;2464 const target = comp.root_mod.resolved_target.result;
...@@ -2490,7 +2492,6 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes...@@ -2490,7 +2492,6 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
2490 switch (lf.tag) {2492 switch (lf.tag) {
2491 .elf => {2493 .elf => {
2492 const elf = lf.cast(link.File.Elf).?;2494 const elf = lf.cast(link.File.Elf).?;
2493 man.hash.add(elf.eh_frame_hdr);
2494 man.hash.add(elf.image_base);2495 man.hash.add(elf.image_base);
2495 man.hash.add(elf.emit_relocs);2496 man.hash.add(elf.emit_relocs);
2496 man.hash.add(elf.z_nodelete);2497 man.hash.add(elf.z_nodelete);
...@@ -6213,8 +6214,7 @@ fn buildOutputFromZig(...@@ -6213,8 +6214,7 @@ fn buildOutputFromZig(
62136214
6214 assert(output_mode != .Exe);6215 assert(output_mode != .Exe);
62156216
6216 const lf = comp.bin_file.?;6217 const unwind_tables = comp.link_eh_frame_hdr;
6217 const unwind_tables = if (lf.cast(link.File.Elf)) |elf| elf.eh_frame_hdr else false;
6218 const strip = comp.compilerRtStrip();6218 const strip = comp.compilerRtStrip();
6219 const optimize_mode = comp.compilerRtOptMode();6219 const optimize_mode = comp.compilerRtOptMode();
62206220
src/link.zig-1
...@@ -85,7 +85,6 @@ pub const File = struct {...@@ -85,7 +85,6 @@ pub const File = struct {
85 entry_addr: ?u64,85 entry_addr: ?u64,
86 stack_size: ?u64,86 stack_size: ?u64,
87 image_base: ?u64,87 image_base: ?u64,
88 eh_frame_hdr: bool,
89 emit_relocs: bool,88 emit_relocs: bool,
90 z_nodelete: bool,89 z_nodelete: bool,
91 z_notext: bool,90 z_notext: bool,
src/link/Elf.zig+8-8
...@@ -1,6 +1,5 @@...@@ -1,6 +1,5 @@
1base: link.File,1base: link.File,
2image_base: u64,2image_base: u64,
3eh_frame_hdr: bool,
4emit_relocs: bool,3emit_relocs: bool,
5z_nodelete: bool,4z_nodelete: bool,
6z_notext: bool,5z_notext: bool,
...@@ -306,7 +305,6 @@ pub fn createEmpty(...@@ -306,7 +305,6 @@ pub fn createEmpty(
306 };305 };
307 },306 },
308307
309 .eh_frame_hdr = options.eh_frame_hdr,
310 .emit_relocs = options.emit_relocs,308 .emit_relocs = options.emit_relocs,
311 .z_nodelete = options.z_nodelete,309 .z_nodelete = options.z_nodelete,
312 .z_notext = options.z_notext,310 .z_notext = options.z_notext,
...@@ -1726,7 +1724,7 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {...@@ -1726,7 +1724,7 @@ fn dumpArgv(self: *Elf, comp: *Compilation) !void {
1726 try argv.append("--print-gc-sections");1724 try argv.append("--print-gc-sections");
1727 }1725 }
17281726
1729 if (self.eh_frame_hdr) {1727 if (comp.link_eh_frame_hdr) {
1730 try argv.append("--eh-frame-hdr");1728 try argv.append("--eh-frame-hdr");
1731 }1729 }
17321730
...@@ -2437,7 +2435,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v...@@ -2437,7 +2435,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
2437 man.hash.add(self.image_base);2435 man.hash.add(self.image_base);
2438 man.hash.add(self.base.gc_sections);2436 man.hash.add(self.base.gc_sections);
2439 man.hash.addOptional(self.sort_section);2437 man.hash.addOptional(self.sort_section);
2440 man.hash.add(self.eh_frame_hdr);2438 man.hash.add(comp.link_eh_frame_hdr);
2441 man.hash.add(self.emit_relocs);2439 man.hash.add(self.emit_relocs);
2442 man.hash.add(comp.config.rdynamic);2440 man.hash.add(comp.config.rdynamic);
2443 man.hash.addListOfBytes(self.lib_dirs);2441 man.hash.addListOfBytes(self.lib_dirs);
...@@ -2633,7 +2631,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v...@@ -2633,7 +2631,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
2633 try argv.append("--print-map");2631 try argv.append("--print-map");
2634 }2632 }
26352633
2636 if (self.eh_frame_hdr) {2634 if (comp.link_eh_frame_hdr) {
2637 try argv.append("--eh-frame-hdr");2635 try argv.append("--eh-frame-hdr");
2638 }2636 }
26392637
...@@ -3317,6 +3315,9 @@ pub fn deleteDeclExport(...@@ -3317,6 +3315,9 @@ pub fn deleteDeclExport(
3317}3315}
33183316
3319fn addLinkerDefinedSymbols(self: *Elf) !void {3317fn addLinkerDefinedSymbols(self: *Elf) !void {
3318 const comp = self.base.comp;
3319 const gpa = comp.gpa;
3320
3320 const linker_defined_index = self.linker_defined_index orelse return;3321 const linker_defined_index = self.linker_defined_index orelse return;
3321 const linker_defined = self.file(linker_defined_index).?.linker_defined;3322 const linker_defined = self.file(linker_defined_index).?.linker_defined;
3322 self.dynamic_index = try linker_defined.addGlobal("_DYNAMIC", self);3323 self.dynamic_index = try linker_defined.addGlobal("_DYNAMIC", self);
...@@ -3331,7 +3332,7 @@ fn addLinkerDefinedSymbols(self: *Elf) !void {...@@ -3331,7 +3332,7 @@ fn addLinkerDefinedSymbols(self: *Elf) !void {
3331 self.plt_index = try linker_defined.addGlobal("_PROCEDURE_LINKAGE_TABLE_", self);3332 self.plt_index = try linker_defined.addGlobal("_PROCEDURE_LINKAGE_TABLE_", self);
3332 self.end_index = try linker_defined.addGlobal("_end", self);3333 self.end_index = try linker_defined.addGlobal("_end", self);
33333334
3334 if (self.eh_frame_hdr) {3335 if (comp.link_eh_frame_hdr) {
3335 self.gnu_eh_frame_hdr_index = try linker_defined.addGlobal("__GNU_EH_FRAME_HDR", self);3336 self.gnu_eh_frame_hdr_index = try linker_defined.addGlobal("__GNU_EH_FRAME_HDR", self);
3336 }3337 }
33373338
...@@ -3345,7 +3346,6 @@ fn addLinkerDefinedSymbols(self: *Elf) !void {...@@ -3345,7 +3346,6 @@ fn addLinkerDefinedSymbols(self: *Elf) !void {
33453346
3346 for (self.shdrs.items) |shdr| {3347 for (self.shdrs.items) |shdr| {
3347 if (self.getStartStopBasename(shdr)) |name| {3348 if (self.getStartStopBasename(shdr)) |name| {
3348 const gpa = self.base.comp.gpa;
3349 try self.start_stop_indexes.ensureUnusedCapacity(gpa, 2);3349 try self.start_stop_indexes.ensureUnusedCapacity(gpa, 2);
33503350
3351 const start = try std.fmt.allocPrintZ(gpa, "__start_{s}", .{name});3351 const start = try std.fmt.allocPrintZ(gpa, "__start_{s}", .{name});
...@@ -3510,7 +3510,7 @@ fn initSyntheticSections(self: *Elf) !void {...@@ -3510,7 +3510,7 @@ fn initSyntheticSections(self: *Elf) !void {
3510 .offset = std.math.maxInt(u64),3510 .offset = std.math.maxInt(u64),
3511 });3511 });
35123512
3513 if (self.eh_frame_hdr) {3513 if (comp.link_eh_frame_hdr) {
3514 self.eh_frame_hdr_section_index = try self.addSection(.{3514 self.eh_frame_hdr_section_index = try self.addSection(.{
3515 .name = ".eh_frame_hdr",3515 .name = ".eh_frame_hdr",
3516 .type = elf.SHT_PROGBITS,3516 .type = elf.SHT_PROGBITS,