<div dir="ltr">Good point. In r241408 I've added a comment to SymbolResolver::findSymbol in RuntimeDyld.h documenting the change.<div><br></div><div>Cheers,</div><div>Lang.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Jul 3, 2015 at 9:47 PM, Philip Reames <span dir="ltr"><<a href="mailto:listmail@philipreames.com" target="_blank">listmail@philipreames.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 07/03/2015 06:35 PM, Lang Hames wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Author: lhames<br>
Date: Fri Jul 3 20:35:26 2015<br>
New Revision: 241383<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D241383-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=onjf3iWbcbrgjH0Wp9H4tCz_Djx_bS9QndtcSNfZb2o&s=WnuNPT3H0_tnUbZQZQ7KLudwtQtqTigxJs-PHJZuwM0&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=241383&view=rev</a><br>
Log:<br>
[RuntimeDyld] Skip relocations for external symbols with 64-bit address ~0ULL.<br>
<br>
Requested by Eugene Rozenfeld of the LLILC team, this feature allows JIT<br>
clients to skip relocations for selected external symbols by returning ~0ULL<br>
from their symbol resolver. If this value is returned for a given symbol,<br>
RuntimeDyld will skip all relocations for that symbol. The client will be<br>
responsible for applying the skipped relocations manually before the code<br>
is executed.<br>
</blockquote></span>
This seems like it's worth documenting somewhere. Possibly on the comment for getSymbolAddress on MCJITMemoryManager?<div class="HOEnZb"><div class="h5"><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
<br>
Modified:<br>
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp<br>
llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp<br>
llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s<br>
llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp<br>
<br>
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_ExecutionEngine_RuntimeDyld_RuntimeDyld.cpp-3Frev-3D241383-26r1-3D241382-26r2-3D241383-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=onjf3iWbcbrgjH0Wp9H4tCz_Djx_bS9QndtcSNfZb2o&s=ekaoVty0q27mLmW2lpsW2_yLDN5Fr2ncl4Q1ST9K5N8&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp?rev=241383&r1=241382&r2=241383&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp (original)<br>
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyld.cpp Fri Jul 3 20:35:26 2015<br>
@@ -815,12 +815,16 @@ void RuntimeDyldImpl::resolveExternalSym<br>
report_fatal_error("Program used external function '" + Name +<br>
"' which could not be resolved!");<br>
- DEBUG(dbgs() << "Resolving relocations Name: " << Name << "\t"<br>
- << format("0x%lx", Addr) << "\n");<br>
- // This list may have been updated when we called getSymbolAddress, so<br>
- // don't change this code to get the list earlier.<br>
- RelocationList &Relocs = i->second;<br>
- resolveRelocationList(Relocs, Addr);<br>
+ // If Resolver returned UINT64_MAX, the client wants to handle this symbol<br>
+ // manually and we shouldn't resolve its relocations.<br>
+ if (Addr != UINT64_MAX) {<br>
+ DEBUG(dbgs() << "Resolving relocations Name: " << Name << "\t"<br>
+ << format("0x%lx", Addr) << "\n");<br>
+ // This list may have been updated when we called getSymbolAddress, so<br>
+ // don't change this code to get the list earlier.<br>
+ RelocationList &Relocs = i->second;<br>
+ resolveRelocationList(Relocs, Addr);<br>
+ }<br>
}<br>
ExternalSymbolRelocations.erase(i);<br>
<br>
Modified: llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_ExecutionEngine_RuntimeDyld_RuntimeDyldChecker.cpp-3Frev-3D241383-26r1-3D241382-26r2-3D241383-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=onjf3iWbcbrgjH0Wp9H4tCz_Djx_bS9QndtcSNfZb2o&s=4XFlnE4EXHF2EwbMs2aO8cV1QeAz_Um0uBhhrrzLHJg&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp?rev=241383&r1=241382&r2=241383&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp (original)<br>
+++ llvm/trunk/lib/ExecutionEngine/RuntimeDyld/RuntimeDyldChecker.cpp Fri Jul 3 20:35:26 2015<br>
@@ -727,7 +727,9 @@ bool RuntimeDyldCheckerImpl::checkAllRul<br>
}<br>
bool RuntimeDyldCheckerImpl::isSymbolValid(StringRef Symbol) const {<br>
- return getRTDyld().getSymbolLocalAddress(Symbol) != nullptr;<br>
+ if (getRTDyld().getSymbolLocalAddress(Symbol))<br>
+ return true;<br>
+ return !!getRTDyld().Resolver.findSymbol(Symbol);<br>
}<br>
uint64_t RuntimeDyldCheckerImpl::getSymbolLocalAddr(StringRef Symbol) const {<br>
<br>
Modified: llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_test_ExecutionEngine_RuntimeDyld_X86_MachO-5Fx86-2D64-5FPIC-5Frelocations.s-3Frev-3D241383-26r1-3D241382-26r2-3D241383-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=onjf3iWbcbrgjH0Wp9H4tCz_Djx_bS9QndtcSNfZb2o&s=yOCz0pXei_aHaI-yGD3BpIinyvXTHr4KUBAXmDp3bRQ&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s?rev=241383&r1=241382&r2=241383&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s (original)<br>
+++ llvm/trunk/test/ExecutionEngine/RuntimeDyld/X86/MachO_x86-64_PIC_relocations.s Fri Jul 3 20:35:26 2015<br>
@@ -1,5 +1,5 @@<br>
# RUN: llvm-mc -triple=x86_64-apple-macosx10.9 -relocation-model=pic -filetype=obj -o %T/test_x86-64.o %s<br>
-# RUN: llvm-rtdyld -triple=x86_64-apple-macosx10.9 -verify -check=%s %/T/test_x86-64.o<br>
+# RUN: llvm-rtdyld -triple=x86_64-apple-macosx10.9 -dummy-extern ds1=0xfffffffffffffffe -dummy-extern ds2=0xffffffffffffffff -verify -check=%s %/T/test_x86-64.o<br>
.section __TEXT,__text,regular,pure_instructions<br>
.globl foo<br>
@@ -46,4 +46,15 @@ eh_frame_test:<br>
x:<br>
.long 5<br>
+# Test dummy-extern relocation.<br>
+# rtdyld-check: *{8}z1 = ds1<br>
+z1:<br>
+ .quad ds1<br>
+<br>
+# Test external-symbol relocation bypass: symbols with addr 0xffffffffffffffff<br>
+# don't have their relocations applied.<br>
+# rtdyld-check: *{8}z2 = 0<br>
+z2:<br>
+ .quad ds2<br>
+<br>
.subsections_via_symbols<br>
<br>
Modified: llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_tools_llvm-2Drtdyld_llvm-2Drtdyld.cpp-3Frev-3D241383-26r1-3D241382-26r2-3D241383-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=onjf3iWbcbrgjH0Wp9H4tCz_Djx_bS9QndtcSNfZb2o&s=8VHv2ageHSFodiOAeUhh06ClhOYCQwBC81eiQs2l7so&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp?rev=241383&r1=241382&r2=241383&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp (original)<br>
+++ llvm/trunk/tools/llvm-rtdyld/llvm-rtdyld.cpp Fri Jul 3 20:35:26 2015<br>
@@ -115,8 +115,17 @@ TargetSectionSep("target-section-sep",<br>
static cl::list<std::string><br>
SpecificSectionMappings("map-section",<br>
- cl::desc("Map a section to a specific address."),<br>
- cl::ZeroOrMore);<br>
+ cl::desc("For -verify only: Map a section to a "<br>
+ "specific address."),<br>
+ cl::ZeroOrMore,<br>
+ cl::Hidden);<br>
+<br>
+static cl::list<std::string><br>
+DummySymbolMappings("dummy-extern",<br>
+ cl::desc("For -verify only: Inject a symbol into the extern "<br>
+ "symbol table."),<br>
+ cl::ZeroOrMore,<br>
+ cl::Hidden);<br>
/* *** */<br>
@@ -147,10 +156,25 @@ public:<br>
// relocations) will get to the data cache but not to the instruction cache.<br>
virtual void invalidateInstructionCache();<br>
+ void addDummySymbol(const std::string &Name, uint64_t Addr) {<br>
+ DummyExterns[Name] = Addr;<br>
+ }<br>
+<br>
+ RuntimeDyld::SymbolInfo findSymbol(const std::string &Name) override {<br>
+ auto I = DummyExterns.find(Name);<br>
+<br>
+ if (I != DummyExterns.end())<br>
+ return RuntimeDyld::SymbolInfo(I->second, JITSymbolFlags::Exported);<br>
+<br>
+ return RTDyldMemoryManager::findSymbol(Name);<br>
+ }<br>
+<br>
void registerEHFrames(uint8_t *Addr, uint64_t LoadAddr,<br>
size_t Size) override {}<br>
void deregisterEHFrames(uint8_t *Addr, uint64_t LoadAddr,<br>
size_t Size) override {}<br>
+private:<br>
+ std::map<std::string, uint64_t> DummyExterns;<br>
};<br>
uint8_t *TrivialMemoryManager::allocateCodeSection(uintptr_t Size,<br>
@@ -401,7 +425,7 @@ applySpecificSectionMappings(RuntimeDyld<br>
for (StringRef Mapping : SpecificSectionMappings) {<br>
size_t EqualsIdx = Mapping.find_first_of("=");<br>
- StringRef SectionIDStr = Mapping.substr(0, EqualsIdx);<br>
+ std::string SectionIDStr = Mapping.substr(0, EqualsIdx);<br>
size_t ComaIdx = Mapping.find_first_of(",");<br>
if (ComaIdx == StringRef::npos) {<br>
@@ -410,8 +434,8 @@ applySpecificSectionMappings(RuntimeDyld<br>
exit(1);<br>
}<br>
- StringRef FileName = SectionIDStr.substr(0, ComaIdx);<br>
- StringRef SectionName = SectionIDStr.substr(ComaIdx + 1);<br>
+ std::string FileName = SectionIDStr.substr(0, ComaIdx);<br>
+ std::string SectionName = SectionIDStr.substr(ComaIdx + 1);<br>
uint64_t OldAddrInt;<br>
std::string ErrorMsg;<br>
@@ -425,11 +449,11 @@ applySpecificSectionMappings(RuntimeDyld<br>
void* OldAddr = reinterpret_cast<void*>(static_cast<uintptr_t>(OldAddrInt));<br>
- StringRef NewAddrStr = Mapping.substr(EqualsIdx + 1);<br>
+ std::string NewAddrStr = Mapping.substr(EqualsIdx + 1);<br>
uint64_t NewAddr;<br>
- if (NewAddrStr.getAsInteger(0, NewAddr)) {<br>
- errs() << "Invalid section address in mapping: " << Mapping << "\n";<br>
+ if (StringRef(NewAddrStr).getAsInteger(0, NewAddr)) {<br>
+ errs() << "Invalid section address in mapping '" << Mapping << "'.\n";<br>
exit(1);<br>
}<br>
@@ -451,9 +475,9 @@ applySpecificSectionMappings(RuntimeDyld<br>
// Defaults to zero. Set to something big<br>
// (e.g. 1 << 32) to stress-test stubs, GOTs, etc.<br>
//<br>
-static void remapSections(const llvm::Triple &TargetTriple,<br>
- const TrivialMemoryManager &MemMgr,<br>
- RuntimeDyldChecker &Checker) {<br>
+static void remapSectionsAndSymbols(const llvm::Triple &TargetTriple,<br>
+ TrivialMemoryManager &MemMgr,<br>
+ RuntimeDyldChecker &Checker) {<br>
// Set up a work list (section addr/size pairs).<br>
typedef std::list<std::pair<void*, uint64_t>> WorklistT;<br>
@@ -516,6 +540,27 @@ static void remapSections(const llvm::Tr<br>
Checker.getRTDyld().mapSectionAddress(CurEntry.first, NextSectionAddr);<br>
}<br>
+ // Add dummy symbols to the memory manager.<br>
+ for (const auto &Mapping : DummySymbolMappings) {<br>
+ size_t EqualsIdx = Mapping.find_first_of("=");<br>
+<br>
+ if (EqualsIdx == StringRef::npos) {<br>
+ errs() << "Invalid dummy symbol specification '" << Mapping<br>
+ << "'. Should be '<symbol name>=<addr>'\n";<br>
+ exit(1);<br>
+ }<br>
+<br>
+ std::string Symbol = Mapping.substr(0, EqualsIdx);<br>
+ std::string AddrStr = Mapping.substr(EqualsIdx + 1);<br>
+<br>
+ uint64_t Addr;<br>
+ if (StringRef(AddrStr).getAsInteger(0, Addr)) {<br>
+ errs() << "Invalid symbol mapping '" << Mapping << "'.\n";<br>
+ exit(1);<br>
+ }<br>
+<br>
+ MemMgr.addDummySymbol(Symbol, Addr);<br>
+ }<br>
}<br>
// Load and link the objects specified on the command line, but do not execute<br>
@@ -604,8 +649,9 @@ static int linkAndVerify() {<br>
}<br>
}<br>
- // Re-map the section addresses into the phony target address space.<br>
- remapSections(TheTriple, MemMgr, Checker);<br>
+ // Re-map the section addresses into the phony target address space and add<br>
+ // dummy symbols.<br>
+ remapSectionsAndSymbols(TheTriple, MemMgr, Checker);<br>
// Resolve all the relocations we can.<br>
Dyld.resolveRelocations();<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote>
<br>
</div></div></blockquote></div><br></div>