Skip to content

Commit

Permalink
Prevent local optimizations of definitions
Browse files Browse the repository at this point in the history
In case of weak definitions, JITLink might merge symbols because we
currently add all llvm::Module's into a single JITDylib. For merges
that late in the pipeline, we also have to prevent optimizations that
take advantage of "localness" to avoid out-of-range relocations for
example on AArch64.
  • Loading branch information
hahnjo authored and jenkins committed Dec 12, 2024
1 parent fb158b8 commit 5ea7949
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions lib/Interpreter/BackendPasses.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,24 @@ namespace {
namespace {
class PreventLocalOptPass : public PassInfoMixin<PreventLocalOptPass> {
bool runOnGlobal(GlobalValue& GV) {
if (!GV.isDeclaration())
return false; // no change.

// GV is a declaration with no definition. Make sure to prevent any
// optimization that tries to take advantage of the actual definition
// being "local" because we have no influence on the memory layout of
// data sections and how "close" they are to the code.

bool changed = false;

// Prevent any optimization that tries to take advantage of the actual
// definition being "local" because we have no influence on the memory
// layout of sections and how "close" they are.

if (GV.hasLocalLinkage()) {
GV.setLinkage(llvm::GlobalValue::ExternalLinkage);
changed = true;
if (GV.isDeclaration()) {
// For declarations with no definition, we can simply adjust the
// linkage.
GV.setLinkage(llvm::GlobalValue::ExternalLinkage);
changed = true;
} else {
// FIXME: Not clear what would be the right linkage. We also cannot
// continue because "GlobalValue with local linkage [...] must be
// dso_local!"
return false;
}
}

if (!GV.hasDefaultVisibility()) {
Expand All @@ -172,7 +177,7 @@ namespace {
}

// Set DSO locality last because setLinkage() and setVisibility() check
// isImplicitDSOLocal().
// isImplicitDSOLocal() and then might call setDSOLocal(true).
if (GV.isDSOLocal()) {
GV.setDSOLocal(false);
changed = true;
Expand Down

0 comments on commit 5ea7949

Please sign in to comment.