[PATCH] D63696: [WebAssembly] Fix list of relocations with addends in lld
Keno Fischer via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 23 16:24:48 PDT 2019
loladiro created this revision.
loladiro added a reviewer: sbc100.
Herald added subscribers: llvm-commits, sunfish, aheejin, hiraditya, jgravelle-google, dschuff.
Herald added a project: LLVM.
The list of relocations with addend in lld was missing `R_WASM_MEMORY_ADDR_REL_SLEB`,
causing `wasm-ld` to generate corrupted output. This fixes that problem and while
we're at it pulls the list of such relocations into the Wasm.h header, to avoid
duplicating it in multiple places.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D63696
Files:
lld/wasm/InputChunks.cpp
llvm/include/llvm/BinaryFormat/Wasm.h
llvm/lib/MC/WasmObjectWriter.cpp
Index: llvm/lib/MC/WasmObjectWriter.cpp
===================================================================
--- llvm/lib/MC/WasmObjectWriter.cpp
+++ llvm/lib/MC/WasmObjectWriter.cpp
@@ -147,19 +147,7 @@
: Offset(Offset), Symbol(Symbol), Addend(Addend), Type(Type),
FixupSection(FixupSection) {}
- bool hasAddend() const {
- switch (Type) {
- case wasm::R_WASM_MEMORY_ADDR_LEB:
- case wasm::R_WASM_MEMORY_ADDR_SLEB:
- case wasm::R_WASM_MEMORY_ADDR_REL_SLEB:
- case wasm::R_WASM_MEMORY_ADDR_I32:
- case wasm::R_WASM_FUNCTION_OFFSET_I32:
- case wasm::R_WASM_SECTION_OFFSET_I32:
- return true;
- default:
- return false;
- }
- }
+ bool hasAddend() const { return wasm::WasmRelocation::hasAddend(Type); }
void print(raw_ostream &Out) const {
Out << wasm::relocTypetoString(Type) << " Off=" << Offset
Index: llvm/include/llvm/BinaryFormat/Wasm.h
===================================================================
--- llvm/include/llvm/BinaryFormat/Wasm.h
+++ llvm/include/llvm/BinaryFormat/Wasm.h
@@ -165,6 +165,8 @@
uint32_t Index; // Index into either symbol or type index space.
uint64_t Offset; // Offset from the start of the section.
int64_t Addend; // A value to add to the symbol.
+ static bool hasAddend(unsigned Type);
+ inline bool hasAddend() const { return hasAddend(Type); };
};
struct WasmInitFunc {
@@ -322,6 +324,20 @@
#undef WASM_RELOC
+inline bool WasmRelocation::hasAddend(unsigned Type) {
+ switch (Type) {
+ case R_WASM_MEMORY_ADDR_LEB:
+ case R_WASM_MEMORY_ADDR_SLEB:
+ case R_WASM_MEMORY_ADDR_REL_SLEB:
+ case R_WASM_MEMORY_ADDR_I32:
+ case R_WASM_FUNCTION_OFFSET_I32:
+ case R_WASM_SECTION_OFFSET_I32:
+ return true;
+ default:
+ return false;
+ }
+}
+
// Subset of types that a value can have
enum class ValType {
I32 = WASM_TYPE_I32,
Index: lld/wasm/InputChunks.cpp
===================================================================
--- lld/wasm/InputChunks.cpp
+++ lld/wasm/InputChunks.cpp
@@ -154,15 +154,8 @@
writeUleb128(OS, Rel.Offset + Off, "reloc offset");
writeUleb128(OS, File->calcNewIndex(Rel), "reloc index");
- switch (Rel.Type) {
- case R_WASM_MEMORY_ADDR_LEB:
- case R_WASM_MEMORY_ADDR_SLEB:
- case R_WASM_MEMORY_ADDR_I32:
- case R_WASM_FUNCTION_OFFSET_I32:
- case R_WASM_SECTION_OFFSET_I32:
+ if (Rel.hasAddend())
writeSleb128(OS, File->calcNewAddend(Rel), "reloc addend");
- break;
- }
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63696.206147.patch
Type: text/x-patch
Size: 2494 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190623/511665fd/attachment.bin>
More information about the llvm-commits
mailing list