diff --git a/src/Compilation/Config.zig b/src/Compilation/Config.zig index 1251552086..3415acf33e 100644 --- a/src/Compilation/Config.zig +++ b/src/Compilation/Config.zig @@ -416,22 +416,29 @@ pub fn resolve(options: Options) ResolveError!Config { const pie: bool = b: { switch (options.output_mode) { - .Obj, .Exe => {}, + .Exe => if (target.os.tag == .fuchsia or + (target.abi.isAndroid() and link_mode == .dynamic)) + { + if (options.pie == false) return error.TargetRequiresPie; + break :b true; + }, .Lib => if (link_mode == .dynamic) { if (options.pie == true) return error.DynamicLibraryPrecludesPie; break :b false; }, - } - if (target_util.requiresPIE(target)) { - if (options.pie == false) return error.TargetRequiresPie; - break :b true; + .Obj => {}, } if (options.any_sanitize_thread) { if (options.pie == false) return error.SanitizeThreadRequiresPie; break :b true; } if (options.pie) |pie| break :b pie; - break :b false; + break :b if (options.output_mode == .Exe) switch (target.os.tag) { + .fuchsia, + .openbsd, + => true, + else => target.os.tag.isDarwin(), + } else false; }; const root_strip = b: { diff --git a/src/target.zig b/src/target.zig index 4b0cc20bda..81a1a4901f 100644 --- a/src/target.zig +++ b/src/target.zig @@ -43,10 +43,6 @@ pub fn libCxxNeedsLibUnwind(target: std.Target) bool { }; } -pub fn requiresPIE(target: std.Target) bool { - return target.abi.isAndroid() or target.os.tag.isDarwin() or target.os.tag == .openbsd; -} - /// This function returns whether non-pic code is completely invalid on the given target. pub fn requiresPIC(target: std.Target, linking_libc: bool) bool { return target.abi.isAndroid() or