| author | |
| committer | |
| log | 4219037faf573da8094ae8083d5ae01da6bdff6e |
| tree | 1620c5c6b4c5f5dbd529a362e36e33983ec0edcb |
| parent | 558a5c7913434547c55355af0075a9d34db0d4bc |
| signature |
Otherwise, by default and with no special flags, we produce objects and static
libraries that cannot be linked into executables.3 files changed, 15 insertions(+), 9 deletions(-)
src/Compilation/Config.zig+1-6| ... | @@ -472,12 +472,7 @@ pub fn resolve(options: Options) ResolveError!Config { | ... | @@ -472,12 +472,7 @@ pub fn resolve(options: Options) ResolveError!Config { |
| 472 | break :b true; | 472 | break :b true; |
| 473 | } | 473 | } |
| 474 | if (options.pie) |pie| break :b pie; | 474 | if (options.pie) |pie| break :b pie; |
| 475 | break :b if (options.output_mode == .Exe) switch (target.os.tag) { | 475 | break :b if (options.output_mode == .Exe) target_util.defaultPie(target) else false; |
| 476 | .fuchsia, | ||
| 477 | .openbsd, | ||
| 478 | => true, | ||
| 479 | else => target.os.tag.isDarwin(), | ||
| 480 | } else false; | ||
| 481 | }; | 476 | }; |
| 482 | 477 | ||
| 483 | const lto: std.zig.LtoMode = b: { | 478 | const lto: std.zig.LtoMode = b: { |
src/Package/Module.zig+6-2| ... | @@ -168,7 +168,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { | ... | @@ -168,7 +168,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { |
| 168 | }; | 168 | }; |
| 169 | 169 | ||
| 170 | const pic = b: { | 170 | const pic = b: { |
| 171 | if (target_util.requiresPIC(target, options.global.link_libc)) { | 171 | if (target_util.requiresPic(target, options.global.link_libc)) { |
| 172 | if (options.inherited.pic == false) | 172 | if (options.inherited.pic == false) |
| 173 | return error.TargetRequiresPic; | 173 | return error.TargetRequiresPic; |
| 174 | break :b true; | 174 | break :b true; |
| ... | @@ -185,7 +185,11 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { | ... | @@ -185,7 +185,11 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module { |
| 185 | } | 185 | } |
| 186 | if (options.inherited.pic) |x| break :b x; | 186 | if (options.inherited.pic) |x| break :b x; |
| 187 | if (options.parent) |p| break :b p.pic; | 187 | if (options.parent) |p| break :b p.pic; |
| 188 | break :b false; | 188 | |
| 189 | // Default to PIC on targets where we default to producing PIEs to make | ||
| 190 | // the common case of linking objects and static libraries into an | ||
| 191 | // executable work out of the box. | ||
| 192 | break :b target_util.defaultPie(target); | ||
| 189 | }; | 193 | }; |
| 190 | 194 | ||
| 191 | const red_zone = b: { | 195 | const red_zone = b: { |
src/target.zig+8-1| ... | @@ -53,7 +53,7 @@ pub fn libCxxNeedsLibUnwind(target: *const std.Target) bool { | ... | @@ -53,7 +53,7 @@ pub fn libCxxNeedsLibUnwind(target: *const std.Target) bool { |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | /// This function returns whether non-pic code is completely invalid on the given target. | 55 | /// This function returns whether non-pic code is completely invalid on the given target. |
| 56 | pub fn requiresPIC(target: *const std.Target, linking_libc: bool) bool { | 56 | pub fn requiresPic(target: *const std.Target, linking_libc: bool) bool { |
| 57 | return target.abi.isAndroid() or | 57 | return target.abi.isAndroid() or |
| 58 | ((target.os.tag == .windows or target.os.tag == .uefi) and (target.cpu.arch == .aarch64 or target.cpu.arch == .x86_64)) or | 58 | ((target.os.tag == .windows or target.os.tag == .uefi) and (target.cpu.arch == .aarch64 or target.cpu.arch == .x86_64)) or |
| 59 | target.requiresLibC() or | 59 | target.requiresLibC() or |
| ... | @@ -84,6 +84,13 @@ pub fn supports_fpic(target: *const std.Target) bool { | ... | @@ -84,6 +84,13 @@ pub fn supports_fpic(target: *const std.Target) bool { |
| 84 | }; | 84 | }; |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | pub fn defaultPie(target: *const std.Target) bool { | ||
| 88 | return switch (target.os.tag) { | ||
| 89 | .openbsd => true, | ||
| 90 | else => target.os.tag.isDarwin(), | ||
| 91 | }; | ||
| 92 | } | ||
| 93 | |||
| 87 | pub fn alwaysSingleThreaded(target: *const std.Target) bool { | 94 | pub fn alwaysSingleThreaded(target: *const std.Target) bool { |
| 88 | _ = target; | 95 | _ = target; |
| 89 | return false; | 96 | return false; |