Skip to content

Commit

Permalink
Default to the medium code model in x86 linux (JuliaLang#53391)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
gbaraldi authored and Drvi committed Jun 7, 2024
1 parent d997433 commit a267f6b
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/aotcompile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "platform.h"

// target support
#include "llvm/Support/CodeGen.h"
#include <llvm/ADT/Triple.h>
#include <llvm/ADT/Statistic.h>
#include <llvm/Analysis/TargetLibraryInfo.h>
Expand Down Expand Up @@ -1498,10 +1499,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<TargetMachine> SourceTM(
jl_ExecutionEngine->getTarget().createTargetMachine(
Expand Down Expand Up @@ -1541,6 +1543,12 @@ void jl_dump_native_impl(void *native_code,
GlobalVariable::ExternalLinkage,
data, "jl_system_image_data");
sysdata->setAlignment(Align(64));
#if JL_LLVM_VERSION >= 180000
sysdata->setCodeModel(CodeModel::Large);
#else
if (TheTriple.isX86() && TheTriple.isArch64Bit() && TheTriple.isOSLinux())
sysdata->setSection(".ldata");
#endif
addComdat(sysdata, TheTriple);
Constant *len = ConstantInt::get(sysimgM.getDataLayout().getIntPtrType(Context), z->size);
addComdat(new GlobalVariable(sysimgM, len->getType(), true,
Expand Down

0 comments on commit a267f6b

Please sign in to comment.