[lld] r357328 - Re-land "[WebAssembly] Improve invalid relocation error message""

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 29 15:56:39 PDT 2019


Author: sbc
Date: Fri Mar 29 15:56:39 2019
New Revision: 357328

URL: http://llvm.org/viewvc/llvm-project?rev=357328&view=rev
Log:
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.

Modified:
    lld/trunk/test/wasm/undefined-data.ll
    lld/trunk/wasm/InputChunks.cpp
    lld/trunk/wasm/InputChunks.h
    lld/trunk/wasm/Writer.cpp

Modified: lld/trunk/test/wasm/undefined-data.ll
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/wasm/undefined-data.ll?rev=357328&r1=357327&r2=357328&view=diff
==============================================================================
--- lld/trunk/test/wasm/undefined-data.ll (original)
+++ lld/trunk/test/wasm/undefined-data.ll Fri Mar 29 15:56:39 2019
@@ -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

Modified: lld/trunk/wasm/InputChunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputChunks.cpp?rev=357328&r1=357327&r2=357328&view=diff
==============================================================================
--- lld/trunk/wasm/InputChunks.cpp (original)
+++ lld/trunk/wasm/InputChunks.cpp Fri Mar 29 15:56:39 2019
@@ -22,7 +22,7 @@ using namespace llvm::support::endian;
 using namespace lld;
 using namespace lld::wasm;
 
-static StringRef reloctTypeToString(uint8_t RelocType) {
+StringRef lld::relocTypeToString(uint8_t RelocType) {
   switch (RelocType) {
 #define WASM_RELOC(NAME, REL)                                                  \
   case REL:                                                                    \
@@ -78,7 +78,7 @@ void InputChunk::verifyRelocTargets() co
     if (Rel.Type != R_WASM_GLOBAL_INDEX_LEB) {
       uint32_t ExpectedValue = File->calcExpectedValue(Rel);
       if (ExpectedValue != ExistingValue)
-        warn("unexpected existing value for " + reloctTypeToString(Rel.Type) +
+        warn("unexpected existing value for " + relocTypeToString(Rel.Type) +
              ": existing=" + Twine(ExistingValue) +
              " expected=" + Twine(ExpectedValue));
     }
@@ -105,7 +105,7 @@ void InputChunk::writeTo(uint8_t *Buf) c
   for (const WasmRelocation &Rel : Relocations) {
     uint8_t *Loc = Buf + Rel.Offset + Off;
     uint32_t Value = File->calcNewValue(Rel);
-    LLVM_DEBUG(dbgs() << "apply reloc: type=" << reloctTypeToString(Rel.Type)
+    LLVM_DEBUG(dbgs() << "apply reloc: type=" << relocTypeToString(Rel.Type)
                       << " addend=" << Rel.Addend << " index=" << Rel.Index
                       << " value=" << Value << " offset=" << Rel.Offset
                       << "\n");

Modified: lld/trunk/wasm/InputChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputChunks.h?rev=357328&r1=357327&r2=357328&view=diff
==============================================================================
--- lld/trunk/wasm/InputChunks.h (original)
+++ lld/trunk/wasm/InputChunks.h Fri Mar 29 15:56:39 2019
@@ -218,6 +218,8 @@ protected:
 } // namespace wasm
 
 std::string toString(const wasm::InputChunk *);
+StringRef relocTypeToString(uint8_t RelocType);
+
 } // namespace lld
 
 #endif // LLD_WASM_INPUT_CHUNKS_H

Modified: lld/trunk/wasm/Writer.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/Writer.cpp?rev=357328&r1=357327&r2=357328&view=diff
==============================================================================
--- lld/trunk/wasm/Writer.cpp (original)
+++ lld/trunk/wasm/Writer.cpp Fri Mar 29 15:56:39 2019
@@ -1152,13 +1152,12 @@ void Writer::processRelocations(InputChu
     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());
+      DataSymbol *Sym = File->getDataSymbol(Reloc.Index);
+      if (!Config->Relocatable && !isa<DefinedData>(Sym) && !Sym->isWeak())
+        error(File->getName() + ": relocation " +
+              relocTypeToString(Reloc.Type) + " cannot be used againt symbol " +
+              Sym->getName() + "; recompile with -fPIC");
+
       break;
     }
     case R_WASM_GLOBAL_INDEX_LEB: {




More information about the llvm-commits mailing list