Skip to content

Commit ccb6e16

Browse files
LemonBoyVexu
authored andcommitted
stage1: Store the specified code model in the LLVM module
This is needed for LTO builds to pick up the correct module. Closes #9132
1 parent b9e7859 commit ccb6e16

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

src/stage1/codegen.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9289,6 +9289,10 @@ static void init(CodeGen *g) {
92899289
ZigLLVMSetModulePIELevel(g->module);
92909290
}
92919291

9292+
if (g->code_model != CodeModelDefault) {
9293+
ZigLLVMSetModuleCodeModel(g->module, to_llvm_code_model(g));
9294+
}
9295+
92929296
const char *target_specific_cpu_args = "";
92939297
const char *target_specific_features = "";
92949298

src/zig_llvm.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -969,6 +969,12 @@ void ZigLLVMSetModulePIELevel(LLVMModuleRef module) {
969969
unwrap(module)->setPIELevel(PIELevel::Level::Large);
970970
}
971971

972+
void ZigLLVMSetModuleCodeModel(LLVMModuleRef module, LLVMCodeModel code_model) {
973+
bool JIT;
974+
unwrap(module)->setCodeModel(*unwrap(code_model, JIT));
975+
assert(!JIT);
976+
}
977+
972978
static AtomicOrdering mapFromLLVMOrdering(LLVMAtomicOrdering Ordering) {
973979
switch (Ordering) {
974980
case LLVMAtomicOrderingNotAtomic: return AtomicOrdering::NotAtomic;

src/zig_llvm.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ ZIG_EXTERN_C void ZigLLVMAddModuleDebugInfoFlag(LLVMModuleRef module);
208208
ZIG_EXTERN_C void ZigLLVMAddModuleCodeViewFlag(LLVMModuleRef module);
209209
ZIG_EXTERN_C void ZigLLVMSetModulePICLevel(LLVMModuleRef module);
210210
ZIG_EXTERN_C void ZigLLVMSetModulePIELevel(LLVMModuleRef module);
211+
ZIG_EXTERN_C void ZigLLVMSetModuleCodeModel(LLVMModuleRef module, LLVMCodeModel code_model);
211212

212213
ZIG_EXTERN_C void ZigLLVMSetCurrentDebugLocation(LLVMBuilderRef builder, int line, int column,
213214
struct ZigLLVMDIScope *scope);

0 commit comments

Comments
 (0)