[LLVMdev] [PATCH][RFC] Bug #4406: stubs for external functions should be registered even if DlsymStubs are disabled

Eric Rannaud eric.rannaud at gmail.com
Wed Jul 1 15:26:12 PDT 2009


See http://llvm.org/bugs/show_bug.cgi?id=4406

The testcase at http://llvm.org/bugs/attachment.cgi?id=3141 needs to be
updated to free the machine code with:

        ee->freeMachineCodeForFunction(cast<Function>(ll_main));

Once that's done, though, the AssertingVH is still triggered on
destruction of the Module.

It turns out that the stub for the external "write" is not registered by
JITEmitter::AddStubToCurrentFunction() because DlsymStubs are not
enabled.

	void JITEmitter::AddStubToCurrentFunction(void *StubAddr) {
	  if (!TheJIT->areDlsymStubsEnabled())
	    return;

It seems wrong. From include/llvm/ExecutionEngine/JITMemoryManager.h, my
understanding is that DlsymStubs are only necessary in certain
situations (like supporting relocations in a different process that the
one doing the JIT), and do not have to be enabled for the testcase to be
correct. (Enabling DlsymStubs, however, does solve the problem, so maybe
that's just what I need to do).

Because the stub is not registered by JITEmitter::AddStubToCurrentFunction(),
JITEmitter::deallocateMemForFunction() cannot dereference it, and it
never gets freed. When the GlobalValue for "write" gets destroyed, the
stub still holds a reference to it, triggering the AssertingVH.

I assume that it is correct for the JIT to create a stub for "write"
even when DlsymStub are disabled. If that's right, then the stub should
be registered by AddStubToCurrentFunction().

If, on the other hand, we don't want stubs in such a case, then there is
another problem elsewhere that turns the call to "write" into an
incorrect MachineRelocation.

Thanks,
Eric.


Index: lib/ExecutionEngine/JIT/JITEmitter.cpp
===================================================================
--- lib/ExecutionEngine/JIT/JITEmitter.cpp	(revision 74506)
+++ lib/ExecutionEngine/JIT/JITEmitter.cpp	(working copy)
@@ -658,9 +658,6 @@
 }
 
 void JITEmitter::AddStubToCurrentFunction(void *StubAddr) {
-  if (!TheJIT->areDlsymStubsEnabled())
-    return;
-  
   assert(CurFn && "Stub added to current function, but current function is 0!");
   
   SmallVectorImpl<void*> &StubsUsed = CurFnStubUses[CurFn];




More information about the llvm-dev mailing list