[lld] r332412 - [WebAssembly] Fix R_WEBASSEMBLY_FUNCTION_OFFSET_I32 relocation entries

Sam Clegg via llvm-commits llvm-commits at lists.llvm.org
Tue May 15 15:27:51 PDT 2018


Author: sbc
Date: Tue May 15 15:27:50 2018
New Revision: 332412

URL: http://llvm.org/viewvc/llvm-project?rev=332412&view=rev
Log:
[WebAssembly] Fix R_WEBASSEMBLY_FUNCTION_OFFSET_I32 relocation entries

Fixes: lld: warning: unexpected existing value for R_WEBASSEMBLY_FUNCTION_OFFSET_I32: existing=839 expected=838

The existing solution is trying to erroneously recover correct offset of
the function code from the body (which is not a function segment that
includes its size, locals, and code).

The D46763 is trying to maintain the offset of the function code
allowing properly calculate the new relocation entry.

Patch by Yury Delendik

Differential Revision: https://reviews.llvm.org/D46765

Modified:
    lld/trunk/wasm/InputChunks.h
    lld/trunk/wasm/InputFiles.cpp

Modified: lld/trunk/wasm/InputChunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputChunks.h?rev=332412&r1=332411&r2=332412&view=diff
==============================================================================
--- lld/trunk/wasm/InputChunks.h (original)
+++ lld/trunk/wasm/InputChunks.h Tue May 15 15:27:50 2018
@@ -134,8 +134,8 @@ public:
   StringRef getName() const override { return Function->SymbolName; }
   StringRef getDebugName() const override { return Function->DebugName; }
   uint32_t getComdat() const override { return Function->Comdat; }
-  const ArrayRef<uint8_t> getFunctionBody() const { return Function->Body; }
   uint32_t getFunctionInputOffset() const { return getInputSectionOffset(); }
+  uint32_t getFunctionCodeOffset() const { return Function->CodeOffset; }
   uint32_t getFunctionIndex() const { return FunctionIndex.getValue(); }
   bool hasFunctionIndex() const { return FunctionIndex.hasValue(); }
   void setFunctionIndex(uint32_t Index);

Modified: lld/trunk/wasm/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/wasm/InputFiles.cpp?rev=332412&r1=332411&r2=332412&view=diff
==============================================================================
--- lld/trunk/wasm/InputFiles.cpp (original)
+++ lld/trunk/wasm/InputFiles.cpp Tue May 15 15:27:50 2018
@@ -16,7 +16,6 @@
 #include "lld/Common/Memory.h"
 #include "llvm/Object/Binary.h"
 #include "llvm/Object/Wasm.h"
-#include "llvm/Support/LEB128.h"
 #include "llvm/Support/raw_ostream.h"
 
 #define DEBUG_TYPE "lld"
@@ -43,12 +42,6 @@ Optional<MemoryBufferRef> lld::wasm::rea
   return MBRef;
 }
 
-static size_t getFunctionCodeOffset(ArrayRef<uint8_t> FunctionBody) {
-  unsigned Count;
-  llvm::decodeULEB128(FunctionBody.data(), &Count);
-  return Count;
-}
-
 void ObjFile::dumpInfo() const {
   log("info for: " + getName() +
       "\n              Symbols : " + Twine(Symbols.size()) +
@@ -105,10 +98,8 @@ uint32_t ObjFile::calcExpectedValue(cons
   }
   case R_WEBASSEMBLY_FUNCTION_OFFSET_I32:
     if (auto *Sym = dyn_cast<DefinedFunction>(getFunctionSymbol(Reloc.Index))) {
-      size_t FunctionCodeOffset =
-          getFunctionCodeOffset(Sym->Function->getFunctionBody());
-      return Sym->Function->getFunctionInputOffset() + FunctionCodeOffset +
-             Reloc.Addend;
+      return Sym->Function->getFunctionInputOffset() +
+             Sym->Function->getFunctionCodeOffset() + Reloc.Addend;
     }
     return 0;
   case R_WEBASSEMBLY_SECTION_OFFSET_I32:
@@ -145,9 +136,8 @@ uint32_t ObjFile::calcNewValue(const Was
     return getGlobalSymbol(Reloc.Index)->getGlobalIndex();
   case R_WEBASSEMBLY_FUNCTION_OFFSET_I32:
     if (auto *Sym = dyn_cast<DefinedFunction>(getFunctionSymbol(Reloc.Index))) {
-      size_t FunctionCodeOffset =
-          getFunctionCodeOffset(Sym->Function->getFunctionBody());
-      return Sym->Function->OutputOffset + FunctionCodeOffset + Reloc.Addend;
+      return Sym->Function->OutputOffset +
+             Sym->Function->getFunctionCodeOffset() + Reloc.Addend;
     }
     return 0;
   case R_WEBASSEMBLY_SECTION_OFFSET_I32:




More information about the llvm-commits mailing list