[WebAssembly] Move relocation handling InputChunks.cpp
Teach each input chunk how to write itself and apply its
own relocations.
Differential Revision: https://reviews.llvm.org/D41891
llvm-svn: 322212
diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp
index 36a609e..14adff8 100644
--- a/lld/wasm/InputFiles.cpp
+++ b/lld/wasm/InputFiles.cpp
@@ -83,6 +83,29 @@
return Index;
}
+// Relocations contain an index into the function, global or table index
+// space of the input file. This function takes a relocation and returns the
+// relocated index (i.e. translates from the input index space to the output
+// index space).
+uint32_t ObjFile::calcNewIndex(const WasmRelocation &Reloc) const {
+ switch (Reloc.Type) {
+ case R_WEBASSEMBLY_TYPE_INDEX_LEB:
+ return relocateTypeIndex(Reloc.Index);
+ case R_WEBASSEMBLY_FUNCTION_INDEX_LEB:
+ return relocateFunctionIndex(Reloc.Index);
+ case R_WEBASSEMBLY_TABLE_INDEX_I32:
+ case R_WEBASSEMBLY_TABLE_INDEX_SLEB:
+ return relocateTableIndex(Reloc.Index);
+ case R_WEBASSEMBLY_GLOBAL_INDEX_LEB:
+ case R_WEBASSEMBLY_MEMORY_ADDR_LEB:
+ case R_WEBASSEMBLY_MEMORY_ADDR_SLEB:
+ case R_WEBASSEMBLY_MEMORY_ADDR_I32:
+ return relocateGlobalIndex(Reloc.Index);
+ default:
+ llvm_unreachable("unknown relocation type");
+ }
+}
+
void ObjFile::parse() {
// Parse a memory buffer as a wasm file.
DEBUG(dbgs() << "Parsing object: " << toString(this) << "\n");