llvm.org GIT mirror llvm / e3f3714
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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@302372 91177308-0d34-0410-b5e6-96231b3b80d8 Lang Hames 2 years ago
4 changed file(s) with 34 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
88
99 #ifndef LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
1010 #define LLVM_EXECUTIONENGINE_RUNTIMEDYLDCHECKER_H
11
12 #include "llvm/ADT/Optional.h"
1113
1214 #include
1315 #include
9698 StringRef SectionName,
9799 bool LocalAddress);
98100
101 /// \brief If there is a section at the given local address, return its load
102 /// address, otherwise return none.
103 Optional getSectionLoadAddress(void *LocalAddress) const;
104
99105 private:
100106 std::unique_ptr Impl;
101107 };
860860 SymInfo.getOffset());
861861 }
862862
863 Optional
864 RuntimeDyldCheckerImpl::getSectionLoadAddress(void *LocalAddress) const {
865 for (auto &S : getRTDyld().Sections) {
866 if (S.getAddress() == LocalAddress)
867 return S.getLoadAddress();
868 }
869 return Optional();
870 }
871
863872 void RuntimeDyldCheckerImpl::registerSection(
864873 StringRef FilePath, unsigned SectionID) {
865874 StringRef FileName = sys::path::filename(FilePath);
934943 bool LocalAddress) {
935944 return Impl->getSectionAddr(FileName, SectionName, LocalAddress);
936945 }
946
947 Optional
948 RuntimeDyldChecker::getSectionLoadAddress(void *LocalAddress) const {
949 return Impl->getSectionLoadAddress(LocalAddress);
950 }
5959 bool IsInsideLoad) const;
6060 StringRef getSubsectionStartingAt(StringRef Name) const;
6161
62 Optional getSectionLoadAddress(void *LocalAddr) const;
63
6264 void registerSection(StringRef FilePath, unsigned SectionID);
6365 void registerStubMap(StringRef FilePath, unsigned SectionID,
6466 const RuntimeDyldImpl::StubMap &RTDyldStubs);
485485 return 0;
486486 }
487487
488 static std::map
489 applySpecificSectionMappings(RuntimeDyldChecker &Checker) {
490
491 std::map SpecificMappings;
488 void applySpecificSectionMappings(RuntimeDyldChecker &Checker) {
492489
493490 for (StringRef Mapping : SpecificSectionMappings) {
494491
521518 "'.");
522519
523520 Checker.getRTDyld().mapSectionAddress(OldAddr, NewAddr);
524 SpecificMappings[OldAddr] = NewAddr;
525 }
526
527 return SpecificMappings;
521 }
528522 }
529523
530524 // Scatter sections in all directions!
553547
554548 // Apply any section-specific mappings that were requested on the command
555549 // line.
556 typedef std::map AppliedMappingsT;
557 AppliedMappingsT AppliedMappings = applySpecificSectionMappings(Checker);
550 applySpecificSectionMappings(Checker);
558551
559552 // Keep an "already allocated" mapping of section target addresses to sizes.
560553 // Sections whose address mappings aren't specified on the command line will
562555 // minimum separation.
563556 std::map AlreadyAllocated;
564557
565 // Move the previously applied mappings into the already-allocated map.
558 // Move the previously applied mappings (whether explicitly specified on the
559 // command line, or implicitly set by RuntimeDyld) into the already-allocated
560 // map.
566561 for (WorklistT::iterator I = Worklist.begin(), E = Worklist.end();
567562 I != E;) {
568563 WorklistT::iterator Tmp = I;
569564 ++I;
570 AppliedMappingsT::iterator AI = AppliedMappings.find(Tmp->first);
571
572 if (AI != AppliedMappings.end()) {
573 AlreadyAllocated[AI->second] = Tmp->second;
565 auto LoadAddr = Checker.getSectionLoadAddress(Tmp->first);
566
567 if (LoadAddr &&
568 *LoadAddr != static_cast(
569 reinterpret_cast(Tmp->first))) {
570 AlreadyAllocated[*LoadAddr] = Tmp->second;
574571 Worklist.erase(Tmp);
575572 }
576573 }