Skip to content

Commit b9e991b

Browse files
gbaraldiKristofferC
authored andcommitted
Default to the medium code model in x86 linux (#53391)
This shouldn't have any cost on smaller images because the only thing that gets put into ldata is the system image data, which is only reference via `dlsym`. This allows for images larger than 2gb (tested by putting a 2gb array in the base image) I did not test how this might be handled in other platforms (Windows doesn't support it). (cherry picked from commit 0f04b33)
1 parent f17965f commit b9e991b

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/aotcompile.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "platform.h"
55

66
// target support
7+
#include "llvm/Support/CodeGen.h"
78
#include <llvm/ADT/Triple.h>
89
#include <llvm/ADT/Statistic.h>
910
#include <llvm/Analysis/TargetLibraryInfo.h>
@@ -1607,10 +1608,11 @@ void jl_dump_native_impl(void *native_code,
16071608
if (TheTriple.isOSLinux() || TheTriple.isOSFreeBSD()) {
16081609
RelocModel = Reloc::PIC_;
16091610
}
1611+
16101612
CodeModel::Model CMModel = CodeModel::Small;
1611-
if (TheTriple.isPPC()) {
1612-
// On PPC the small model is limited to 16bit offsets
1613-
CMModel = CodeModel::Medium;
1613+
if (TheTriple.isPPC() || (TheTriple.isX86() && TheTriple.isArch64Bit() && TheTriple.isOSLinux())) {
1614+
// On PPC the small model is limited to 16bit offsets. For very large images the small code model
1615+
CMModel = CodeModel::Medium; // isn't good enough on x86 so use Medium, it has no cost because only the image goes in .ldata
16141616
}
16151617
std::unique_ptr<TargetMachine> SourceTM(
16161618
jl_ExecutionEngine->getTarget().createTargetMachine(
@@ -1653,6 +1655,12 @@ void jl_dump_native_impl(void *native_code,
16531655
GlobalVariable::ExternalLinkage,
16541656
data, "jl_system_image_data");
16551657
sysdata->setAlignment(Align(64));
1658+
#if JL_LLVM_VERSION >= 180000
1659+
sysdata->setCodeModel(CodeModel::Large);
1660+
#else
1661+
if (TheTriple.isX86() && TheTriple.isArch64Bit() && TheTriple.isOSLinux())
1662+
sysdata->setSection(".ldata");
1663+
#endif
16561664
addComdat(sysdata, TheTriple);
16571665
Constant *len = ConstantInt::get(sysimgM.getDataLayout().getIntPtrType(Context), z->size);
16581666
addComdat(new GlobalVariable(sysimgM, len->getType(), true,

0 commit comments

Comments
 (0)