Skip to content

Commit 72ea1a7

Browse files
committed
[ORC] Fix weak hidden symbols failure on PPC with runtimedyld
Fix "JIT session error: Symbols not found: [ DW.ref.__gxx_personality_v0 ] error" which happens when trying to use exceptions on ppc linux. To do this, it expands AutoClaimSymbols option in RTDyldObjectLinkingLayer to also claim weak symbols before they are tried to be resovled. In ppc linux, DW.ref symbols is emitted as weak hidden symbols in the later stage of MC pipeline. This means when using IRLayer (i.e. LLJIT), IRLayer will not claim responsibility for such symbols and RuntimeDyld will skip defining this symbol even though it couldn't resolve corresponding external symbol. Reviewed By: sgraenitz Differential Revision: https://reviews.llvm.org/D129175
1 parent 0cc3c18 commit 72ea1a7

File tree

3 files changed

+40
-5
lines changed

3 files changed

+40
-5
lines changed

clang/unittests/Interpreter/ExceptionTests/InterpreterExceptionTest.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,6 @@ extern "C" int throw_exception() {
9898
// FIXME: Re-enable the excluded target triples.
9999
const clang::CompilerInstance *CI = Interp->getCompilerInstance();
100100
const llvm::Triple &Triple = CI->getASTContext().getTargetInfo().getTriple();
101-
// FIXME: PPC fails due to `Symbols not found: [DW.ref.__gxx_personality_v0]`
102-
// The current understanding is that the JIT should emit this symbol if it was
103-
// not (eg. the way passing clang -fPIC does it).
104-
if (Triple.isPPC())
105-
return;
106101

107102
// FIXME: ARM fails due to `Not implemented relocation type!`
108103
if (Triple.isARM())

llvm/lib/ExecutionEngine/Orc/LLJIT.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,6 +746,11 @@ LLJIT::createObjectLinkingLayer(LLJITBuilderState &S, ExecutionSession &ES) {
746746
Layer->setAutoClaimResponsibilityForObjectSymbols(true);
747747
}
748748

749+
if (S.JTMB->getTargetTriple().isOSBinFormatELF() &&
750+
(S.JTMB->getTargetTriple().getArch() == Triple::ArchType::ppc64 ||
751+
S.JTMB->getTargetTriple().getArch() == Triple::ArchType::ppc64le))
752+
Layer->setAutoClaimResponsibilityForObjectSymbols(true);
753+
749754
// FIXME: Explicit conversion to std::unique_ptr<ObjectLayer> added to silence
750755
// errors from some GCC / libstdc++ bots. Remove this conversion (i.e.
751756
// just return ObjLinkingLayer) once those bots are upgraded.

llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ void RTDyldObjectLinkingLayer::emit(
108108
// filter these later.
109109
auto InternalSymbols = std::make_shared<std::set<StringRef>>();
110110
{
111+
SymbolFlagsMap ExtraSymbolsToClaim;
111112
for (auto &Sym : (*Obj)->symbols()) {
112113

113114
// Skip file symbols.
@@ -128,6 +129,33 @@ void RTDyldObjectLinkingLayer::emit(
128129
return;
129130
}
130131

132+
// Try to claim responsibility of weak symbols
133+
// if AutoClaimObjectSymbols flag is set.
134+
if (AutoClaimObjectSymbols &&
135+
(*SymFlagsOrErr & object::BasicSymbolRef::SF_Weak)) {
136+
auto SymName = Sym.getName();
137+
if (!SymName) {
138+
ES.reportError(SymName.takeError());
139+
R->failMaterialization();
140+
return;
141+
}
142+
143+
// Already included in responsibility set, skip it
144+
SymbolStringPtr SymbolName = ES.intern(*SymName);
145+
if (R->getSymbols().count(SymbolName))
146+
continue;
147+
148+
auto SymFlags = JITSymbolFlags::fromObjectSymbol(Sym);
149+
if (!SymFlags) {
150+
ES.reportError(SymFlags.takeError());
151+
R->failMaterialization();
152+
return;
153+
}
154+
155+
ExtraSymbolsToClaim[SymbolName] = *SymFlags;
156+
continue;
157+
}
158+
131159
// Don't include symbols that aren't global.
132160
if (!(*SymFlagsOrErr & object::BasicSymbolRef::SF_Global)) {
133161
if (auto SymName = Sym.getName())
@@ -139,6 +167,13 @@ void RTDyldObjectLinkingLayer::emit(
139167
}
140168
}
141169
}
170+
171+
if (!ExtraSymbolsToClaim.empty()) {
172+
if (auto Err = R->defineMaterializing(ExtraSymbolsToClaim)) {
173+
ES.reportError(std::move(Err));
174+
R->failMaterialization();
175+
}
176+
}
142177
}
143178

144179
auto MemMgr = GetMemoryManager();

0 commit comments

Comments
 (0)