[PATCH] D95914: [lld][WebAssembly] Fix for weak undefined functions in -pie mode
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 2 19:15:19 PST 2021
sbc100 updated this revision to Diff 320972.
sbc100 edited the summary of this revision.
sbc100 added a comment.
typos
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D95914/new/
https://reviews.llvm.org/D95914
Files:
lld/test/wasm/weak-undefined-pic.s
lld/wasm/Driver.cpp
lld/wasm/Writer.cpp
Index: lld/wasm/Writer.cpp
===================================================================
--- lld/wasm/Writer.cpp
+++ lld/wasm/Writer.cpp
@@ -585,8 +585,6 @@
for (Symbol *sym : symtab->getSymbols()) {
if (!sym->isUndefined())
continue;
- if (sym->isWeak() && !config->relocatable)
- continue;
if (!sym->isLive())
continue;
if (!sym->isUsedInRegularObj)
Index: lld/wasm/Driver.cpp
===================================================================
--- lld/wasm/Driver.cpp
+++ lld/wasm/Driver.cpp
@@ -1023,7 +1023,8 @@
warn(Twine("symbol exported via --export not found: ") + arg->getValue());
}
- if (!config->relocatable && !config->isPic) {
+ if (!config->relocatable &&
+ config->unresolvedSymbols != UnresolvedPolicy::ImportFuncs) {
// Add synthetic dummies for weak undefined functions. Must happen
// after LTO otherwise functions may not yet have signatures.
symtab->handleWeakUndefines();
Index: lld/test/wasm/weak-undefined-pic.s
===================================================================
--- lld/test/wasm/weak-undefined-pic.s
+++ lld/test/wasm/weak-undefined-pic.s
@@ -22,6 +22,7 @@
_start:
.functype _start () -> ()
call get_foo_addr
+ call foo
end_function
.weak foo
@@ -68,11 +69,15 @@
# CHECK-NEXT: - Index: 1
# CHECK-NEXT: Name: 'GOT.func.internal.undefined_weak:foo'
-# With `-pie` or `-shared` the resolution should be deferred to the dynamic
-# linker and the function address should be imported as GOT.func.foo.
+# With `-pie + + --unresolved-symbols=import-functions` or `-shared` the
+# resolution should be deferred to the dynamic linker and the function address
+# should be imported as GOT.func.foo.
#
-# RUN: wasm-ld --experimental-pic -pie %t.o -o %t3.wasm
+# RUN: wasm-ld --experimental-pic -shared %t.o -o %t3.wasm
# RUN: obj2yaml %t3.wasm | FileCheck %s --check-prefix=IMPORT
+#
+# RUN: wasm-ld --experimental-pic -pie --unresolved-symbols=import-functions %t.o -o %t4.wasm
+# RUN: obj2yaml %t4.wasm | FileCheck %s --check-prefix=IMPORT
# IMPORT: - Type: IMPORT
# IMPORT: - Module: GOT.func
@@ -88,3 +93,12 @@
# IMPORT-NEXT: Name: __table_base
# IMPORT-NEXT: - Index: 2
# IMPORT-NEXT: Name: foo
+
+# With just `-pie` (which does not default to import-functions) there shoule be
+# no import at all.
+#
+# RUN: wasm-ld --experimental-pic -pie %t.o -o %t5.wasm
+# RUN: obj2yaml %t5.wasm | FileCheck %s --check-prefix=NO-IMPORT
+
+# NO-IMPORT: Name: 'undefined_weak:foo'
+# NO-IMPORT-NOT: Name: foo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95914.320972.patch
Type: text/x-patch
Size: 2682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210203/f9e750ff/attachment.bin>
More information about the llvm-commits
mailing list