| ... | @@ -1072,8 +1072,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1072,8 +1072,6 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1072 | .Exe => true, | 1072 | .Exe => true, |
| 1073 | }; | 1073 | }; |
| 1074 | | 1074 | |
| 1075 | const needs_c_symbols = !options.skip_linker_dependencies and is_exe_or_dyn_lib; | | |
| 1076 | | | |
| 1077 | // WASI-only. Resolve the optional exec-model option, defaults to command. | 1075 | // WASI-only. Resolve the optional exec-model option, defaults to command. |
| 1078 | const wasi_exec_model = if (options.target.os.tag != .wasi) undefined else options.wasi_exec_model orelse .command; | 1076 | const wasi_exec_model = if (options.target.os.tag != .wasi) undefined else options.wasi_exec_model orelse .command; |
| 1079 | | 1077 | |
| ... | @@ -1381,7 +1379,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -1381,7 +1379,8 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 1381 | return error.StackProtectorUnavailableWithoutLibC; | 1379 | return error.StackProtectorUnavailableWithoutLibC; |
| 1382 | } | 1380 | } |
| 1383 | | 1381 | |
| 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); |
| 1385 | | 1384 | |
| 1386 | const single_threaded = st: { | 1385 | const single_threaded = st: { |
| 1387 | if (target_util.isSingleThreaded(options.target)) { | 1386 | if (target_util.isSingleThreaded(options.target)) { |
| ... | @@ -2196,7 +2195,13 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { | ... | @@ -2196,7 +2195,13 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { |
| 2196 | comp.job_queued_compiler_rt_obj = true; | 2195 | comp.job_queued_compiler_rt_obj = true; |
| 2197 | } | 2196 | } |
| 2198 | } | 2197 | } |
| 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 | )) { |
| 2200 | // Related: https://github.com/ziglang/zig/issues/7265. | 2205 | // Related: https://github.com/ziglang/zig/issues/7265. |
| 2201 | if (comp.bin_file.options.stack_protector != 0 and | 2206 | if (comp.bin_file.options.stack_protector != 0 and |
| 2202 | (!comp.bin_file.options.link_libc or | 2207 | (!comp.bin_file.options.link_libc or |
| ... | @@ -6580,6 +6585,29 @@ fn zigBackend(target: std.Target, use_llvm: bool) std.builtin.CompilerBackend { | ... | @@ -6580,6 +6585,29 @@ fn zigBackend(target: std.Target, use_llvm: bool) std.builtin.CompilerBackend { |
| 6580 | }; | 6585 | }; |
| 6581 | } | 6586 | } |
| 6582 | | 6587 | |
| | 6588 | fn 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 | |
| 6583 | pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Allocator.Error![:0]u8 { | 6611 | pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Allocator.Error![:0]u8 { |
| 6584 | const tracy_trace = trace(@src()); | 6612 | const tracy_trace = trace(@src()); |
| 6585 | defer tracy_trace.end(); | 6613 | defer tracy_trace.end(); |