Skip to content

Commit 055ee22

Browse files
hahnjotstellar
authored andcommitted
[ORC] Drop Comdat when discarding IR symbol
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)
1 parent bd00ad5 commit 055ee22

File tree

3 files changed

+34
-0
lines changed

3 files changed

+34
-0
lines changed

llvm/lib/ExecutionEngine/Orc/Layer.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,10 @@ void IRMaterializationUnit::discard(const JITDylib &JD,
125125
assert(!I->second->isDeclaration() &&
126126
"Discard should only apply to definitions");
127127
I->second->setLinkage(GlobalValue::AvailableExternallyLinkage);
128+
// According to the IR verifier, "Declaration[s] may not be in a Comdat!"
129+
// Remove it, if this is a GlobalObject.
130+
if (auto *GO = dyn_cast<GlobalObject>(I->second))
131+
GO->setComdat(nullptr);
128132
SymbolToDefinition.erase(I);
129133
}
130134

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
define i32 @g() {
2+
entry:
3+
ret i32 0
4+
}
5+
6+
$f = comdat nodeduplicate
7+
8+
define i32 @f() comdat {
9+
entry:
10+
%0 = call i32 @g()
11+
ret i32 %0
12+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
; RUN: lli -extra-module %p/Inputs/weak-comdat-def.ll %s
2+
; UNSUPPORTED: target={{.*}}-darwin{{.*}}
3+
4+
declare i32 @g()
5+
6+
$f = comdat nodeduplicate
7+
8+
define weak i32 @f() comdat {
9+
entry:
10+
%0 = call i32 @g()
11+
ret i32 %0
12+
}
13+
14+
define i32 @main() {
15+
entry:
16+
%0 = call i32 @f()
17+
ret i32 %0
18+
}

0 commit comments

Comments
 (0)