[LLVMdev] [llvm-c] LLVMInitializeNativeTarget not exported in shared library

Moritz Maxeiner moritzmaxeiner at googlemail.com
Sun Feb 17 08:59:38 PST 2013


Dear LLVM devs (and other subscribers),

when building llvm as a shared library (so or dll, tested with both) and 
then performing objdump
on the resulting library will reveal that LLVMInitializeNativeTarget 
does not get exported
("objdump -x libLLVM-3.3svn.so | grep LLVMInitializeNativeTarget" will 
return without any output).

As far as I can tell this is because the function is marked as inline at 
its definition in
http://llvm.org/docs/doxygen/html/TargetSelect_8h_source.html#l00116
which afaik (correct me if I'm wrong here) means that for each call to 
the function its body
will be copied to the call location when compiling/linking with other 
c/c++ code,
instead of being compiled as a normal function call (in addition it 
allows the function body
to be defined directly in the header, instead of a c/cpp file);
That in turn means the compiler won't export a symbol for this function, 
making it
inaccessible for other C compatible languages that use the shared library.

Applying a visibiliy attribute of default to the functio
i.e. changing
static inline LLVMBool LLVMInitializeNativeTarget(void) {
to
__attribute__((visibility("default"))) static inline LLVMBool 
LLVMInitializeNativeTarget(void) {
doesn't work because -fvisibility-inlines-hidden seems to get handed 
down from the top Makefile.

The solution to this may be simple, but I cannot see it right now, so I 
would be grateful
if anyone knows how to get LLVMInitializeNativeTarget to be exported 
properly (other
than to remove the inline and make it a normal function, because I think 
there was a reason
it was made inline originally), because with this afaict a llvm shared 
lib cannot be used
for jitting via the c api from non-c, c-compatible languages.

-- Moritz




More information about the llvm-dev mailing list