mirror of
https://github.com/ziglang/zig.git
synced 2026-02-21 16:54:52 +00:00
llvm: Set PIC level 1 for MIPS.
For hysterical raisins, MIPS always uses 1, regardless of `-fpic` vs `-fPIC`.
This commit is contained in:
parent
93cb44c805
commit
7d9edff11d
@ -1259,8 +1259,11 @@ pub const Object = struct {
|
|||||||
);
|
);
|
||||||
errdefer target_machine.dispose();
|
errdefer target_machine.dispose();
|
||||||
|
|
||||||
if (pic) module.setModulePICLevel();
|
const large_pic = target_util.usesLargePIC(comp.root_mod.resolved_target.result);
|
||||||
if (comp.config.pie) module.setModulePIELevel();
|
|
||||||
|
if (pic) module.setModulePICLevel(large_pic);
|
||||||
|
if (comp.config.pie) module.setModulePIELevel(large_pic);
|
||||||
|
|
||||||
if (code_model != .Default) module.setModuleCodeModel(code_model);
|
if (code_model != .Default) module.setModuleCodeModel(code_model);
|
||||||
|
|
||||||
if (comp.llvm_opt_bisect_limit >= 0) {
|
if (comp.llvm_opt_bisect_limit >= 0) {
|
||||||
|
|||||||
@ -53,10 +53,10 @@ pub const Module = opaque {
|
|||||||
extern fn LLVMDisposeModule(*Module) void;
|
extern fn LLVMDisposeModule(*Module) void;
|
||||||
|
|
||||||
pub const setModulePICLevel = ZigLLVMSetModulePICLevel;
|
pub const setModulePICLevel = ZigLLVMSetModulePICLevel;
|
||||||
extern fn ZigLLVMSetModulePICLevel(module: *Module) void;
|
extern fn ZigLLVMSetModulePICLevel(module: *Module, big: bool) void;
|
||||||
|
|
||||||
pub const setModulePIELevel = ZigLLVMSetModulePIELevel;
|
pub const setModulePIELevel = ZigLLVMSetModulePIELevel;
|
||||||
extern fn ZigLLVMSetModulePIELevel(module: *Module) void;
|
extern fn ZigLLVMSetModulePIELevel(module: *Module, large: bool) void;
|
||||||
|
|
||||||
pub const setModuleCodeModel = ZigLLVMSetModuleCodeModel;
|
pub const setModuleCodeModel = ZigLLVMSetModuleCodeModel;
|
||||||
extern fn ZigLLVMSetModuleCodeModel(module: *Module, code_model: CodeModel) void;
|
extern fn ZigLLVMSetModuleCodeModel(module: *Module, code_model: CodeModel) void;
|
||||||
|
|||||||
@ -49,6 +49,12 @@ pub fn requiresPIC(target: std.Target, linking_libc: bool) bool {
|
|||||||
(target.abi == .ohos and target.cpu.arch == .aarch64);
|
(target.abi == .ohos and target.cpu.arch == .aarch64);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn usesLargePIC(target: std.Target) bool {
|
||||||
|
// 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();
|
||||||
|
}
|
||||||
|
|
||||||
/// This is not whether the target supports Position Independent Code, but whether the -fPIC
|
/// This is not whether the target supports Position Independent Code, but whether the -fPIC
|
||||||
/// C compiler argument is valid to Clang.
|
/// C compiler argument is valid to Clang.
|
||||||
pub fn supports_fpic(target: std.Target) bool {
|
pub fn supports_fpic(target: std.Target) bool {
|
||||||
|
|||||||
@ -81,7 +81,7 @@ static const bool assertions_on = false;
|
|||||||
|
|
||||||
LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple,
|
LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple,
|
||||||
const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc,
|
const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc,
|
||||||
LLVMCodeModel CodeModel, bool function_sections, bool data_sections, ZigLLVMABIType float_abi,
|
LLVMCodeModel CodeModel, bool function_sections, bool data_sections, ZigLLVMABIType float_abi,
|
||||||
const char *abi_name)
|
const char *abi_name)
|
||||||
{
|
{
|
||||||
std::optional<Reloc::Model> RM;
|
std::optional<Reloc::Model> RM;
|
||||||
@ -430,12 +430,12 @@ void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv) {
|
|||||||
cl::ParseCommandLineOptions(argc, argv);
|
cl::ParseCommandLineOptions(argc, argv);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZigLLVMSetModulePICLevel(LLVMModuleRef module) {
|
void ZigLLVMSetModulePICLevel(LLVMModuleRef module, bool big) {
|
||||||
unwrap(module)->setPICLevel(PICLevel::Level::BigPIC);
|
unwrap(module)->setPICLevel(big ? PICLevel::Level::BigPIC : PICLevel::Level::SmallPIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZigLLVMSetModulePIELevel(LLVMModuleRef module) {
|
void ZigLLVMSetModulePIELevel(LLVMModuleRef module, bool large) {
|
||||||
unwrap(module)->setPIELevel(PIELevel::Level::Large);
|
unwrap(module)->setPIELevel(large ? PIELevel::Level::Large : PIELevel::Level::Small);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ZigLLVMSetModuleCodeModel(LLVMModuleRef module, LLVMCodeModel code_model) {
|
void ZigLLVMSetModuleCodeModel(LLVMModuleRef module, LLVMCodeModel code_model) {
|
||||||
|
|||||||
@ -77,7 +77,7 @@ enum ZigLLVMABIType {
|
|||||||
|
|
||||||
ZIG_EXTERN_C LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple,
|
ZIG_EXTERN_C LLVMTargetMachineRef ZigLLVMCreateTargetMachine(LLVMTargetRef T, const char *Triple,
|
||||||
const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc,
|
const char *CPU, const char *Features, LLVMCodeGenOptLevel Level, LLVMRelocMode Reloc,
|
||||||
LLVMCodeModel CodeModel, bool function_sections, bool data_sections, enum ZigLLVMABIType float_abi,
|
LLVMCodeModel CodeModel, bool function_sections, bool data_sections, enum ZigLLVMABIType float_abi,
|
||||||
const char *abi_name);
|
const char *abi_name);
|
||||||
|
|
||||||
ZIG_EXTERN_C void ZigLLVMSetOptBisectLimit(LLVMContextRef context_ref, int limit);
|
ZIG_EXTERN_C void ZigLLVMSetOptBisectLimit(LLVMContextRef context_ref, int limit);
|
||||||
@ -154,8 +154,8 @@ enum ZigLLVM_CallingConv {
|
|||||||
ZigLLVM_MaxID = 1023,
|
ZigLLVM_MaxID = 1023,
|
||||||
};
|
};
|
||||||
|
|
||||||
ZIG_EXTERN_C void ZigLLVMSetModulePICLevel(LLVMModuleRef module);
|
ZIG_EXTERN_C void ZigLLVMSetModulePICLevel(LLVMModuleRef module, bool big);
|
||||||
ZIG_EXTERN_C void ZigLLVMSetModulePIELevel(LLVMModuleRef module);
|
ZIG_EXTERN_C void ZigLLVMSetModulePIELevel(LLVMModuleRef module, bool large);
|
||||||
ZIG_EXTERN_C void ZigLLVMSetModuleCodeModel(LLVMModuleRef module, LLVMCodeModel code_model);
|
ZIG_EXTERN_C void ZigLLVMSetModuleCodeModel(LLVMModuleRef module, LLVMCodeModel code_model);
|
||||||
|
|
||||||
ZIG_EXTERN_C void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv);
|
ZIG_EXTERN_C void ZigLLVMParseCommandLineOptions(size_t argc, const char *const *argv);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user