From 76102ea41f6369b2254b4a281001061e48d81ffb Mon Sep 17 00:00:00 2001 From: LemonBoy Date: Wed, 16 Jun 2021 12:14:50 +0200 Subject: [PATCH] stage1: Store the specified code model in the LLVM module This is needed for LTO builds to pick up the correct module. Closes #9132 --- src/stage1/codegen.cpp | 4 ++++ src/zig_llvm.cpp | 6 ++++++ src/zig_llvm.h | 1 + 3 files changed, 11 insertions(+) diff --git a/src/stage1/codegen.cpp b/src/stage1/codegen.cpp index 4aa02680a27f671b41b4fa413ae9e3118ed96b6f..6f9be3e705fc8350af8182e90500947c5b4fa165 100644 --- a/src/stage1/codegen.cpp +++ b/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 = ""; diff --git a/src/zig_llvm.cpp b/src/zig_llvm.cpp index 722b77406e87f3d069f872070d6a0aab080ef9a5..8c54af4bb45e3bbf94353972a6e7cb34aed356b0 100644 --- a/src/zig_llvm.cpp +++ b/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; diff --git a/src/zig_llvm.h b/src/zig_llvm.h index 0d08980835d93392e220c4373da655ac54be6630..32a969f70e1441d54e8a2d8e481b0942bb133f45 100644 --- a/src/zig_llvm.h +++ b/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); -- 2.54.0