mirror of
https://codeberg.org/ziglang/zig.git
synced 2026-04-27 19:09:47 +03:00
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:
+4
-4
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
},
|
||||
|
||||
@@ -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,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user