#ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
#define LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
+#include "llvm/ADT/Optional.h"
+
#include <cstdint>
#include <memory>
#include <string>
StringRef SectionName,
bool LocalAddress);
+ /// \brief If there is a section at the given local address, return its load
+ /// address, otherwise return none.
+ Optional<uint64_t> getSectionLoadAddress(void *LocalAddress) const;
+
private:
std::unique_ptr<RuntimeDyldCheckerImpl> Impl;
};
SymInfo.getOffset());
}
+Optional<uint64_t>
+RuntimeDyldCheckerImpl::getSectionLoadAddress(void *LocalAddress) const {
+ for (auto &S : getRTDyld().Sections) {
+ if (S.getAddress() == LocalAddress)
+ return S.getLoadAddress();
+ }
+ return Optional<uint64_t>();
+}
+
void RuntimeDyldCheckerImpl::registerSection(
StringRef FilePath, unsigned SectionID) {
StringRef FileName = sys::path::filename(FilePath);
bool LocalAddress) {
return Impl->getSectionAddr(FileName, SectionName, LocalAddress);
}
+
+Optional<uint64_t>
+RuntimeDyldChecker::getSectionLoadAddress(void *LocalAddress) const {
+ return Impl->getSectionLoadAddress(LocalAddress);
+}
bool IsInsideLoad) const;
StringRef getSubsectionStartingAt(StringRef Name) const;
+ Optional<uint64_t> getSectionLoadAddress(void *LocalAddr) const;
+
void registerSection(StringRef FilePath, unsigned SectionID);
void registerStubMap(StringRef FilePath, unsigned SectionID,
const RuntimeDyldImpl::StubMap &RTDyldStubs);
return 0;
}
-static std::map<void *, uint64_t>
-applySpecificSectionMappings(RuntimeDyldChecker &Checker) {
-
- std::map<void*, uint64_t> SpecificMappings;
+void applySpecificSectionMappings(RuntimeDyldChecker &Checker) {
for (StringRef Mapping : SpecificSectionMappings) {
"'.");
Checker.getRTDyld().mapSectionAddress(OldAddr, NewAddr);
- SpecificMappings[OldAddr] = NewAddr;
}
-
- return SpecificMappings;
}
// Scatter sections in all directions!
// Apply any section-specific mappings that were requested on the command
// line.
- typedef std::map<void*, uint64_t> AppliedMappingsT;
- AppliedMappingsT AppliedMappings = applySpecificSectionMappings(Checker);
+ applySpecificSectionMappings(Checker);
// Keep an "already allocated" mapping of section target addresses to sizes.
// Sections whose address mappings aren't specified on the command line will
// minimum separation.
std::map<uint64_t, uint64_t> AlreadyAllocated;
- // Move the previously applied mappings into the already-allocated map.
+ // Move the previously applied mappings (whether explicitly specified on the
+ // command line, or implicitly set by RuntimeDyld) into the already-allocated
+ // map.
for (WorklistT::iterator I = Worklist.begin(), E = Worklist.end();
I != E;) {
WorklistT::iterator Tmp = I;
++I;
- AppliedMappingsT::iterator AI = AppliedMappings.find(Tmp->first);
+ auto LoadAddr = Checker.getSectionLoadAddress(Tmp->first);
- if (AI != AppliedMappings.end()) {
- AlreadyAllocated[AI->second] = Tmp->second;
+ if (LoadAddr &&
+ *LoadAddr != static_cast<uint64_t>(
+ reinterpret_cast<uintptr_t>(Tmp->first))) {
+ AlreadyAllocated[*LoadAddr] = Tmp->second;
Worklist.erase(Tmp);
}
}