[PATCH] D138264: [COFF] Improve JIT support of weak symbols
Vassil Vassilev via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 20 11:50:29 PST 2023
v.g.vassilev updated this revision to Diff 490931.
v.g.vassilev added a comment.
clang-format
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D138264/new/
https://reviews.llvm.org/D138264
Files:
llvm/lib/ExecutionEngine/Orc/Layer.cpp
llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
llvm/test/ExecutionEngine/OrcLazy/Inputs/comdat-functions.ll
llvm/test/ExecutionEngine/OrcLazy/comdat-functions.ll
Index: llvm/test/ExecutionEngine/OrcLazy/comdat-functions.ll
===================================================================
--- /dev/null
+++ llvm/test/ExecutionEngine/OrcLazy/comdat-functions.ll
@@ -0,0 +1,16 @@
+; REQUIRES: system-windows
+; RUN: lli -jit-kind=orc-lazy -extra-module %p/Inputs/comdat-functions.ll %s
+; Check if crashing comdat any functions are not causing duplicate symbol error.
+
+$baz = comdat any
+
+define i32 @baz() comdat {
+entry:
+ ret i32 0
+}
+
+define i32 @main(i32 %argc, i8** %argv) {
+entry:
+ %call = tail call i32 @baz()
+ ret i32 %call
+}
Index: llvm/test/ExecutionEngine/OrcLazy/Inputs/comdat-functions.ll
===================================================================
--- /dev/null
+++ llvm/test/ExecutionEngine/OrcLazy/Inputs/comdat-functions.ll
@@ -0,0 +1,6 @@
+$baz = comdat any
+
+define i32 @baz() comdat {
+entry:
+ ret i32 0
+}
Index: llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
===================================================================
--- llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
+++ llvm/lib/ExecutionEngine/Orc/RTDyldObjectLinkingLayer.cpp
@@ -259,6 +259,46 @@
if (COFFSec.Characteristics & COFF::IMAGE_SCN_LNK_COMDAT)
I->second.setFlags(I->second.getFlags() | JITSymbolFlags::Weak);
}
+
+ // Handle any aliases.
+ for (auto &Sym : COFFObj->symbols()) {
+ uint32_t SymFlags = cantFail(Sym.getFlags());
+ if (SymFlags & object::BasicSymbolRef::SF_Undefined)
+ continue;
+ auto Name = Sym.getName();
+ if (!Name)
+ return Name.takeError();
+ auto I = Resolved.find(*Name);
+
+ // Skip already-resolved symbols, and symbols that we're not responsible
+ // for.
+ if (I != Resolved.end() || !R.getSymbols().count(ES.intern(*Name)))
+ continue;
+
+ // Skip anything other than weak externals.
+ auto COFFSym = COFFObj->getCOFFSymbol(Sym);
+ if (!COFFSym.isWeakExternal())
+ continue;
+ auto *WeakExternal = COFFSym.getAux<object::coff_aux_weak_external>();
+ if (WeakExternal->Characteristics != COFF::IMAGE_WEAK_EXTERN_SEARCH_ALIAS)
+ continue;
+
+ // We found an alias. Reuse the resolution of the alias target for the
+ // alias itself.
+ Expected<object::COFFSymbolRef> TargetSymbol =
+ COFFObj->getSymbol(WeakExternal->TagIndex);
+ if (!TargetSymbol)
+ return TargetSymbol.takeError();
+ Expected<StringRef> TargetName = COFFObj->getSymbolName(*TargetSymbol);
+ if (!TargetName)
+ return TargetName.takeError();
+ auto J = Resolved.find(*TargetName);
+ if (J == Resolved.end())
+ return make_error<StringError>("Could alias target " + *TargetName +
+ " not resolved",
+ inconvertibleErrorCode());
+ Resolved[*Name] = J->second;
+ }
}
for (auto &KV : Resolved) {
Index: llvm/lib/ExecutionEngine/Orc/Layer.cpp
===================================================================
--- llvm/lib/ExecutionEngine/Orc/Layer.cpp
+++ llvm/lib/ExecutionEngine/Orc/Layer.cpp
@@ -77,6 +77,9 @@
// Otherwise we just need a normal linker mangling.
auto MangledName = Mangle(G.getName());
SymbolFlags[MangledName] = JITSymbolFlags::fromGlobalValue(G);
+ if (G.getComdat() &&
+ G.getComdat()->getSelectionKind() != Comdat::NoDeduplicate)
+ SymbolFlags[MangledName] |= JITSymbolFlags::Weak;
SymbolToDefinition[MangledName] = &G;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D138264.490931.patch
Type: text/x-patch
Size: 3568 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230120/81e2ca5f/attachment.bin>
More information about the llvm-commits
mailing list