mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-24 22:30:13 +00:00
[WebAssembly] Improve invalid relocation error message
This message now matches the equivalent message in the ELF linker. Differential Revision: https://reviews.llvm.org/D59860 llvm-svn: 357143
This commit is contained in:
parent
0a2d0c1f5f
commit
0805ec5f7b
@ -13,4 +13,4 @@ entry:
|
||||
}
|
||||
|
||||
; 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
|
||||
|
@ -22,7 +22,7 @@ using namespace llvm::support::endian;
|
||||
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: \
|
||||
|
@ -218,6 +218,8 @@ protected:
|
||||
} // namespace wasm
|
||||
|
||||
std::string toString(const wasm::InputChunk *);
|
||||
StringRef reloctTypeToString(uint8_t RelocType);
|
||||
|
||||
} // namespace lld
|
||||
|
||||
#endif // LLD_WASM_INPUT_CHUNKS_H
|
||||
|
@ -1141,18 +1141,6 @@ void Writer::processRelocations(InputChunk *Chunk) {
|
||||
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 +1149,23 @@ void Writer::processRelocations(InputChunk *Chunk) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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_I32:
|
||||
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");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user