authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-12-12 20:25:34+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-01-06 21:15:02+01:00
loga996a75e06193d377c3071042ece1c3af5cfdc6c
tree389c9eb5b65a4cd639e9d3ca6c0ac0eed6b927c6
parent312b231da9a90e477c56801fb2056324edc50ea1
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

compiler: make all Zig-provided libraries use -ffunction-sections -fdata-sections

We already did this for some of them; this just makes us consistent. Doing this gives the linker more flexibility to rearrange code/data, but more importantly, allows --gc-sections to get rid of all the unused code, which is a real concern for these libraries in particular.

6 files changed, 13 insertions(+), 13 deletions(-)

src/Compilation.zig+4-4
......@@ -8084,8 +8084,8 @@ fn buildOutputFromZig(
80848084}
80858085
80868086pub const CrtFileOptions = struct {
8087 function_sections: ?bool = null,
8088 data_sections: ?bool = null,
8087 function_sections: bool = true,
8088 data_sections: bool = true,
80898089 omit_frame_pointer: ?bool = null,
80908090 unwind_tables: ?std.builtin.UnwindTables = null,
80918091 pic: ?bool = null,
......@@ -8188,8 +8188,8 @@ pub fn build_crt_file(
81888188 .root_name = root_name,
81898189 .libc_installation = comp.libc_installation,
81908190 .emit_bin = .yes_cache,
8191 .function_sections = options.function_sections orelse false,
8192 .data_sections = options.data_sections orelse false,
8191 .function_sections = options.function_sections,
8192 .data_sections = options.data_sections,
81938193 .c_source_files = c_source_files,
81948194 .verbose_cc = comp.verbose_cc,
81958195 .verbose_link = comp.verbose_link,
src/libs/libcxx.zig+4
......@@ -265,6 +265,8 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError!
265265 .root_name = root_name,
266266 .libc_installation = comp.libc_installation,
267267 .emit_bin = .yes_cache,
268 .function_sections = true,
269 .data_sections = true,
268270 .c_source_files = c_source_files.items,
269271 .verbose_cc = comp.verbose_cc,
270272 .verbose_link = comp.verbose_link,
......@@ -459,6 +461,8 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
459461 .root_name = root_name,
460462 .libc_installation = comp.libc_installation,
461463 .emit_bin = .yes_cache,
464 .function_sections = true,
465 .data_sections = true,
462466 .c_source_files = c_source_files.items,
463467 .verbose_cc = comp.verbose_cc,
464468 .verbose_link = comp.verbose_link,
src/libs/libtsan.zig+2
......@@ -288,6 +288,8 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo
288288 .root_name = root_name,
289289 .libc_installation = comp.libc_installation,
290290 .emit_bin = .yes_cache,
291 .function_sections = true,
292 .data_sections = true,
291293 .c_source_files = c_source_files.items,
292294 .verbose_cc = comp.verbose_cc,
293295 .verbose_link = comp.verbose_link,
src/libs/libunwind.zig+2-1
......@@ -155,7 +155,8 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr
155155 .main_mod = null,
156156 .libc_installation = comp.libc_installation,
157157 .emit_bin = .yes_cache,
158 .function_sections = comp.function_sections,
158 .function_sections = true,
159 .data_sections = true,
159160 .c_source_files = &c_source_files,
160161 .verbose_cc = comp.verbose_cc,
161162 .verbose_link = comp.verbose_link,
src/libs/mingw.zig+1
......@@ -56,6 +56,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
5656 },
5757 };
5858 return comp.build_crt_file("crt2", .Obj, .@"mingw-w64 crt2.o", prog_node, &files, .{
59 .function_sections = false, // https://codeberg.org/ziglang/zig/issues/30702
5960 .unwind_tables = unwind_tables,
6061 });
6162 },
src/libs/musl.zig-8
......@@ -43,8 +43,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
4343 },
4444 };
4545 return comp.build_crt_file("crt1", .Obj, .@"musl crt1.o", prog_node, &files, .{
46 .function_sections = true,
47 .data_sections = true,
4846 .omit_frame_pointer = true,
4947 .no_builtin = true,
5048 });
......@@ -63,8 +61,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
6361 },
6462 };
6563 return comp.build_crt_file("rcrt1", .Obj, .@"musl rcrt1.o", prog_node, &files, .{
66 .function_sections = true,
67 .data_sections = true,
6864 .omit_frame_pointer = true,
6965 .pic = true,
7066 .no_builtin = true,
......@@ -84,8 +80,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
8480 },
8581 };
8682 return comp.build_crt_file("Scrt1", .Obj, .@"musl Scrt1.o", prog_node, &files, .{
87 .function_sections = true,
88 .data_sections = true,
8983 .omit_frame_pointer = true,
9084 .pic = true,
9185 .no_builtin = true,
......@@ -172,8 +166,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
172166 };
173167 }
174168 return comp.build_crt_file("c", .Lib, .@"musl libc.a", prog_node, c_source_files.items, .{
175 .function_sections = true,
176 .data_sections = true,
177169 .omit_frame_pointer = true,
178170 .no_builtin = true,
179171 });