[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 11:41:43 PDT 2022


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG0e8f4ce31df1: [lld][WebAssembly] Fix crash on undefined+weak function syms in LTO objects (authored by sbc100).

Changed prior to commit:
  https://reviews.llvm.org/D126554?vs=432586&id=432608#toc

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
@@ -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 reference 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.432608.patch
Type: text/x-patch
Size: 1122 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220527/6e8bb46a/attachment.bin>


More information about the llvm-commits mailing list