| author | |
| committer | |
| log | 7d9edff11d4c0dd6793bfd4bb2d7e3c2d32c88cd |
| tree | 82c547eab6f1cd93cef5905e88c14b0438cc5a12 |
| parent | 93cb44c80582dd02b63b02e7bb7e54d7ad8a4ebc |
| signature |
For hysterical raisins, MIPS always uses 1, regardless of `-fpic` vs `-fPIC`.5 files changed, 21 insertions(+), 12 deletions(-)
src/codegen/llvm.zig+5-2| ... | @@ -1259,8 +1259,11 @@ pub const Object = struct { | ... | @@ -1259,8 +1259,11 @@ pub const Object = struct { |
| 1259 | ); | 1259 | ); |
| 1260 | errdefer target_machine.dispose(); | 1260 | errdefer target_machine.dispose(); |
| 1261 | 1261 | ||
| 1262 | if (pic) module.setModulePICLevel(); | 1262 | const large_pic = target_util.usesLargePIC(comp.root_mod.resolved_target.result); |
| 1263 | if (comp.config.pie) module.setModulePIELevel(); | 1263 | |
| 1264 | if (pic) module.setModulePICLevel(large_pic); | ||
| 1265 | if (comp.config.pie) module.setModulePIELevel(large_pic); | ||
| 1266 | |||
| 1264 | if (code_model != .Default) module.setModuleCodeModel(code_model); | 1267 | if (code_model != .Default) module.setModuleCodeModel(code_model); |
| 1265 | 1268 | ||
| 1266 | if (comp.llvm_opt_bisect_limit >= 0) { | 1269 | if (comp.llvm_opt_bisect_limit >= 0) { |
src/codegen/llvm/bindings.zig+2-2| ... | @@ -53,10 +53,10 @@ pub const Module = opaque { | ... | @@ -53,10 +53,10 @@ pub const Module = opaque { |
| 53 | extern fn LLVMDisposeModule(*Module) void; | 53 | extern fn LLVMDisposeModule(*Module) void; |
| 54 | 54 | ||
| 55 | pub const setModulePICLevel = ZigLLVMSetModulePICLevel; | 55 | pub const setModulePICLevel = ZigLLVMSetModulePICLevel; |
| 56 | extern fn ZigLLVMSetModulePICLevel(module: *Module) void; | 56 | extern fn ZigLLVMSetModulePICLevel(module: *Module, big: bool) void; |
| 57 | 57 | ||
| 58 | pub const setModulePIELevel = ZigLLVMSetModulePIELevel; | 58 | pub const setModulePIELevel = ZigLLVMSetModulePIELevel; |
| 59 | extern fn ZigLLVMSetModulePIELevel(module: *Module) void; | 59 | extern fn ZigLLVMSetModulePIELevel(module: *Module, large: bool) void; |
| 60 | 60 | ||
| 61 | pub const setModuleCodeModel = ZigLLVMSetModuleCodeModel; | 61 | pub const setModuleCodeModel = ZigLLVMSetModuleCodeModel; |
| 62 | extern fn ZigLLVMSetModuleCodeModel(module: *Module, code_model: CodeModel) void; | 62 | extern fn ZigLLVMSetModuleCodeModel(module: *Module, code_model: CodeModel) void; |
src/target.zig+6| ... | @@ -49,6 +49,12 @@ pub fn requiresPIC(target: std.Target, linking_libc: bool) bool { | ... | @@ -49,6 +49,12 @@ pub fn requiresPIC(target: std.Target, linking_libc: bool) bool { |
| 49 | (target.abi == .ohos and target.cpu.arch == .aarch64); | 49 | (target.abi == .ohos and target.cpu.arch == .aarch64); |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | pub fn usesLargePIC(target: std.Target) bool { | ||
| 53 | // MIPS always uses PIC level 1; other platforms vary in their default PIC levels, but they | ||
| 54 | // support both level 1 and 2, in which case we prefer 2. | ||
| 55 | return !target.cpu.arch.isMIPS(); | ||
| 56 | } | ||
| 57 | |||
| 52 | /// This is not whether the target supports Position Independent Code, but whether the -fPIC | 58 | /// This is not whether the target supports Position Independent Code, but whether the -fPIC |
| 53 | /// C compiler argument is valid to Clang. | 59 | /// C compiler argument is valid to Clang. |
| 54 | pub fn supports_fpic(target: std.Target) bool { | 60 | pub fn supports_fpic(target: std.Target) bool { |
src/zig_llvm.cpp+5-5| ... | @@ -81,7 +81,7 @@ static const bool assertions_on = false; | ... | @@ -81,7 +81,7 @@ static const bool assertions_on = false; |
| 81 | 81 | ||
| 82 | LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple, | 82 | LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple, |
| 83 | const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, | 83 | const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, |
| 84 | LLVMCodeModel CodeModel, bool function_sections, bool data_sections, ZigLLVMABIType float_abi, | 84 | LLVMCodeModel CodeModel, bool function_sections, bool data_sections, ZigLLVMABIType float_abi, |
| 85 | const char *abi_name) | 85 | const char *abi_name) |
| 86 | { | 86 | { |
| 87 | std::optional<Reloc::Model> RM; | 87 | std::optional<Reloc::Model> RM; |
| ... | @@ -430,12 +430,12 @@ void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv) { | ... | @@ -430,12 +430,12 @@ void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv) { |
| 430 | cl::ParseCommandLineOptions(argc, argv); | 430 | cl::ParseCommandLineOptions(argc, argv); |
| 431 | } | 431 | } |
| 432 | 432 | ||
| 433 | void ZigLLVMSetModulePICLevel(LLVMModuleRef module) { | 433 | void ZigLLVMSetModulePICLevel(LLVMModuleRef module, bool big) { |
| 434 | unwrap(module)->setPICLevel(PICLevel::Level::BigPIC); | 434 | unwrap(module)->setPICLevel(big ? PICLevel::Level::BigPIC : PICLevel::Level::SmallPIC); |
| 435 | } | 435 | } |
| 436 | 436 | ||
| 437 | void ZigLLVMSetModulePIELevel(LLVMModuleRef module) { | 437 | void ZigLLVMSetModulePIELevel(LLVMModuleRef module, bool large) { |
| 438 | unwrap(module)->setPIELevel(PIELevel::Level::Large); | 438 | unwrap(module)->setPIELevel(large ? PIELevel::Level::Large : PIELevel::Level::Small); |
| 439 | } | 439 | } |
| 440 | 440 | ||
| 441 | void ZigLLVMSetModuleCodeModel(LLVMModuleRef module, LLVMCodeModel code_model) { | 441 | void ZigLLVMSetModuleCodeModel(LLVMModuleRef module, LLVMCodeModel code_model) { |
src/zig_llvm.h+3-3| ... | @@ -77,7 +77,7 @@ enum ZigLLVMABIType { | ... | @@ -77,7 +77,7 @@ enum ZigLLVMABIType { |
| 77 | 77 | ||
| 78 | ZIG_EXTERN_C LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple, | 78 | ZIG_EXTERN_C LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple, |
| 79 | const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, | 79 | const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc, |
| 80 | LLVMCodeModel CodeModel, bool function_sections, bool data_sections, enum ZigLLVMABIType float_abi, | 80 | LLVMCodeModel CodeModel, bool function_sections, bool data_sections, enum ZigLLVMABIType float_abi, |
| 81 | const char *abi_name); | 81 | const char *abi_name); |
| 82 | 82 | ||
| 83 | ZIG_EXTERN_C void ZigLLVMSetOptBisectLimit(LLVMContextRef context_ref, int limit); | 83 | ZIG_EXTERN_C void ZigLLVMSetOptBisectLimit(LLVMContextRef context_ref, int limit); |
| ... | @@ -154,8 +154,8 @@ enum ZigLLVM_CallingConv { | ... | @@ -154,8 +154,8 @@ enum ZigLLVM_CallingConv { |
| 154 | ZigLLVM_MaxID = 1023, | 154 | ZigLLVM_MaxID = 1023, |
| 155 | }; | 155 | }; |
| 156 | 156 | ||
| 157 | ZIG_EXTERN_C void ZigLLVMSetModulePICLevel(LLVMModuleRef module); | 157 | ZIG_EXTERN_C void ZigLLVMSetModulePICLevel(LLVMModuleRef module, bool big); |
| 158 | ZIG_EXTERN_C void ZigLLVMSetModulePIELevel(LLVMModuleRef module); | 158 | ZIG_EXTERN_C void ZigLLVMSetModulePIELevel(LLVMModuleRef module, bool large); |
| 159 | ZIG_EXTERN_C void ZigLLVMSetModuleCodeModel(LLVMModuleRef module, LLVMCodeModel code_model); | 159 | ZIG_EXTERN_C void ZigLLVMSetModuleCodeModel(LLVMModuleRef module, LLVMCodeModel code_model); |
| 160 | 160 | ||
| 161 | ZIG_EXTERN_C void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv); | 161 | ZIG_EXTERN_C void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv); |