[PATCH] D44237: [WebAssembly] Honor --allow-undefined even for explicit exports

Sam Clegg via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 7 17:07:55 PST 2018


sbc100 created this revision.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, dschuff, jfb.

When a symbol is exported via --export=foo but --allow-undefined
is also specified, the symbol is now allowed to be undefined.
Previously we were special casing such symbols.

This combinations of behavior is exactly what emescripten
requires. Although we are trying hard not to allow emscripten
specific features in lld, this one makes sense.

Enforce this behavior by added this case to test/wasm/undefined.ll.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D44237

Files:
  test/wasm/undefined.ll
  wasm/Driver.cpp


Index: wasm/Driver.cpp
===================================================================
--- wasm/Driver.cpp
+++ wasm/Driver.cpp
@@ -346,7 +346,7 @@
     Symbol *Sym = Symtab->find(Name);
     if (Sym && Sym->isDefined())
       Sym->setHidden(false);
-    else
+    else if (!Config->AllowUndefined)
       error("symbol exported via --export not found: " + Name);
   }
 
Index: test/wasm/undefined.ll
===================================================================
--- test/wasm/undefined.ll
+++ test/wasm/undefined.ll
@@ -6,10 +6,14 @@
 ; CHECK: error: {{.*}}.o: undefined symbol: foo
 ; CHECK: error: undefined symbol: baz
 
-; But succeeds if we pass a file containing 'foo' as --allow-undefined-file.
+; Succeeds if we pass a file containing 'foo' as --allow-undefined-file.
 ; RUN: echo 'foo' > %t.txt
 ; RUN: wasm-ld --check-signatures --allow-undefined-file=%t.txt -o %t.wasm %t.o
 
+; Succeeds even if a missing symbol is added via --export
+; RUN: echo 'foo' > %t.txt
+; RUN: wasm-ld --check-signatures --allow-undefined --export=xxx -o %t.wasm %t.o
+
 target triple = "wasm32-unknown-unknown-wasm"
 
 ; Takes the address of the external foo() resulting in undefined external


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44237.137513.patch
Type: text/x-patch
Size: 1193 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180308/4038aa9c/attachment.bin>


More information about the llvm-commits mailing list