Commit 15b4c01ab1
Changed files (2)
src
codegen
src/codegen/llvm.zig
@@ -1107,12 +1107,12 @@ pub const Object = struct {
const behavior_max = try o.builder.metadataConstant(try o.builder.intConst(.i32, 7));
const behavior_min = try o.builder.metadataConstant(try o.builder.intConst(.i32, 8));
- const large_pic = target_util.usesLargePIC(comp.root_mod.resolved_target.result);
+ const pic_level = target_util.picLevel(comp.root_mod.resolved_target.result);
if (comp.root_mod.pic) {
module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(
behavior_min,
try o.builder.metadataString("PIC Level"),
- try o.builder.metadataConstant(try o.builder.intConst(.i32, @as(i32, if (large_pic) 2 else 1))),
+ try o.builder.metadataConstant(try o.builder.intConst(.i32, pic_level)),
));
}
@@ -1120,7 +1120,7 @@ pub const Object = struct {
module_flags.appendAssumeCapacity(try o.builder.metadataModuleFlag(
behavior_max,
try o.builder.metadataString("PIE Level"),
- try o.builder.metadataConstant(try o.builder.intConst(.i32, @as(i32, if (large_pic) 2 else 1))),
+ try o.builder.metadataConstant(try o.builder.intConst(.i32, pic_level)),
));
}
src/target.zig
@@ -49,10 +49,10 @@ pub fn requiresPIC(target: std.Target, linking_libc: bool) bool {
(target.abi == .ohos and target.cpu.arch == .aarch64);
}
-pub fn usesLargePIC(target: std.Target) bool {
+pub fn picLevel(target: std.Target) u32 {
// MIPS always uses PIC level 1; other platforms vary in their default PIC levels, but they
// support both level 1 and 2, in which case we prefer 2.
- return !target.cpu.arch.isMIPS();
+ return if (target.cpu.arch.isMIPS()) 1 else 2;
}
/// This is not whether the target supports Position Independent Code, but whether the -fPIC