Fix a dynamic symbol lookup issue in interpreter mode.

This was a very subtle bug, which occurred only in interpreter mode under Linux.
The actual name of the symbol should be artificially prefixed by an underscore,
because this underscore is stripped during a symbol lookup in interpreter mode.
If this is not done, then a reference to variable "_x" is being resolved as a reference
to the function "x"!
This commit is contained in:
Roman Levenstein
2016-02-25 09:11:15 -08:00
parent b3e60afcc7
commit f9d0609d16

View File

@@ -595,8 +595,14 @@ llvm::Constant *swift::getWrapperFn(llvm::Module &Module,
ARGS, ATTRS) \
llvm::Constant *IRGenModule::get##ID##Fn() { \
using namespace RuntimeConstants; \
return getWrapperFn(Module, ID##Fn, #NAME, STR(SYMBOL_NAME), CC, RETURNS, \
ARGS, ATTRS); \
/* Add an underscore in JIT mode under Linux to enable proper symbol \
* lookup */ \
const char *Symbol = \
(Opts.UseJIT && TargetInfo.OutputObjectFormat == llvm::Triple::ELF) \
? "_" STR(SYMBOL_NAME) \
: STR(SYMBOL_NAME); \
return getWrapperFn(Module, ID##Fn, #NAME, Symbol, CC, RETURNS, ARGS, \
ATTRS); \
}
#include "swift/Runtime/RuntimeFunctions.def"