aboutsummaryrefslogtreecommitdiff
path: root/src/Compilation.zig
diff options
context:
space:
mode:
authorMichael Dusan <michael.dusan@gmail.com>2023-10-18 15:54:46 -0400
committerAndrew Kelley <andrew@ziglang.org>2023-10-20 01:59:55 -0400
commitaa76ca2931d7adbc8ee3b33cdaa2cb1de1adda8a (patch)
tree7d9d01dceab74371da65f0eee94c84f216866c79 /src/Compilation.zig
parent5d8bc56ab67c01f9c1b6de6227356c1c74852464 (diff)
downloadzig-aa76ca2931d7adbc8ee3b33cdaa2cb1de1adda8a.tar.gz
zig-aa76ca2931d7adbc8ee3b33cdaa2cb1de1adda8a.zip
llvm: set PIE only for executables
closes #17575
Diffstat (limited to 'src/Compilation.zig')
-rw-r--r--src/Compilation.zig27
1 files changed, 19 insertions, 8 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index 84e0c512d1..596e555411 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -1037,13 +1037,24 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
const sysroot = options.sysroot orelse libc_dirs.sysroot;
- const must_pie = target_util.requiresPIE(options.target);
- const pie: bool = if (options.want_pie) |explicit| pie: {
- if (!explicit and must_pie) {
- return error.TargetRequiresPIE;
+ const pie: bool = pie: {
+ if (options.output_mode != .Exe) {
+ if (options.want_pie == true) return error.OutputModeForbidsPie;
+ break :pie false;
}
- break :pie explicit;
- } else must_pie or tsan;
+ if (target_util.requiresPIE(options.target)) {
+ if (options.want_pie == false) return error.TargetRequiresPie;
+ break :pie true;
+ }
+ if (tsan) {
+ if (options.want_pie == false) return error.TsanRequiresPie;
+ break :pie true;
+ }
+ if (options.want_pie) |want_pie| {
+ break :pie want_pie;
+ }
+ break :pie false;
+ };
const must_pic: bool = b: {
if (target_util.requiresPIC(options.target, link_libc))
@@ -6533,7 +6544,7 @@ fn buildOutputFromZig(
.want_tsan = false,
.want_unwind_tables = comp.bin_file.options.eh_frame_hdr,
.want_pic = comp.bin_file.options.pic,
- .want_pie = comp.bin_file.options.pie,
+ .want_pie = null,
.emit_h = null,
.strip = comp.compilerRtStrip(),
.is_native_os = comp.bin_file.options.is_native_os,
@@ -6608,7 +6619,7 @@ pub fn build_crt_file(
.want_valgrind = false,
.want_tsan = false,
.want_pic = comp.bin_file.options.pic,
- .want_pie = comp.bin_file.options.pie,
+ .want_pie = null,
.want_lto = switch (output_mode) {
.Lib => comp.bin_file.options.lto,
.Obj, .Exe => false,