authorgravatar for motiejus@jakstys.ltMotiejus Jakštys <motiejus@jakstys.lt> 2022-05-09 09:44:14+03:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-09-08 22:30:32-04:00
loga833bdcd7e6fcfee6e9cc33a3f7de78b16a36941
tree5b45c1662789e9743d328356167b3dce72495bfd
parentab4b26d8a6a36ccf75af8e25f0a1f7b88063b76f

[ld] add --print-* for diagnostics

This adds the following for passthrough to lld: - `--print-gc-sections` - `--print-icf-sections` - `--print-map` I am not adding these to the cache manifest, since it does not change the produced artifacts. Tested with an example from #11398: it successfully prints the resulting map and the GC'd sections.

4 files changed, 33 insertions(+), 0 deletions(-)

src/Compilation.zig+6
......@@ -878,6 +878,9 @@ pub const InitOptions = struct {
878878 linker_shared_memory: bool = false,
879879 linker_global_base: ?u64 = null,
880880 linker_export_symbol_names: []const []const u8 = &.{},
881 linker_print_gc_sections: bool = false,
882 linker_print_icf_sections: bool = false,
883 linker_print_map: bool = false,
881884 each_lib_rpath: ?bool = null,
882885 build_id: ?bool = null,
883886 disable_c_depfile: bool = false,
......@@ -1727,6 +1730,9 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
17271730 .shared_memory = options.linker_shared_memory,
17281731 .global_base = options.linker_global_base,
17291732 .export_symbol_names = options.linker_export_symbol_names,
1733 .print_gc_sections = options.linker_print_gc_sections,
1734 .print_icf_sections = options.linker_print_icf_sections,
1735 .print_map = options.linker_print_map,
17301736 .z_nodelete = options.linker_z_nodelete,
17311737 .z_notext = options.linker_z_notext,
17321738 .z_defs = options.linker_z_defs,
src/link.zig+3
......@@ -166,6 +166,9 @@ pub const Options = struct {
166166 version_script: ?[]const u8,
167167 soname: ?[]const u8,
168168 llvm_cpu_features: ?[*:0]const u8,
169 print_gc_sections: bool,
170 print_icf_sections: bool,
171 print_map: bool,
169172
170173 objects: []Compilation.LinkObject,
171174 framework_dirs: []const []const u8,
src/link/Elf.zig+12
......@@ -1482,6 +1482,18 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
14821482 try argv.append("--gc-sections");
14831483 }
14841484
1485 if (self.base.options.print_gc_sections) {
1486 try argv.append("--print-gc-sections");
1487 }
1488
1489 if (self.base.options.print_icf_sections) {
1490 try argv.append("--print-icf-sections");
1491 }
1492
1493 if (self.base.options.print_map) {
1494 try argv.append("--print-map");
1495 }
1496
14851497 if (self.base.options.eh_frame_hdr) {
14861498 try argv.append("--eh-frame-hdr");
14871499 }
src/main.zig+12
......@@ -691,6 +691,9 @@ fn buildOutputType(
691691 var linker_max_memory: ?u64 = null;
692692 var linker_shared_memory: bool = false;
693693 var linker_global_base: ?u64 = null;
694 var linker_print_gc_sections: bool = false;
695 var linker_print_icf_sections: bool = false;
696 var linker_print_map: bool = false;
694697 var linker_z_nodelete = false;
695698 var linker_z_notext = false;
696699 var linker_z_defs = false;
......@@ -1816,6 +1819,12 @@ fn buildOutputType(
18161819 linker_gc_sections = true;
18171820 } else if (mem.eql(u8, arg, "--no-gc-sections")) {
18181821 linker_gc_sections = false;
1822 } else if (mem.eql(u8, arg, "--print-gc-sections")) {
1823 linker_print_gc_sections = true;
1824 } else if (mem.eql(u8, arg, "--print-icf-sections")) {
1825 linker_print_icf_sections = true;
1826 } else if (mem.eql(u8, arg, "--print-map")) {
1827 linker_print_map = true;
18191828 } else if (mem.eql(u8, arg, "--allow-shlib-undefined") or
18201829 mem.eql(u8, arg, "-allow-shlib-undefined"))
18211830 {
......@@ -2911,6 +2920,9 @@ fn buildOutputType(
29112920 .linker_initial_memory = linker_initial_memory,
29122921 .linker_max_memory = linker_max_memory,
29132922 .linker_shared_memory = linker_shared_memory,
2923 .linker_print_gc_sections = linker_print_gc_sections,
2924 .linker_print_icf_sections = linker_print_icf_sections,
2925 .linker_print_map = linker_print_map,
29142926 .linker_global_base = linker_global_base,
29152927 .linker_export_symbol_names = linker_export_symbol_names.items,
29162928 .linker_z_nodelete = linker_z_nodelete,