Skip to content

Commit e3a845e

Browse files
committed
Re-land "[WebAssembly] Improve invalid relocation error message""
See https://reviews.llvm.org/D59860 The initial version of this change effected more than just the error message. This version is scoped down to only effect the error itself. llvm-svn: 357328
1 parent c8d6e04 commit e3a845e

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

lld/test/wasm/undefined-data.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ entry:
1313
}
1414

1515
; UNDEF: undefined symbol: data_external
16-
; BADRELOC: undefined-data.ll.tmp.o: relocation of type R_WASM_MEMORY_ADDR_* against undefined data symbol: data_external
16+
; BADRELOC: undefined-data.ll.tmp.o: relocation R_WASM_MEMORY_ADDR_LEB cannot be used againt symbol data_external; recompile with -fPIC

lld/wasm/InputChunks.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ using namespace llvm::support::endian;
2222
using namespace lld;
2323
using namespace lld::wasm;
2424

25-
static StringRef reloctTypeToString(uint8_t RelocType) {
25+
StringRef lld::relocTypeToString(uint8_t RelocType) {
2626
switch (RelocType) {
2727
#define WASM_RELOC(NAME, REL) \
2828
case REL: \
@@ -78,7 +78,7 @@ void InputChunk::verifyRelocTargets() const {
7878
if (Rel.Type != R_WASM_GLOBAL_INDEX_LEB) {
7979
uint32_t ExpectedValue = File->calcExpectedValue(Rel);
8080
if (ExpectedValue != ExistingValue)
81-
warn("unexpected existing value for " + reloctTypeToString(Rel.Type) +
81+
warn("unexpected existing value for " + relocTypeToString(Rel.Type) +
8282
": existing=" + Twine(ExistingValue) +
8383
" expected=" + Twine(ExpectedValue));
8484
}
@@ -105,7 +105,7 @@ void InputChunk::writeTo(uint8_t *Buf) const {
105105
for (const WasmRelocation &Rel : Relocations) {
106106
uint8_t *Loc = Buf + Rel.Offset + Off;
107107
uint32_t Value = File->calcNewValue(Rel);
108-
LLVM_DEBUG(dbgs() << "apply reloc: type=" << reloctTypeToString(Rel.Type)
108+
LLVM_DEBUG(dbgs() << "apply reloc: type=" << relocTypeToString(Rel.Type)
109109
<< " addend=" << Rel.Addend << " index=" << Rel.Index
110110
<< " value=" << Value << " offset=" << Rel.Offset
111111
<< "\n");

lld/wasm/InputChunks.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ class InputSection : public InputChunk {
218218
} // namespace wasm
219219

220220
std::string toString(const wasm::InputChunk *);
221+
StringRef relocTypeToString(uint8_t RelocType);
222+
221223
} // namespace lld
222224

223225
#endif // LLD_WASM_INPUT_CHUNKS_H

lld/wasm/Writer.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,13 +1152,12 @@ void Writer::processRelocations(InputChunk *Chunk) {
11521152
case R_WASM_MEMORY_ADDR_SLEB:
11531153
case R_WASM_MEMORY_ADDR_I32:
11541154
case R_WASM_MEMORY_ADDR_LEB: {
1155-
DataSymbol *DataSym = File->getDataSymbol(Reloc.Index);
1156-
if (!Config->Relocatable && !isa<DefinedData>(DataSym) &&
1157-
!DataSym->isWeak())
1158-
error(File->getName() +
1159-
": relocation of type R_WASM_MEMORY_ADDR_* "
1160-
"against undefined data symbol: " +
1161-
DataSym->getName());
1155+
DataSymbol *Sym = File->getDataSymbol(Reloc.Index);
1156+
if (!Config->Relocatable && !isa<DefinedData>(Sym) && !Sym->isWeak())
1157+
error(File->getName() + ": relocation " +
1158+
relocTypeToString(Reloc.Type) + " cannot be used againt symbol " +
1159+
Sym->getName() + "; recompile with -fPIC");
1160+
11621161
break;
11631162
}
11641163
case R_WASM_GLOBAL_INDEX_LEB: {

0 commit comments

Comments
 (0)