authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-11-05 20:21:58-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-11-10 13:12:00-07:00
log24b020d9f62ff8ea5d154ae573a049623474214e
tree51439f33abf4b7c98b65d601717abf3be31a8f37
parent9ad03b628f5d4770f9f26e646019292b5ae9cf9b

Compilation: fix logic regarding needs_c_symbols


1 files changed, 32 insertions(+), 4 deletions(-)

src/Compilation.zig+32-4
......@@ -1072,8 +1072,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
10721072 .Exe => true,
10731073 };
10741074
1075 const needs_c_symbols = !options.skip_linker_dependencies and is_exe_or_dyn_lib;
1076
10771075 // WASI-only. Resolve the optional exec-model option, defaults to command.
10781076 const wasi_exec_model = if (options.target.os.tag != .wasi) undefined else options.wasi_exec_model orelse .command;
10791077
......@@ -1381,7 +1379,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
13811379 return error.StackProtectorUnavailableWithoutLibC;
13821380 }
13831381
1384 const include_compiler_rt = options.want_compiler_rt orelse needs_c_symbols;
1382 const include_compiler_rt = options.want_compiler_rt orelse
1383 (!options.skip_linker_dependencies and is_exe_or_dyn_lib);
13851384
13861385 const single_threaded = st: {
13871386 if (target_util.isSingleThreaded(options.target)) {
......@@ -2196,7 +2195,13 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
21962195 comp.job_queued_compiler_rt_obj = true;
21972196 }
21982197 }
2199 if (needs_c_symbols) {
2198 if (needsCSymbols(
2199 options.skip_linker_dependencies,
2200 options.output_mode,
2201 options.link_mode,
2202 options.target,
2203 comp.bin_file.options.use_llvm,
2204 )) {
22002205 // Related: https://github.com/ziglang/zig/issues/7265.
22012206 if (comp.bin_file.options.stack_protector != 0 and
22022207 (!comp.bin_file.options.link_libc or
......@@ -6580,6 +6585,29 @@ fn zigBackend(target: std.Target, use_llvm: bool) std.builtin.CompilerBackend {
65806585 };
65816586}
65826587
6588fn needsCSymbols(
6589 skip_linker_dependencies: bool,
6590 output_mode: std.builtin.OutputMode,
6591 link_mode: ?std.builtin.LinkMode,
6592 target: std.Target,
6593 use_llvm: bool,
6594) bool {
6595 if (skip_linker_dependencies)
6596 return false;
6597
6598 switch (output_mode) {
6599 .Obj => return false,
6600 .Lib => if (link_mode != .Dynamic) return false,
6601 .Exe => {},
6602 }
6603
6604 // LLVM might generate calls to libc symbols.
6605 if (zigBackend(target, use_llvm) == .stage2_llvm)
6606 return true;
6607
6608 return false;
6609}
6610
65836611pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Allocator.Error![:0]u8 {
65846612 const tracy_trace = trace(@src());
65856613 defer tracy_trace.end();