[PATCH] D104495: [lld][WebAssembly] Fix crash calling weakly undefined function in PIC code
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 17 16:49:04 PDT 2021
sbc100 created this revision.
Herald added subscribers: wingo, ecnelises, sunfish, jgravelle-google, dschuff.
sbc100 requested review of this revision.
Herald added subscribers: llvm-commits, aheejin.
Herald added a project: LLVM.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D104495
Files:
lld/test/wasm/weak-undefined-pic.s
lld/wasm/InputChunks.cpp
lld/wasm/Writer.cpp
Index: lld/wasm/Writer.cpp
===================================================================
--- lld/wasm/Writer.cpp
+++ lld/wasm/Writer.cpp
@@ -546,7 +546,7 @@
static bool shouldImport(Symbol *sym) {
if (!sym->isUndefined())
return false;
- if (sym->isWeak() && !config->relocatable)
+ if (sym->isWeak() && !config->relocatable && !config->isPic)
return false;
if (!sym->isLive())
return false;
Index: lld/wasm/InputChunks.cpp
===================================================================
--- lld/wasm/InputChunks.cpp
+++ lld/wasm/InputChunks.cpp
@@ -106,13 +106,12 @@
for (const WasmRelocation &rel : relocations) {
uint8_t *loc = buf + rel.Offset - inputSectionOffset;
- auto value = file->calcNewValue(rel, tombstone, this);
LLVM_DEBUG(dbgs() << "apply reloc: type=" << relocTypeToString(rel.Type));
if (rel.Type != R_WASM_TYPE_INDEX_LEB)
LLVM_DEBUG(dbgs() << " sym=" << file->getSymbols()[rel.Index]->getName());
LLVM_DEBUG(dbgs() << " addend=" << rel.Addend << " index=" << rel.Index
- << " value=" << value << " offset=" << rel.Offset
- << "\n");
+ << " offset=" << rel.Offset << "\n");
+ auto value = file->calcNewValue(rel, tombstone, this);
switch (rel.Type) {
case R_WASM_TYPE_INDEX_LEB:
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
@@ -75,7 +76,10 @@
# RUN: obj2yaml %t3.wasm | FileCheck %s --check-prefix=IMPORT
# IMPORT: - Type: IMPORT
-# IMPORT: - Module: GOT.func
+# IMPORT: Field: foo
+# IMPORT-NEXT: Kind: FUNCTION
+# IMPORT-NEXT: SigIndex: 0
+# IMPORT-NEXT: - Module: GOT.func
# IMPORT-NEXT: Field: foo
# IMPORT-NEXT: Kind: GLOBAL
# IMPORT-NEXT: GlobalType: I32
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104495.352875.patch
Type: text/x-patch
Size: 2145 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210617/b1ffe5b3/attachment.bin>
More information about the llvm-commits
mailing list