zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

commit a996a75e06193d377c3071042ece1c3af5cfdc6c (tree)
parent 312b231da9a90e477c56801fb2056324edc50ea1
Author: Alex Rønne Petersen <alex@alexrp.com>
Date:   Fri, 12 Dec 2025 20:25:34 +0100

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.

Diffstat:
Msrc/Compilation.zig | 8++++----
Msrc/libs/libcxx.zig | 4++++
Msrc/libs/libtsan.zig | 2++
Msrc/libs/libunwind.zig | 3++-
Msrc/libs/mingw.zig | 1+
Msrc/libs/musl.zig | 8--------
6 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/src/Compilation.zig b/src/Compilation.zig @@ -8084,8 +8084,8 @@ fn buildOutputFromZig( } pub const CrtFileOptions = struct { - function_sections: ?bool = null, - data_sections: ?bool = null, + function_sections: bool = true, + data_sections: bool = true, omit_frame_pointer: ?bool = null, unwind_tables: ?std.builtin.UnwindTables = null, pic: ?bool = null, @@ -8188,8 +8188,8 @@ pub fn build_crt_file( .root_name = root_name, .libc_installation = comp.libc_installation, .emit_bin = .yes_cache, - .function_sections = options.function_sections orelse false, - .data_sections = options.data_sections orelse false, + .function_sections = options.function_sections, + .data_sections = options.data_sections, .c_source_files = c_source_files, .verbose_cc = comp.verbose_cc, .verbose_link = comp.verbose_link, diff --git a/src/libs/libcxx.zig b/src/libs/libcxx.zig @@ -265,6 +265,8 @@ pub fn buildLibCxx(comp: *Compilation, prog_node: std.Progress.Node) BuildError! .root_name = root_name, .libc_installation = comp.libc_installation, .emit_bin = .yes_cache, + .function_sections = true, + .data_sections = true, .c_source_files = c_source_files.items, .verbose_cc = comp.verbose_cc, .verbose_link = comp.verbose_link, @@ -459,6 +461,8 @@ pub fn buildLibCxxAbi(comp: *Compilation, prog_node: std.Progress.Node) BuildErr .root_name = root_name, .libc_installation = comp.libc_installation, .emit_bin = .yes_cache, + .function_sections = true, + .data_sections = true, .c_source_files = c_source_files.items, .verbose_cc = comp.verbose_cc, .verbose_link = comp.verbose_link, diff --git a/src/libs/libtsan.zig b/src/libs/libtsan.zig @@ -288,6 +288,8 @@ pub fn buildTsan(comp: *Compilation, prog_node: std.Progress.Node) BuildError!vo .root_name = root_name, .libc_installation = comp.libc_installation, .emit_bin = .yes_cache, + .function_sections = true, + .data_sections = true, .c_source_files = c_source_files.items, .verbose_cc = comp.verbose_cc, .verbose_link = comp.verbose_link, diff --git a/src/libs/libunwind.zig b/src/libs/libunwind.zig @@ -155,7 +155,8 @@ pub fn buildStaticLib(comp: *Compilation, prog_node: std.Progress.Node) BuildErr .main_mod = null, .libc_installation = comp.libc_installation, .emit_bin = .yes_cache, - .function_sections = comp.function_sections, + .function_sections = true, + .data_sections = true, .c_source_files = &c_source_files, .verbose_cc = comp.verbose_cc, .verbose_link = comp.verbose_link, diff --git a/src/libs/mingw.zig b/src/libs/mingw.zig @@ -56,6 +56,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre }, }; return comp.build_crt_file("crt2", .Obj, .@"mingw-w64 crt2.o", prog_node, &files, .{ + .function_sections = false, // https://codeberg.org/ziglang/zig/issues/30702 .unwind_tables = unwind_tables, }); }, diff --git a/src/libs/musl.zig b/src/libs/musl.zig @@ -43,8 +43,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro }, }; return comp.build_crt_file("crt1", .Obj, .@"musl crt1.o", prog_node, &files, .{ - .function_sections = true, - .data_sections = true, .omit_frame_pointer = true, .no_builtin = true, }); @@ -63,8 +61,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro }, }; return comp.build_crt_file("rcrt1", .Obj, .@"musl rcrt1.o", prog_node, &files, .{ - .function_sections = true, - .data_sections = true, .omit_frame_pointer = true, .pic = true, .no_builtin = true, @@ -84,8 +80,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro }, }; return comp.build_crt_file("Scrt1", .Obj, .@"musl Scrt1.o", prog_node, &files, .{ - .function_sections = true, - .data_sections = true, .omit_frame_pointer = true, .pic = true, .no_builtin = true, @@ -172,8 +166,6 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro }; } return comp.build_crt_file("c", .Lib, .@"musl libc.a", prog_node, c_source_files.items, .{ - .function_sections = true, - .data_sections = true, .omit_frame_pointer = true, .no_builtin = true, });