diff options
author | Lang Hames <lhames@gmail.com> | 2017-05-07 17:19:53 +0000 |
---|---|---|
committer | Lang Hames <lhames@gmail.com> | 2017-05-07 17:19:53 +0000 |
commit | ff41150ddb5a722c6e614e31f89e8fa52e2f7595 (patch) | |
tree | 11293cfeff37f5cf39c570c2f2ea2cfd88e8ebd5 /llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp | |
parent | 252682a41bcb7d3c100aaf2f2fb21c7895714773 (diff) | |
download | bcm5719-llvm-ff41150ddb5a722c6e614e31f89e8fa52e2f7595.tar.gz bcm5719-llvm-ff41150ddb5a722c6e614e31f89e8fa52e2f7595.zip |
Make llvm-rtdlyd -check preserve automatic address mappings made by RuntimeDyld.
Currently llvm-rtdyld in -check mode will map sections to back-to-back 4k
aligned slabs starting at 0x1000. Automatically remapping sections by default is
helpful because it quickly exposes relocation bugs due to use of local addresses
rather than load addresses (these would silently pass if the load address was
not remapped). These mappings can be explicitly overridden on a per-section
basis using llvm-rtdlyd's -map-section option. This patch extends this scheme to
also preserve any mappings made by RuntimeDyld itself. Preserving RuntimeDyld's
automatic mappings allows us to write test cases to verify that these automatic
mappings have been applied.
This will allow the fix in https://reviews.llvm.org/D32899 to be tested with
llvm-rtdyld -check.
llvm-svn: 302372
Diffstat (limited to 'llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp')
-rw-r--r-- | llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp index 4e1caa0400f..75345de5028 100644 --- a/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp +++ b/llvm/tools/llvm-rtdyld/llvm-rtdyld.cpp @@ -486,10 +486,7 @@ static int checkAllExpressions(RuntimeDyldChecker &Checker) { 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) { @@ -522,10 +519,7 @@ applySpecificSectionMappings(RuntimeDyldChecker &Checker) { "'."); Checker.getRTDyld().mapSectionAddress(OldAddr, NewAddr); - SpecificMappings[OldAddr] = NewAddr; } - - return SpecificMappings; } // Scatter sections in all directions! @@ -554,8 +548,7 @@ static void remapSectionsAndSymbols(const llvm::Triple &TargetTriple, // 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 @@ -563,15 +556,19 @@ static void remapSectionsAndSymbols(const llvm::Triple &TargetTriple, // 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); } } |