[PATCH] D64280: [lld][WebAssembly] Report undefined data relocations earlier
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Jul 6 00:52:57 PDT 2019
sbc100 created this revision.
Herald added subscribers: llvm-commits, sunfish, aheejin, jgravelle-google, dschuff.
Herald added a project: LLVM.
See https://github.com/emscripten-core/emscripten/issues/8930.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D64280
Files:
lld/wasm/InputFiles.cpp
lld/wasm/Relocations.cpp
Index: lld/wasm/Relocations.cpp
===================================================================
--- lld/wasm/Relocations.cpp
+++ lld/wasm/Relocations.cpp
@@ -50,16 +50,16 @@
if (!isa<GlobalSymbol>(Sym))
Out.ImportSec->addGOTEntry(Sym);
break;
- case R_WASM_MEMORY_ADDR_SLEB:
- case R_WASM_MEMORY_ADDR_LEB:
- case R_WASM_MEMORY_ADDR_REL_SLEB:
- if (!Config->Relocatable && Sym->isUndefined() && !Sym->isWeak()) {
+ }
+
+ // Handle undefined data symbols.
+ // For non-weak symbols this is normally an error except in the PIC case
+ // where we can generate runtime relocations for R_WASM_MEMORY_ADDR_I32.
+ if (isa<UndefinedData>(Sym) && !Config->Relocatable && !Sym->isWeak())
+ if (!(Config->Pic && Reloc.Type == R_WASM_MEMORY_ADDR_I32))
error(toString(File) + ": cannot resolve relocation of type " +
relocTypeToString(Reloc.Type) +
" against undefined (non-weak) data symbol: " + toString(*Sym));
- }
- break;
- }
if (Config->Pic) {
switch (Reloc.Type) {
Index: lld/wasm/InputFiles.cpp
===================================================================
--- lld/wasm/InputFiles.cpp
+++ lld/wasm/InputFiles.cpp
@@ -161,21 +161,11 @@
if ((isa<FunctionSymbol>(Sym) || isa<DataSymbol>(Sym)) && !Sym->isLive())
return 0;
- // Special handling for undefined data symbols. Most relocations against
- // such symbols cannot be resolved.
- if (isa<DataSymbol>(Sym) && Sym->isUndefined()) {
- if (Sym->isWeak() || Config->Relocatable)
- return 0;
- // R_WASM_MEMORY_ADDR_I32 relocations in PIC code are turned into runtime
- // fixups in __wasm_apply_relocs
- if (Config->Pic && Reloc.Type == R_WASM_MEMORY_ADDR_I32)
- return 0;
- if (Reloc.Type != R_WASM_GLOBAL_INDEX_LEB) {
- llvm_unreachable(
- ("invalid relocation against undefined data symbol: " + toString(*Sym))
- .c_str());
- }
- }
+ // Special handling for undefined data symbols. For weak symbols or for
+ // data relocations in PIC mode writing zero is the correct behaviour. For
+ // other cases, an error will have been reported during scanRelocations.
+ if (isa<DataSymbol>(Sym) && Sym->isUndefined())
+ return 0;
}
switch (Reloc.Type) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D64280.208261.patch
Type: text/x-patch
Size: 2350 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190706/18756928/attachment.bin>
More information about the llvm-commits
mailing list