Files
revng-revng/include/revng/Model/Importer/Binary/BinaryImporterHelper.h
Alessandro Di Federico f562d0373f Importers: fix usage of BaseAddress
This commit ensure the BaseAddress is propagate as appropriate to all
levels of the importers and that it is ignored for executables
(non-PIC).

This was a recurring source of importing the same function twice, once
relocated, once not.
2023-05-10 09:20:40 +02:00

49 lines
1.2 KiB
C++

#pragma once
//
// This file is distributed under the MIT License. See LICENSE.md for details.
//
#include <cstdint>
#include "llvm/ADT/ArrayRef.h"
#include "revng/Model/Architecture.h"
#include "revng/Support/Debug.h"
#include "revng/Support/MetaAddress.h"
class BinaryImporterHelper {
protected:
model::Architecture::Values Architecture = model::Architecture::Invalid;
uint64_t BaseAddress = 0;
public:
BinaryImporterHelper(model::Architecture::Values Architecture,
uint64_t BaseAddress) :
Architecture(Architecture), BaseAddress(BaseAddress) {}
public:
MetaAddress relocate(MetaAddress Address) const {
return Address += BaseAddress;
}
MetaAddress relocate(uint64_t Address) const {
return relocate(fromGeneric(Address));
}
MetaAddress fromPC(uint64_t PC) const {
using namespace model::Architecture;
revng_assert(Architecture != Invalid);
return MetaAddress::fromPC(toLLVMArchitecture(Architecture), PC);
}
MetaAddress fromGeneric(uint64_t Address) const {
using namespace model::Architecture;
revng_assert(Architecture != Invalid);
return MetaAddress::fromGeneric(toLLVMArchitecture(Architecture), Address);
}
public:
static uint64_t u64(uint64_t Value) { return Value; }
};