aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorAlex Rønne Petersen <alex@alexrp.com>2024-11-12 16:40:00 +0100
committerGitHub <noreply@github.com>2024-11-12 16:40:00 +0100
commit1db8cade5ab5c05fa3c6a884e50947633ebcf065 (patch)
tree5a74083c154ad53748440fa85c75a16b009043d9 /src/Compilation.zig
parentbbbc95afd0d035224047443d56ed2252d8f47cb9 (diff)
parentc9052ef93105107bd20bd52ee51197d55e7ace34 (diff)
downloadzig-1db8cade5ab5c05fa3c6a884e50947633ebcf065.tar.gz
zig-1db8cade5ab5c05fa3c6a884e50947633ebcf065.zip
Merge pull request #21920 from alexrp/nobuiltin
compiler: Improve handling of `-fno-builtin` and compiler-rt options
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig40
1 files changed, 26 insertions, 14 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 51877d7973..f646ef258a 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -89,7 +89,6 @@ windows_libs: std.StringArrayHashMapUnmanaged(void),
version: ?std.SemanticVersion,
libc_installation: ?*const LibCInstallation,
skip_linker_dependencies: bool,
-no_builtin: bool,
function_sections: bool,
data_sections: bool,
link_eh_frame_hdr: bool,
@@ -852,6 +851,7 @@ pub const cache_helpers = struct {
hh.add(mod.fuzz);
hh.add(mod.unwind_tables);
hh.add(mod.structured_cfg);
+ hh.add(mod.no_builtin);
hh.addListOfBytes(mod.cc_argv);
}
@@ -1057,7 +1057,6 @@ pub const CreateOptions = struct {
want_lto: ?bool = null,
function_sections: bool = false,
data_sections: bool = false,
- no_builtin: bool = false,
time_report: bool = false,
stack_report: bool = false,
link_eh_frame_hdr: bool = false,
@@ -1299,7 +1298,11 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
},
.fully_qualified_name = "compiler_rt",
.cc_argv = &.{},
- .inherited = .{},
+ .inherited = .{
+ .stack_check = false,
+ .stack_protector = 0,
+ .no_builtin = true,
+ },
.global = options.config,
.parent = options.root_mod,
.builtin_mod = options.root_mod.getBuiltinDependency(),
@@ -1353,7 +1356,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
cache.hash.add(options.config.link_mode);
cache.hash.add(options.function_sections);
cache.hash.add(options.data_sections);
- cache.hash.add(options.no_builtin);
cache.hash.add(link_libc);
cache.hash.add(options.config.link_libcpp);
cache.hash.add(options.config.link_libunwind);
@@ -1490,7 +1492,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
.framework_dirs = options.framework_dirs,
.llvm_opt_bisect_limit = options.llvm_opt_bisect_limit,
.skip_linker_dependencies = options.skip_linker_dependencies,
- .no_builtin = options.no_builtin,
.job_queued_update_builtin_zig = have_zcu,
.function_sections = options.function_sections,
.data_sections = options.data_sections,
@@ -5261,7 +5262,7 @@ pub fn addCCArgs(
try argv.append("-fdata-sections");
}
- if (comp.no_builtin) {
+ if (mod.no_builtin) {
try argv.append("-fno-builtin");
}
@@ -6154,7 +6155,6 @@ fn buildOutputFromZig(
assert(output_mode != .Exe);
- const unwind_tables = comp.link_eh_frame_hdr;
const strip = comp.compilerRtStrip();
const optimize_mode = comp.compilerRtOptMode();
@@ -6168,7 +6168,6 @@ fn buildOutputFromZig(
.root_optimize_mode = optimize_mode,
.root_strip = strip,
.link_libc = comp.config.link_libc,
- .any_unwind_tables = unwind_tables,
});
const root_mod = try Package.Module.create(arena, .{
@@ -6185,10 +6184,11 @@ fn buildOutputFromZig(
.stack_protector = 0,
.red_zone = comp.root_mod.red_zone,
.omit_frame_pointer = comp.root_mod.omit_frame_pointer,
- .unwind_tables = unwind_tables,
+ .unwind_tables = comp.root_mod.unwind_tables,
.pic = comp.root_mod.pic,
.optimize_mode = optimize_mode,
.structured_cfg = comp.root_mod.structured_cfg,
+ .no_builtin = true,
.code_model = comp.root_mod.code_model,
},
.global = config,
@@ -6237,7 +6237,6 @@ fn buildOutputFromZig(
},
.function_sections = true,
.data_sections = true,
- .no_builtin = true,
.emit_h = null,
.verbose_cc = comp.verbose_cc,
.verbose_link = comp.verbose_link,
@@ -6262,16 +6261,24 @@ fn buildOutputFromZig(
comp.queueLinkTaskMode(crt_file.full_object_path, output_mode);
}
+pub const CrtFileOptions = struct {
+ function_sections: ?bool = null,
+ data_sections: ?bool = null,
+ omit_frame_pointer: ?bool = null,
+ pic: ?bool = null,
+ no_builtin: ?bool = null,
+};
+
pub fn build_crt_file(
comp: *Compilation,
root_name: []const u8,
output_mode: std.builtin.OutputMode,
- pic: ?bool,
misc_task_tag: MiscTask,
prog_node: std.Progress.Node,
/// These elements have to get mutated to add the owner module after it is
/// created within this function.
c_source_files: []CSourceFile,
+ options: CrtFileOptions,
) !void {
const tracy_trace = trace(@src());
defer tracy_trace.end();
@@ -6316,13 +6323,16 @@ pub fn build_crt_file(
.sanitize_c = false,
.sanitize_thread = false,
.red_zone = comp.root_mod.red_zone,
- .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
+ // Some libcs (e.g. musl) are opinionated about -fomit-frame-pointer.
+ .omit_frame_pointer = options.omit_frame_pointer orelse comp.root_mod.omit_frame_pointer,
.valgrind = false,
.unwind_tables = false,
- // Some CRT objects (rcrt1.o, Scrt1.o) are opinionated about PIC.
- .pic = pic orelse comp.root_mod.pic,
+ // Some CRT objects (e.g. musl's rcrt1.o and Scrt1.o) are opinionated about PIC.
+ .pic = options.pic orelse comp.root_mod.pic,
.optimize_mode = comp.compilerRtOptMode(),
.structured_cfg = comp.root_mod.structured_cfg,
+ // Some libcs (e.g. musl) are opinionated about -fno-builtin.
+ .no_builtin = options.no_builtin orelse comp.root_mod.no_builtin,
},
.global = config,
.cc_argv = &.{},
@@ -6350,6 +6360,8 @@ pub fn build_crt_file(
.directory = null, // Put it in the cache directory.
.basename = basename,
},
+ .function_sections = options.function_sections orelse false,
+ .data_sections = options.data_sections orelse false,
.emit_h = null,
.c_source_files = c_source_files,
.verbose_cc = comp.verbose_cc,