llvm-6502/lib/ExecutionEngine
Lang Hames 2fd2535b54 [MCJIT] Make RTDyldMemoryManager::getSymbolAddress's behaviour more consistent.
This patch modifies RTDyldMemoryManager::getSymbolAddress(Name)'s behavior to
make it consistent with how clients are using it: Name should be mangled, and
getSymbolAddress should demangle it on the caller's behalf before looking the
name up in the process. This patch also fixes the one client
(MCJIT::getPointerToFunction) that had been passing unmangled names (by having
it pass mangled names instead).

Background:

RTDyldMemoryManager::getSymbolAddress(Name) has always used a re-try mechanism
when looking up symbol names in the current process. Prior to this patch
getSymbolAddress first tried to look up 'Name' exactly as the user passed it in
and then, if that failed, tried to demangle 'Name' and re-try the look up. The
implication of this behavior is that getSymbolAddress expected to be called with
unmangled names, and that handling mangled names was a fallback for convenience.
This is inconsistent with how clients (particularly the RuntimeDyldImpl
subclasses, but also MCJIT) usually use this API. Most clients pass in mangled
names, and succeed only because of the fallback case. For clients passing in
mangled names, getSymbolAddress's old behavior was actually dangerous, as it
could cause unmangled names in the process to shadow mangled names being looked
up.

For example, consider:

foo.c:

int _x = 7;
int x() { return _x; }

foo.o:

000000000000000c D __x
0000000000000000 T _x

If foo.c becomes part of the process (E.g. via dlopen("libfoo.dylib")) it will
add symbols 'x' (the function) and '_x' (the variable) to the process. However
jit clients looking for the function 'x' will be using the mangled function name
'_x' (note how function 'x' appears in foo.o). When getSymbolAddress goes
looking for '_x' it will find the variable instead, and return its address and
in place of the function, leading to JIT'd code calling the variable and
crashing (if we're lucky).

By requiring that getSymbolAddress be called with mangled names, and demangling
only when we're about to do a lookup in the process, the new behavior
implemented in this patch should eliminate any chance of names being shadowed
during lookup.

There's no good way to test this at the moment: This issue only arrises when
looking up process symbols (not JIT'd symbols). Any test case would have to
generate a platform-appropriate dylib to pass to llvm-rtdyld, and I'm not
aware of any in-tree tool for doing this in a portable way.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218187 91177308-0d34-0410-b5e6-96231b3b80d8
2014-09-20 17:44:56 +00:00
..
IntelJITEvents IntelJITEventListener updates to fix breaks by recent changes to EngineBuilder and DIContext. 2014-08-21 07:01:55 +00:00
Interpreter Converting FuncNames to a ManagedStatic to avoid static constructors and destructors. 2014-09-19 21:07:01 +00:00
MCJIT [MCJIT] Make RTDyldMemoryManager::getSymbolAddress's behaviour more consistent. 2014-09-20 17:44:56 +00:00
OProfileJIT [Modules] Fix potential ODR violations by sinking the DEBUG_TYPE 2014-04-22 03:04:17 +00:00
RuntimeDyld Converting the JITDebugLock mutex to a ManagedStatic to avoid the static constructor and destructor. 2014-09-19 21:38:20 +00:00
CMakeLists.txt [JIT] Add an out-of-line definition for the virtual destructor in 2014-09-03 20:39:10 +00:00
EventListenerCommon.h [Layering] Move DebugInfo.h into the IR library where its implementation 2014-03-06 00:46:21 +00:00
ExecutionEngine.cpp unique_ptrify passing the TargetMachine to ExecutionEngine::MCJITCtor 2014-09-02 22:41:07 +00:00
ExecutionEngineBindings.cpp Reinstate "Nuke the old JIT." 2014-09-02 22:28:02 +00:00
JITEventListener.cpp [JIT] Add an out-of-line definition for the virtual destructor in 2014-09-03 20:39:10 +00:00
LLVMBuild.txt Reinstate "Nuke the old JIT." 2014-09-02 22:28:02 +00:00
Makefile Reinstate "Nuke the old JIT." 2014-09-02 22:28:02 +00:00
RTDyldMemoryManager.cpp [MCJIT] Make RTDyldMemoryManager::getSymbolAddress's behaviour more consistent. 2014-09-20 17:44:56 +00:00
TargetSelect.cpp Reinstate "Nuke the old JIT." 2014-09-02 22:28:02 +00:00