Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 1 | //===- InputSegment.cpp ---------------------------------------------------===// |
| 2 | // |
| 3 | // The LLVM Linker |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | |
Sam Clegg | 5fa274b | 2018-01-10 01:13:34 +0000 | [diff] [blame^] | 10 | #include "InputChunks.h" |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 11 | #include "OutputSegment.h" |
| 12 | #include "lld/Common/LLVM.h" |
| 13 | |
| 14 | #define DEBUG_TYPE "lld" |
| 15 | |
| 16 | using namespace llvm; |
| 17 | using namespace lld::wasm; |
| 18 | |
| 19 | uint32_t InputSegment::translateVA(uint32_t Address) const { |
| 20 | assert(Address >= startVA() && Address < endVA()); |
Sam Clegg | 5fa274b | 2018-01-10 01:13:34 +0000 | [diff] [blame^] | 21 | int32_t Delta = OutputSeg->StartVA + OutputOffset - startVA(); |
Sam Clegg | c94d393 | 2017-11-17 18:14:09 +0000 | [diff] [blame] | 22 | DEBUG(dbgs() << "translateVA: " << getName() << " Delta=" << Delta |
| 23 | << " Address=" << Address << "\n"); |
| 24 | return Address + Delta; |
| 25 | } |
Sam Clegg | 5fa274b | 2018-01-10 01:13:34 +0000 | [diff] [blame^] | 26 | |
| 27 | void InputChunk::copyRelocations(const WasmSection &Section) { |
| 28 | size_t Start = getInputSectionOffset(); |
| 29 | size_t Size = getSize(); |
| 30 | for (const WasmRelocation &R : Section.Relocations) |
| 31 | if (R.Offset >= Start && R.Offset < Start + Size) |
| 32 | Relocations.push_back(R); |
| 33 | } |