[PATCH] D126554: [lld][WebAssembly] Fix crash on undefined/weak function symbols in LTO objects
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri May 27 09:21:46 PDT 2022
sbc100 updated this revision to Diff 432584.
sbc100 added a comment.
Herald added subscribers: ormris, steven_wu, hiraditya.
- add test
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D126554/new/
https://reviews.llvm.org/D126554
Files:
lld/test/wasm/lto/weak-undefined.ll
lld/wasm/SymbolTable.cpp
Index: lld/wasm/SymbolTable.cpp
===================================================================
--- lld/wasm/SymbolTable.cpp
+++ lld/wasm/SymbolTable.cpp
@@ -842,7 +842,7 @@
void SymbolTable::replaceWithUndefined(Symbol *sym) {
// Add a synthetic dummy for weak undefined functions. These dummies will
// be GC'd if not used as the target of any "call" instructions.
- StringRef debugName = saver().save("undefined_weak:" + toString(*sym));
+ StringRef debugName = saver().save("undefined_weak:" + sym->getName());
replaceWithUnreachable(sym, *sym->getSignature(), debugName);
// Hide our dummy to prevent export.
sym->setHidden(true);
@@ -854,7 +854,7 @@
// the call instruction that passes Wasm validation.
void SymbolTable::handleWeakUndefines() {
for (Symbol *sym : getSymbols()) {
- if (sym->isUndefWeak()) {
+ if (sym->isUndefWeak() && sym->isUsedInRegularObj) {
if (sym->getSignature()) {
replaceWithUndefined(sym);
} else {
Index: lld/test/wasm/lto/weak-undefined.ll
===================================================================
--- lld/test/wasm/lto/weak-undefined.ll
+++ lld/test/wasm/lto/weak-undefined.ll
@@ -11,6 +11,17 @@
declare extern_weak i32 @foo()
+declare extern_weak i32 @bar()
+
+; The refernce to bar here will exist in the LTO file, but the LTO process will
+; remove it, so it will never be referenced by an normal object file, and
+; therefore never have a signature.
+define void @unused_function() #0 {
+entry:
+ %call2 = call i32 @bar()
+ ret void
+}
+
define void @_start() #0 {
entry:
%call2 = call i32 @foo()
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D126554.432584.patch
Type: text/x-patch
Size: 1622 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220527/71fcf3f1/attachment.bin>
More information about the llvm-commits
mailing list