Skip to content

Commit 0e771af

Browse files
gbaraldiRAI CI (GitHub Action Automation)
authored andcommitted
Default to the medium code model in x86 linux (JuliaLang#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 7ebe203 commit 0e771af

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>
@@ -1506,10 +1507,11 @@ void jl_dump_native_impl(void *native_code,
15061507
if (TheTriple.isOSLinux() || TheTriple.isOSFreeBSD()) {
15071508
RelocModel = Reloc::PIC_;
15081509
}
1510+
15091511
CodeModel::Model CMModel = CodeModel::Small;
1510-
if (TheTriple.isPPC()) {
1511-
// On PPC the small model is limited to 16bit offsets
1512-
CMModel = CodeModel::Medium;
1512+
if (TheTriple.isPPC() || (TheTriple.isX86() && TheTriple.isArch64Bit() && TheTriple.isOSLinux())) {
1513+
// On PPC the small model is limited to 16bit offsets. For very large images the small code model
1514+
CMModel = CodeModel::Medium; // isn't good enough on x86 so use Medium, it has no cost because only the image goes in .ldata
15131515
}
15141516
std::unique_ptr<TargetMachine> SourceTM(
15151517
jl_ExecutionEngine->getTarget().createTargetMachine(
@@ -1549,6 +1551,12 @@ void jl_dump_native_impl(void *native_code,
15491551
GlobalVariable::ExternalLinkage,
15501552
data, "jl_system_image_data");
15511553
sysdata->setAlignment(Align(64));
1554+
#if JL_LLVM_VERSION >= 180000
1555+
sysdata->setCodeModel(CodeModel::Large);
1556+
#else
1557+
if (TheTriple.isX86() && TheTriple.isArch64Bit() && TheTriple.isOSLinux())
1558+
sysdata->setSection(".ldata");
1559+
#endif
15521560
addComdat(sysdata, TheTriple);
15531561
Constant *len = ConstantInt::get(sysimgM.getDataLayout().getIntPtrType(Context), z->size);
15541562
addComdat(new GlobalVariable(sysimgM, len->getType(), true,

0 commit comments

Comments
 (0)