From 6e0dbb1b10cb1daa2a6a8e6ce4f948b03e2db59f Mon Sep 17 00:00:00 2001 From: Gabriel Baraldi Date: Mon, 19 Feb 2024 16:46:12 -0300 Subject: [PATCH 1/3] Default to the medium code model in x86 linux --- src/aotcompile.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/aotcompile.cpp b/src/aotcompile.cpp index 54c92fb688d30..29b52b7484fbb 100644 --- a/src/aotcompile.cpp +++ b/src/aotcompile.cpp @@ -4,6 +4,7 @@ #include "platform.h" // target support +#include "llvm/Support/CodeGen.h" #include #include #include @@ -1609,10 +1610,11 @@ void jl_dump_native_impl(void *native_code, if (TheTriple.isOSLinux() || TheTriple.isOSFreeBSD()) { RelocModel = Reloc::PIC_; } + CodeModel::Model CMModel = CodeModel::Small; - if (TheTriple.isPPC()) { - // On PPC the small model is limited to 16bit offsets - CMModel = CodeModel::Medium; + if (TheTriple.isPPC() || (TheTriple.isX86() && TheTriple.isArch64Bit() && TheTriple.isOSLinux())) { + // On PPC the small model is limited to 16bit offsets. For very large images the small code model + CMModel = CodeModel::Medium; // isn't good enough on x86 so use Medium, it has no cost because only the image goes in .ldata } std::unique_ptr SourceTM( jl_ExecutionEngine->getTarget().createTargetMachine( @@ -1655,6 +1657,8 @@ void jl_dump_native_impl(void *native_code, GlobalVariable::ExternalLinkage, data, "jl_system_image_data"); sysdata->setAlignment(Align(64)); + if (TheTriple.isX86() && TheTriple.isArch64Bit() && TheTriple.isOSLinux()) + sysdata->setSection(".ldata"); addComdat(sysdata, TheTriple); Constant *len = ConstantInt::get(sysimgM.getDataLayout().getIntPtrType(Context), z->size); addComdat(new GlobalVariable(sysimgM, len->getType(), true, From 4a1514892978e7f46527d34b1e70cb63360a5f17 Mon Sep 17 00:00:00 2001 From: gbaraldi Date: Fri, 8 Mar 2024 12:31:23 -0300 Subject: [PATCH 2/3] Add ifdef for LLVM 18 change --- src/aotcompile.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/aotcompile.cpp b/src/aotcompile.cpp index 614a28bd84d27..c29fb77afb39f 100644 --- a/src/aotcompile.cpp +++ b/src/aotcompile.cpp @@ -1658,7 +1658,11 @@ void jl_dump_native_impl(void *native_code, data, "jl_system_image_data"); sysdata->setAlignment(Align(64)); if (TheTriple.isX86() && TheTriple.isArch64Bit() && TheTriple.isOSLinux()) +#if JL_LLVM_VERSION >= 180000 + sysdata->setCodeModel(CodeModel::Large); +#else sysdata->setSection(".ldata"); +#endif addComdat(sysdata, TheTriple); Constant *len = ConstantInt::get(sysimgM.getDataLayout().getIntPtrType(Context), z->size); addComdat(new GlobalVariable(sysimgM, len->getType(), true, From af8ef5d45b67861b33cc9412bd14cbe21b9c851e Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Thu, 14 Mar 2024 11:41:49 -0400 Subject: [PATCH 3/3] Update src/aotcompile.cpp --- src/aotcompile.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/aotcompile.cpp b/src/aotcompile.cpp index c29fb77afb39f..5929f7bf2cd85 100644 --- a/src/aotcompile.cpp +++ b/src/aotcompile.cpp @@ -1657,10 +1657,10 @@ void jl_dump_native_impl(void *native_code, GlobalVariable::ExternalLinkage, data, "jl_system_image_data"); sysdata->setAlignment(Align(64)); - if (TheTriple.isX86() && TheTriple.isArch64Bit() && TheTriple.isOSLinux()) #if JL_LLVM_VERSION >= 180000 - sysdata->setCodeModel(CodeModel::Large); + sysdata->setCodeModel(CodeModel::Large); #else + if (TheTriple.isX86() && TheTriple.isArch64Bit() && TheTriple.isOSLinux()) sysdata->setSection(".ldata"); #endif addComdat(sysdata, TheTriple);