diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2025-06-04 21:45:31 -0400 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2025-06-06 23:42:14 -0700 |
| commit | 0bf8617d963dc432ed0204b10285cc414becf2fd (patch) | |
| tree | b4a28f10bd66183cd949e6f0fbb4a786bfc1aa04 /src/Compilation/Config.zig | |
| parent | 178ee8aef1b9f765da916f3e1e4cab66437f8e0a (diff) | |
| download | zig-0bf8617d963dc432ed0204b10285cc414becf2fd.tar.gz zig-0bf8617d963dc432ed0204b10285cc414becf2fd.zip | |
x86_64: add support for pie executables
Diffstat (limited to 'src/Compilation/Config.zig')
| -rw-r--r-- | src/Compilation/Config.zig | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/src/Compilation/Config.zig b/src/Compilation/Config.zig index 626b2c3631..637a4bb280 100644 --- a/src/Compilation/Config.zig +++ b/src/Compilation/Config.zig @@ -345,11 +345,19 @@ pub fn resolve(options: Options) ResolveError!Config { } else false; }; + const is_dyn_lib = switch (options.output_mode) { + .Obj, .Exe => false, + .Lib => link_mode == .dynamic, + }; + // Make a decision on whether to use LLVM backend for machine code generation. // Note that using the LLVM backend does not necessarily mean using LLVM libraries. // For example, Zig can emit .bc and .ll files directly, and this is still considered // using "the LLVM backend". - const prefer_llvm = b: { + const use_llvm = b: { + // If we have no zig code to compile, no need for LLVM. + if (!options.have_zcu) break :b false; + // If emitting to LLVM bitcode object format, must use LLVM backend. if (options.emit_llvm_ir or options.emit_llvm_bc) { if (options.use_llvm == false) @@ -382,9 +390,9 @@ pub fn resolve(options: Options) ResolveError!Config { // Prefer LLVM for release builds. if (root_optimize_mode != .Debug) break :b true; - // Self-hosted backends can't handle the inline assembly in std.pie yet - // https://github.com/ziglang/zig/issues/24046 - if (pie) break :b true; + // load_dynamic_library standalone test not passing on this combination + // https://github.com/ziglang/zig/issues/24080 + if (target.os.tag == .macos and is_dyn_lib) break :b true; // At this point we would prefer to use our own self-hosted backend, // because the compilation speed is better than LLVM. But only do it if @@ -392,13 +400,6 @@ pub fn resolve(options: Options) ResolveError!Config { break :b !target_util.selfHostedBackendIsAsRobustAsLlvm(target); }; - const use_llvm = b: { - // If we have no zig code to compile, no need for LLVM. - if (!options.have_zcu) break :b false; - - break :b prefer_llvm; - }; - if (options.emit_bin and options.have_zcu) { if (!use_lib_llvm and use_llvm) { // Explicit request to use LLVM to produce an object file, but without @@ -435,7 +436,13 @@ pub fn resolve(options: Options) ResolveError!Config { } if (options.use_lld) |x| break :b x; - break :b prefer_llvm; + + // If we have no zig code to compile, no need for the self-hosted linker. + if (!options.have_zcu) break :b true; + + // If we do have zig code, match the decision for whether to use the llvm backend, + // so that the llvm backend defaults to lld and the self-hosted backends do not. + break :b use_llvm; }; const lto: std.zig.LtoMode = b: { |
