[PATCH] D43484: Inline applyRelocations into writeTo.
Rui Ueyama via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Feb 19 14:51:18 PST 2018
ruiu created this revision.
ruiu added a reviewer: sbc100.
Herald added subscribers: aheejin, dschuff, jfb.
writeTo is memcpy() and applyRelocations(), but the former part is
too small that it doesn't make much sense to split it into two.
https://reviews.llvm.org/D43484
Files:
lld/wasm/InputChunks.cpp
Index: lld/wasm/InputChunks.cpp
===================================================================
--- lld/wasm/InputChunks.cpp
+++ lld/wasm/InputChunks.cpp
@@ -44,51 +44,47 @@
Relocations.push_back(R);
}
-static void applyRelocation(uint8_t *Buf, const OutputRelocation &Reloc) {
- DEBUG(dbgs() << "write reloc: type=" << Reloc.Reloc.Type
- << " index=" << Reloc.Reloc.Index << " value=" << Reloc.Value
- << " offset=" << Reloc.Reloc.Offset << "\n");
-
- Buf += Reloc.Reloc.Offset;
-
- switch (Reloc.Reloc.Type) {
- case R_WEBASSEMBLY_TYPE_INDEX_LEB:
- case R_WEBASSEMBLY_FUNCTION_INDEX_LEB:
- case R_WEBASSEMBLY_GLOBAL_INDEX_LEB:
- // Additional check to verify that the existing value that the location
- // matches our expectations.
- if (decodeULEB128(Buf) != Reloc.Reloc.Index) {
- DEBUG(dbgs() << "existing value: " << decodeULEB128(Buf) << "\n");
- assert(decodeULEB128(Buf) == Reloc.Reloc.Index);
- }
- LLVM_FALLTHROUGH;
- case R_WEBASSEMBLY_MEMORY_ADDR_LEB:
- encodeULEB128(Reloc.Value, Buf, 5);
- break;
- case R_WEBASSEMBLY_TABLE_INDEX_SLEB:
- case R_WEBASSEMBLY_MEMORY_ADDR_SLEB:
- encodeSLEB128(static_cast<int32_t>(Reloc.Value), Buf, 5);
- break;
- case R_WEBASSEMBLY_TABLE_INDEX_I32:
- case R_WEBASSEMBLY_MEMORY_ADDR_I32:
- write32le(Buf, Reloc.Value);
- break;
- default:
- llvm_unreachable("unknown relocation type");
- }
-}
-
// Copy this input chunk to an mmap'ed output file.
void InputChunk::writeTo(uint8_t *Buf) const {
// Copy contents
memcpy(Buf + getOutputOffset(), data().data(), data().size());
// Apply relocations
- if (OutRelocations.empty())
- return;
DEBUG(dbgs() << "applyRelocations: count=" << OutRelocations.size() << "\n");
- for (const OutputRelocation &Reloc : OutRelocations)
- applyRelocation(Buf, Reloc);
+
+ for (const OutputRelocation &Reloc : OutRelocations) {
+ DEBUG(dbgs() << "write reloc: type=" << Reloc.Reloc.Type
+ << " index=" << Reloc.Reloc.Index << " value=" << Reloc.Value
+ << " offset=" << Reloc.Reloc.Offset << "\n");
+
+ uint8_t *Loc = Buf + Reloc.Reloc.Offset;
+
+ switch (Reloc.Reloc.Type) {
+ case R_WEBASSEMBLY_TYPE_INDEX_LEB:
+ case R_WEBASSEMBLY_FUNCTION_INDEX_LEB:
+ case R_WEBASSEMBLY_GLOBAL_INDEX_LEB:
+ // Additional check to verify that the existing value that the location
+ // matches our expectations.
+ if (decodeULEB128(Loc) != Reloc.Reloc.Index) {
+ DEBUG(dbgs() << "existing value: " << decodeULEB128(Loc) << "\n");
+ assert(decodeULEB128(Loc) == Reloc.Reloc.Index);
+ }
+ LLVM_FALLTHROUGH;
+ case R_WEBASSEMBLY_MEMORY_ADDR_LEB:
+ encodeULEB128(Reloc.Value, Loc, 5);
+ break;
+ case R_WEBASSEMBLY_TABLE_INDEX_SLEB:
+ case R_WEBASSEMBLY_MEMORY_ADDR_SLEB:
+ encodeSLEB128(static_cast<int32_t>(Reloc.Value), Loc, 5);
+ break;
+ case R_WEBASSEMBLY_TABLE_INDEX_I32:
+ case R_WEBASSEMBLY_MEMORY_ADDR_I32:
+ write32le(Loc, Reloc.Value);
+ break;
+ default:
+ llvm_unreachable("unknown relocation type");
+ }
+ }
}
// Populate OutRelocations based on the input relocations and offset within the
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43484.134978.patch
Type: text/x-patch
Size: 3240 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180219/d724984b/attachment.bin>
More information about the llvm-commits
mailing list