Skip to content

Commit a833bdc

Browse files
motiejusandrewrk
authored andcommitted
[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.
1 parent ab4b26d commit a833bdc

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

src/Compilation.zig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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,

0 commit comments

Comments
 (0)