Skip to content

Commit

Permalink
[ORC] Drop Comdat when discarding IR symbol
Browse files Browse the repository at this point in the history
According to the IR verifier, "Declaration[s] may not be in a Comdat!"

This is a re-commit of 76b3f0b and
87d7838 with updates to the test:
 * Force emission of the extra-module, to trigger the bug after D138264,
   by providing a second symbol @g, and making the comdat nodeduplicate.
   (Technically only one is needed, but two should be safer.)
 * Name the comdat $f to avoid failure on Windows:
   LLVM ERROR: Associative COMDAT symbol 'c' does not exist.
 * Mark the test as UNSUPPORTED on macOS, MachO doesn't support COMDATs.

Differential Revision: https://reviews.llvm.org/D142443

(cherry picked from commit 50ca8b3)
  • Loading branch information
hahnjo authored and tstellar committed Feb 6, 2023
1 parent bd00ad5 commit 055ee22
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
4 changes: 4 additions & 0 deletions llvm/lib/ExecutionEngine/Orc/Layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,10 @@ void IRMaterializationUnit::discard(const JITDylib &JD,
assert(!I->second->isDeclaration() &&
"Discard should only apply to definitions");
I->second->setLinkage(GlobalValue::AvailableExternallyLinkage);
// According to the IR verifier, "Declaration[s] may not be in a Comdat!"
// Remove it, if this is a GlobalObject.
if (auto *GO = dyn_cast<GlobalObject>(I->second))
GO->setComdat(nullptr);
SymbolToDefinition.erase(I);
}

Expand Down
12 changes: 12 additions & 0 deletions llvm/test/ExecutionEngine/Orc/Inputs/weak-comdat-def.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
define i32 @g() {
entry:
ret i32 0
}

$f = comdat nodeduplicate

define i32 @f() comdat {
entry:
%0 = call i32 @g()
ret i32 %0
}
18 changes: 18 additions & 0 deletions llvm/test/ExecutionEngine/Orc/weak-comdat.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
; RUN: lli -extra-module %p/Inputs/weak-comdat-def.ll %s
; UNSUPPORTED: target={{.*}}-darwin{{.*}}

declare i32 @g()

$f = comdat nodeduplicate

define weak i32 @f() comdat {
entry:
%0 = call i32 @g()
ret i32 %0
}

define i32 @main() {
entry:
%0 = call i32 @f()
ret i32 %0
}

0 comments on commit 055ee22

Please sign in to comment.