Skip to content

Commit 0ac17ad

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 e1b2099 commit 0ac17ad

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

0 commit comments

Comments
 (0)