[PATCH] D59860: [WebAssembly] Improve invalid relocation error message
Sam Clegg via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 26 18:46:53 PDT 2019
sbc100 updated this revision to Diff 192400.
sbc100 added a comment.
- clang-format
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D59860/new/
https://reviews.llvm.org/D59860
Files:
lld/test/wasm/undefined-data.ll
lld/wasm/InputChunks.cpp
lld/wasm/InputChunks.h
lld/wasm/Writer.cpp
Index: lld/wasm/Writer.cpp
===================================================================
--- lld/wasm/Writer.cpp
+++ lld/wasm/Writer.cpp
@@ -1124,6 +1124,7 @@
if (!Chunk->Live)
return;
ObjFile *File = Chunk->File;
+
ArrayRef<WasmSignature> Types = File->getWasmObj()->types();
for (const WasmRelocation &Reloc : Chunk->getRelocations()) {
switch (Reloc.Type) {
@@ -1141,18 +1142,6 @@
File->TypeMap[Reloc.Index] = registerType(Types[Reloc.Index]);
File->TypeIsUsed[Reloc.Index] = true;
break;
- case R_WASM_MEMORY_ADDR_SLEB:
- case R_WASM_MEMORY_ADDR_I32:
- case R_WASM_MEMORY_ADDR_LEB: {
- DataSymbol *DataSym = File->getDataSymbol(Reloc.Index);
- if (!Config->Relocatable && !isa<DefinedData>(DataSym) &&
- !DataSym->isWeak())
- error(File->getName() +
- ": relocation of type R_WASM_MEMORY_ADDR_* "
- "against undefined data symbol: " +
- DataSym->getName());
- break;
- }
case R_WASM_GLOBAL_INDEX_LEB: {
auto* Sym = File->getSymbols()[Reloc.Index];
if (!isa<GlobalSymbol>(Sym) && !Sym->isInGOT()) {
@@ -1161,6 +1150,23 @@
}
}
}
+
+ if (!Config->Relocatable) {
+ switch (Reloc.Type) {
+ // These relocations types appear the code section.
+ // They should never appear in code compiled with -fPIC.
+ case R_WASM_TABLE_INDEX_SLEB:
+ case R_WASM_MEMORY_ADDR_SLEB:
+ case R_WASM_MEMORY_ADDR_LEB: {
+ auto *Sym = File->getSymbols()[Reloc.Index];
+ if (Sym->isUndefined() && !Sym->isWeak())
+ error(File->getName() + ": relocation " +
+ reloctTypeToString(Reloc.Type) +
+ " cannot be used againt symbol " + Sym->getName() +
+ "; recompile with -fPIC");
+ }
+ }
+ }
}
}
Index: lld/wasm/InputChunks.h
===================================================================
--- lld/wasm/InputChunks.h
+++ lld/wasm/InputChunks.h
@@ -218,6 +218,8 @@
} // namespace wasm
std::string toString(const wasm::InputChunk *);
+StringRef reloctTypeToString(uint8_t RelocType);
+
} // namespace lld
#endif // LLD_WASM_INPUT_CHUNKS_H
Index: lld/wasm/InputChunks.cpp
===================================================================
--- lld/wasm/InputChunks.cpp
+++ lld/wasm/InputChunks.cpp
@@ -22,7 +22,7 @@
using namespace lld;
using namespace lld::wasm;
-static StringRef reloctTypeToString(uint8_t RelocType) {
+StringRef lld::reloctTypeToString(uint8_t RelocType) {
switch (RelocType) {
#define WASM_RELOC(NAME, REL) \
case REL: \
Index: lld/test/wasm/undefined-data.ll
===================================================================
--- lld/test/wasm/undefined-data.ll
+++ lld/test/wasm/undefined-data.ll
@@ -13,4 +13,4 @@
}
; UNDEF: undefined symbol: data_external
-; BADRELOC: undefined-data.ll.tmp.o: relocation of type R_WASM_MEMORY_ADDR_* against undefined data symbol: data_external
+; BADRELOC: undefined-data.ll.tmp.o: relocation R_WASM_MEMORY_ADDR_LEB cannot be used againt symbol data_external; recompile with -fPIC
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D59860.192400.patch
Type: text/x-patch
Size: 3240 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190327/bdf2016d/attachment.bin>
More information about the llvm-commits
mailing list