Commit 76102ea41f

LemonBoy <thatlemon@gmail.com>
2021-06-16 12:14:50
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 74ca811
Changed files (3)
src/stage1/codegen.cpp
@@ -9289,6 +9289,10 @@ static void init(CodeGen *g) {
         ZigLLVMSetModulePIELevel(g->module);
     }
 
+    if (g->code_model != CodeModelDefault) {
+        ZigLLVMSetModuleCodeModel(g->module, to_llvm_code_model(g));
+    }
+
     const char *target_specific_cpu_args = "";
     const char *target_specific_features = "";
 
src/zig_llvm.cpp
@@ -969,6 +969,12 @@ void ZigLLVMSetModulePIELevel(LLVMModuleRef module) {
     unwrap(module)->setPIELevel(PIELevel::Level::Large);
 }
 
+void ZigLLVMSetModuleCodeModel(LLVMModuleRef module, LLVMCodeModel code_model) {
+    bool JIT;
+    unwrap(module)->setCodeModel(*unwrap(code_model, JIT));
+    assert(!JIT);
+}
+
 static AtomicOrdering mapFromLLVMOrdering(LLVMAtomicOrdering Ordering) {
     switch (Ordering) {
         case LLVMAtomicOrderingNotAtomic: return AtomicOrdering::NotAtomic;
src/zig_llvm.h
@@ -208,6 +208,7 @@ ZIG_EXTERN_C void ZigLLVMAddModuleDebugInfoFlag(LLVMModuleRef module);
 ZIG_EXTERN_C void ZigLLVMAddModuleCodeViewFlag(LLVMModuleRef module);
 ZIG_EXTERN_C void ZigLLVMSetModulePICLevel(LLVMModuleRef module);
 ZIG_EXTERN_C void ZigLLVMSetModulePIELevel(LLVMModuleRef module);
+ZIG_EXTERN_C void ZigLLVMSetModuleCodeModel(LLVMModuleRef module, LLVMCodeModel code_model);
 
 ZIG_EXTERN_C void ZigLLVMSetCurrentDebugLocation(LLVMBuilderRef builder, int line, int column,
         struct ZigLLVMDIScope *scope);