[PATCH] D57420: [WebAssembly] Fix undefined weak functions symbol in LTO builds

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 29 15:17:52 PST 2019


sbc100 created this revision.
Herald added subscribers: llvm-commits, dexonsmith, steven_wu, sunfish, aheejin, jgravelle-google, inglorion, mehdi_amini, dschuff.

Fixes PR40219


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D57420

Files:
  test/wasm/lto/weak-undefined.ll
  wasm/Driver.cpp


Index: wasm/Driver.cpp
===================================================================
--- wasm/Driver.cpp
+++ wasm/Driver.cpp
@@ -587,9 +587,6 @@
 
   Symbol *EntrySym = nullptr;
   if (!Config->Relocatable) {
-    // Add synthetic dummies for weak undefined functions.
-    handleWeakUndefines();
-
     if (!Config->Shared && !Config->Entry.empty()) {
       EntrySym = handleUndefined(Config->Entry);
       if (EntrySym && EntrySym->isDefined())
@@ -613,6 +610,11 @@
   if (errorCount())
     return;
 
+  // Add synthetic dummies for weak undefined functions.  Must happen
+  // after LTO otherwise functions may not yet have signatures.
+  if (!Config->Relocatable)
+    handleWeakUndefines();
+
   if (EntrySym)
     EntrySym->setHidden(false);
 
Index: test/wasm/lto/weak-undefined.ll
===================================================================
--- /dev/null
+++ test/wasm/lto/weak-undefined.ll
@@ -0,0 +1,20 @@
+; RUN: llvm-as %s -o %t.o
+; RUN: wasm-ld %t.o -o %t.wasm
+; RUN: obj2yaml %t.wasm | FileCheck %s
+
+; Test that undefined weak external functions are handled in the LTO case
+; We had a bug where stub function generation was failing because functions
+; that are in bitcode (pre-LTO) don't have signatures assigned.
+
+target datalayout = "e-m:e-p:32:32-i64:64-n32:64-S128"
+target triple = "wasm32-unknown-unknown"
+
+declare extern_weak i32 @foo()
+
+define void @_start() #0 {
+entry:
+    %call2 = call i32 @foo()
+    ret void
+}
+
+; CHECK: Name:            undefined function foo


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D57420.184191.patch
Type: text/x-patch
Size: 1522 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190129/c032a69b/attachment.bin>


More information about the llvm-commits mailing list