[llvm-commits] [llvm] r86606 - in /llvm/trunk: include/llvm/ExecutionEngine/ExecutionEngine.h include/llvm/ExecutionEngine/JITMemoryManager.h lib/ExecutionEngine/ExecutionEngine.cpp lib/ExecutionEngine/JIT/JIT.cpp lib/ExecutionEngine/JIT/JIT.h lib/ExecutionEngine/JIT/JITEmitter.cpp lib/ExecutionEngine/JIT/JITMemoryManager.cpp unittests/ExecutionEngine/JIT/JITTest.cpp
Jeffrey Yasskin
jyasskin at google.com
Mon Nov 9 14:34:19 PST 2009
Author: jyasskin
Date: Mon Nov 9 16:34:19 2009
New Revision: 86606
URL: http://llvm.org/viewvc/llvm-project?rev=86606&view=rev
Log:
Remove dlsym stubs, with Nate Begeman's permission.
Modified:
llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h
llvm/trunk/include/llvm/ExecutionEngine/JITMemoryManager.h
llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp
llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp
llvm/trunk/lib/ExecutionEngine/JIT/JIT.h
llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp
llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp
Modified: llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h?rev=86606&r1=86605&r2=86606&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/ExecutionEngine.h Mon Nov 9 16:34:19 2009
@@ -91,7 +91,6 @@
bool CompilingLazily;
bool GVCompilationDisabled;
bool SymbolSearchingDisabled;
- bool DlsymStubsEnabled;
friend class EngineBuilder; // To allow access to JITCtor and InterpCtor.
@@ -369,15 +368,7 @@
bool isSymbolSearchingDisabled() const {
return SymbolSearchingDisabled;
}
-
- /// EnableDlsymStubs -
- void EnableDlsymStubs(bool Enabled = true) {
- DlsymStubsEnabled = Enabled;
- }
- bool areDlsymStubsEnabled() const {
- return DlsymStubsEnabled;
- }
-
+
/// InstallLazyFunctionCreator - If an unknown function is needed, the
/// specified function pointer is invoked to create it. If it returns null,
/// the JIT will abort.
Modified: llvm/trunk/include/llvm/ExecutionEngine/JITMemoryManager.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ExecutionEngine/JITMemoryManager.h?rev=86606&r1=86605&r2=86606&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ExecutionEngine/JITMemoryManager.h (original)
+++ llvm/trunk/include/llvm/ExecutionEngine/JITMemoryManager.h Mon Nov 9 16:34:19 2009
@@ -71,17 +71,6 @@
/// return a pointer to its base.
virtual uint8_t *getGOTBase() const = 0;
- /// SetDlsymTable - If the JIT must be able to relocate stubs after they have
- /// been emitted, potentially because they are being copied to a process
- /// where external symbols live at different addresses than in the JITing
- /// process, allocate a table with sufficient information to do so.
- virtual void SetDlsymTable(void *ptr) = 0;
-
- /// getDlsymTable - If this is managing a table of entries so that stubs to
- /// external symbols can be later relocated, this method should return a
- /// pointer to it.
- virtual void *getDlsymTable() const = 0;
-
/// NeedsExactSize - If the memory manager requires to know the size of the
/// objects to be emitted
bool NeedsExactSize() const {
Modified: llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp?rev=86606&r1=86605&r2=86606&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/ExecutionEngine.cpp Mon Nov 9 16:34:19 2009
@@ -52,7 +52,6 @@
CompilingLazily = false;
GVCompilationDisabled = false;
SymbolSearchingDisabled = false;
- DlsymStubsEnabled = false;
Modules.push_back(P);
assert(P && "ModuleProvider is null?");
}
Modified: llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp?rev=86606&r1=86605&r2=86606&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JIT.cpp Mon Nov 9 16:34:19 2009
@@ -613,11 +613,6 @@
// the stub with real address of the function.
updateFunctionStub(PF);
}
-
- // If the JIT is configured to emit info so that dlsym can be used to
- // rewrite stubs to external globals, do so now.
- if (areDlsymStubsEnabled() && !isCompilingLazily())
- updateDlsymStubTable();
}
/// getPointerToFunction - This method is used to get the address of the
@@ -660,8 +655,7 @@
}
if (F->isDeclaration() || F->hasAvailableExternallyLinkage()) {
- bool AbortOnFailure =
- !areDlsymStubsEnabled() && !F->hasExternalWeakLinkage();
+ bool AbortOnFailure = !F->hasExternalWeakLinkage();
void *Addr = getPointerToNamedFunction(F->getName(), AbortOnFailure);
addGlobalMapping(F, Addr);
return Addr;
@@ -690,7 +684,7 @@
return (void*)&__dso_handle;
#endif
Ptr = sys::DynamicLibrary::SearchForAddressOfSymbol(GV->getName());
- if (Ptr == 0 && !areDlsymStubsEnabled()) {
+ if (Ptr == 0) {
llvm_report_error("Could not resolve external global address: "
+GV->getName());
}
Modified: llvm/trunk/lib/ExecutionEngine/JIT/JIT.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JIT.h?rev=86606&r1=86605&r2=86606&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JIT.h (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JIT.h Mon Nov 9 16:34:19 2009
@@ -195,7 +195,6 @@
TargetMachine &tm);
void runJITOnFunctionUnlocked(Function *F, const MutexGuard &locked);
void updateFunctionStub(Function *F);
- void updateDlsymStubTable();
protected:
Modified: llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp?rev=86606&r1=86605&r2=86606&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JITEmitter.cpp Mon Nov 9 16:34:19 2009
@@ -369,10 +369,6 @@
// the stub is unused.
DenseMap<void *, SmallPtrSet<const Function*, 1> > StubFnRefs;
- // ExtFnStubs - A map of external function names to stubs which have entries
- // in the JITResolver's ExternalFnToStubMap.
- StringMap<void *> ExtFnStubs;
-
DebugLocTuple PrevDLT;
public:
@@ -461,10 +457,6 @@
/// deallocateMemForFunction to also remove stubs no longer referenced.
void AddStubToCurrentFunction(void *Stub);
- /// getExternalFnStubs - Accessor for the JIT to find stubs emitted for
- /// MachineRelocations that reference external functions by name.
- const StringMap<void*> &getExternalFnStubs() const { return ExtFnStubs; }
-
virtual void processDebugLoc(DebugLoc DL, bool BeforePrintingInsn);
virtual void emitLabel(uint64_t LabelID) {
@@ -536,10 +528,8 @@
Actual = TheJIT->getPointerToFunction(F);
// If we resolved the symbol to a null address (eg. a weak external)
- // don't emit a stub. Return a null pointer to the application. If dlsym
- // stubs are enabled, not being able to resolve the address is not
- // meaningful.
- if (!Actual && !TheJIT->areDlsymStubsEnabled()) return 0;
+ // don't emit a stub. Return a null pointer to the application.
+ if (!Actual) return 0;
}
// Codegen a new stub, calling the lazy resolver or the actual address of the
@@ -758,10 +748,9 @@
if (ResultPtr) return ResultPtr;
// If this is an external function pointer, we can force the JIT to
- // 'compile' it, which really just adds it to the map. In dlsym mode,
- // external functions are forced through a stub, regardless of reloc type.
+ // 'compile' it, which really just adds it to the map.
if (F->isDeclaration() && !F->hasNotBeenReadFromBitcode() &&
- !MayNeedFarStub && !TheJIT->areDlsymStubsEnabled())
+ !MayNeedFarStub)
return TheJIT->getPointerToFunction(F);
// Okay, the function has not been compiled yet, if the target callback
@@ -1112,16 +1101,7 @@
// If the target REALLY wants a stub for this function, emit it now.
if (MR.mayNeedFarStub()) {
- if (!TheJIT->areDlsymStubsEnabled()) {
- ResultPtr = Resolver.getExternalFunctionStub(ResultPtr);
- } else {
- void *&Stub = ExtFnStubs[MR.getExternalSymbol()];
- if (!Stub) {
- Stub = Resolver.getExternalFunctionStub((void *)&Stub);
- AddStubToCurrentFunction(Stub);
- }
- ResultPtr = Stub;
- }
+ ResultPtr = Resolver.getExternalFunctionStub(ResultPtr);
}
} else if (MR.isGlobalValue()) {
ResultPtr = getPointerToGlobal(MR.getGlobalValue(),
@@ -1335,19 +1315,10 @@
StubFnRefs.erase(Stub);
// Invalidate the stub. If it is a GV stub, update the JIT's global
- // mapping for that GV to zero, otherwise, search the string map of
- // external function names to stubs and remove the entry for this stub.
+ // mapping for that GV to zero.
GlobalValue *GV = Resolver.invalidateStub(Stub);
if (GV) {
TheJIT->updateGlobalMapping(GV, 0);
- } else {
- for (StringMapIterator<void*> i = ExtFnStubs.begin(),
- e = ExtFnStubs.end(); i != e; ++i) {
- if (i->second == Stub) {
- ExtFnStubs.erase(i);
- break;
- }
- }
}
}
}
@@ -1588,92 +1559,6 @@
getJITInfo().emitFunctionStubAtAddr(F, Addr, Stub, *getCodeEmitter());
}
-/// updateDlsymStubTable - Emit the data necessary to relocate the stubs
-/// that were emitted during code generation.
-///
-void JIT::updateDlsymStubTable() {
- assert(isa<JITEmitter>(JCE) && "Unexpected MCE?");
- JITEmitter *JE = cast<JITEmitter>(getCodeEmitter());
-
- SmallVector<GlobalValue*, 8> GVs;
- SmallVector<void*, 8> Ptrs;
- const StringMap<void *> &ExtFns = JE->getExternalFnStubs();
-
- JE->getJITResolver().getRelocatableGVs(GVs, Ptrs);
-
- unsigned nStubs = GVs.size() + ExtFns.size();
-
- // If there are no relocatable stubs, return.
- if (nStubs == 0)
- return;
-
- // If there are no new relocatable stubs, return.
- void *CurTable = JE->getMemMgr()->getDlsymTable();
- if (CurTable && (*(unsigned *)CurTable == nStubs))
- return;
-
- // Calculate the size of the stub info
- unsigned offset = 4 + 4 * nStubs + sizeof(intptr_t) * nStubs;
-
- SmallVector<unsigned, 8> Offsets;
- for (unsigned i = 0; i != GVs.size(); ++i) {
- Offsets.push_back(offset);
- offset += GVs[i]->getName().size() + 1;
- }
- for (StringMapConstIterator<void*> i = ExtFns.begin(), e = ExtFns.end();
- i != e; ++i) {
- Offsets.push_back(offset);
- offset += strlen(i->first()) + 1;
- }
-
- // Allocate space for the new "stub", which contains the dlsym table.
- JE->startGVStub(0, offset, 4);
-
- // Emit the number of records
- JE->emitInt32(nStubs);
-
- // Emit the string offsets
- for (unsigned i = 0; i != nStubs; ++i)
- JE->emitInt32(Offsets[i]);
-
- // Emit the pointers. Verify that they are at least 2-byte aligned, and set
- // the low bit to 0 == GV, 1 == Function, so that the client code doing the
- // relocation can write the relocated pointer at the appropriate place in
- // the stub.
- for (unsigned i = 0; i != GVs.size(); ++i) {
- intptr_t Ptr = (intptr_t)Ptrs[i];
- assert((Ptr & 1) == 0 && "Stub pointers must be at least 2-byte aligned!");
-
- if (isa<Function>(GVs[i]))
- Ptr |= (intptr_t)1;
-
- if (sizeof(Ptr) == 8)
- JE->emitInt64(Ptr);
- else
- JE->emitInt32(Ptr);
- }
- for (StringMapConstIterator<void*> i = ExtFns.begin(), e = ExtFns.end();
- i != e; ++i) {
- intptr_t Ptr = (intptr_t)i->second | 1;
-
- if (sizeof(Ptr) == 8)
- JE->emitInt64(Ptr);
- else
- JE->emitInt32(Ptr);
- }
-
- // Emit the strings.
- for (unsigned i = 0; i != GVs.size(); ++i)
- JE->emitString(GVs[i]->getName());
- for (StringMapConstIterator<void*> i = ExtFns.begin(), e = ExtFns.end();
- i != e; ++i)
- JE->emitString(i->first());
-
- // Tell the JIT memory manager where it is. The JIT Memory Manager will
- // deallocate space for the old one, if one existed.
- JE->getMemMgr()->SetDlsymTable(JE->finishGVStub(0));
-}
-
/// freeMachineCodeForFunction - release machine code memory for given Function.
///
void JIT::freeMachineCodeForFunction(Function *F) {
Modified: llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp?rev=86606&r1=86605&r2=86606&view=diff
==============================================================================
--- llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp (original)
+++ llvm/trunk/lib/ExecutionEngine/JIT/JITMemoryManager.cpp Mon Nov 9 16:34:19 2009
@@ -296,7 +296,6 @@
MemoryRangeHeader *CurBlock;
uint8_t *GOTBase; // Target Specific reserved memory
- void *DlsymTable; // Stub external symbol information
public:
DefaultJITMemoryManager();
~DefaultJITMemoryManager();
@@ -318,7 +317,6 @@
static const size_t DefaultSizeThreshold;
void AllocateGOT();
- void SetDlsymTable(void *);
// Testing methods.
virtual bool CheckInvariants(std::string &ErrorStr);
@@ -469,10 +467,6 @@
return GOTBase;
}
- void *getDlsymTable() const {
- return DlsymTable;
- }
-
void deallocateBlock(void *Block) {
// Find the block that is allocated for this function.
MemoryRangeHeader *MemRange = static_cast<MemoryRangeHeader*>(Block) - 1;
@@ -599,7 +593,6 @@
FreeMemoryList = Mem0;
GOTBase = NULL;
- DlsymTable = NULL;
}
void DefaultJITMemoryManager::AllocateGOT() {
@@ -608,10 +601,6 @@
HasGOT = true;
}
-void DefaultJITMemoryManager::SetDlsymTable(void *ptr) {
- DlsymTable = ptr;
-}
-
DefaultJITMemoryManager::~DefaultJITMemoryManager() {
for (unsigned i = 0, e = CodeSlabs.size(); i != e; ++i)
sys::Memory::ReleaseRWX(CodeSlabs[i]);
Modified: llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp?rev=86606&r1=86605&r2=86606&view=diff
==============================================================================
--- llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp (original)
+++ llvm/trunk/unittests/ExecutionEngine/JIT/JITTest.cpp Mon Nov 9 16:34:19 2009
@@ -68,8 +68,6 @@
virtual void setPoisonMemory(bool poison) { Base->setPoisonMemory(poison); }
virtual void AllocateGOT() { Base->AllocateGOT(); }
virtual uint8_t *getGOTBase() const { return Base->getGOTBase(); }
- virtual void SetDlsymTable(void *ptr) { Base->SetDlsymTable(ptr); }
- virtual void *getDlsymTable() const { return Base->getDlsymTable(); }
struct StartFunctionBodyCall {
StartFunctionBodyCall(uint8_t *Result, const Function *F,
uintptr_t ActualSize, uintptr_t ActualSizeResult)
@@ -303,7 +301,6 @@
ConstantInt::get(TypeBuilder<int, false>::get(Context), 7));
Builder.CreateRet(result);
- TheJIT->EnableDlsymStubs(false);
TheJIT->DisableLazyCompilation(true);
int (*TestFunctionPtr)() = reinterpret_cast<int(*)()>(
(intptr_t)TheJIT->getPointerToFunction(TestFunction));
More information about the llvm-commits
mailing list