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.
This commit is contained in:
Alex Rønne Petersen
2025-12-12 20:25:34 +01:00
parent 312b231da9
commit a996a75e06
6 changed files with 13 additions and 13 deletions
+4 -4
View File
@@ -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,
+4
View File
@@ -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,
+2
View File
@@ -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,
+2 -1
View File
@@ -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,
+1
View File
@@ -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,
});
},
-8
View File
@@ -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,
});