[LLVMdev] Hidden-visibility aliases to default-visibility globals

Rafael EspĂ­ndola rafael.espindola at gmail.com
Fri May 17 09:56:21 PDT 2013


> [2] http://www.airs.com/blog/archives/307

Note that it is not just efficiency. You actually get wrong results.
Without a marker like dllimport/dllexport used on windows, the
compiler can only guess if a symbol is on this module or not.

* One option is to be conservative and say it can be in another
module. In that case it will use the GOT to get the address of a
function, which is inefficient if the function is on this module. The
static linker could optimize this a bit. This is what OS X does
(symbols are effectively protected in there).

* The other option is to guess it is on the same module. The produced
code now has a relocation for a nearby entity (it is a 32 bit field),
and the best the dynamic linker can do is fill it with the GOT
address. This is what linux does.

You can observe the different strategies with the attached IL file:

$ ./build/bin/llc main.ll -mtriple=x86_64-apple-darwin -o - | grep foo
cmpq _foo at GOTPCREL(%rip), %rax
$ ./build/bin/llc main.ll -mtriple=x86_64-pc-linux-gnu -o - | grep foo
movl $foo, %ecx

There is an interesting article about this problem in
http://www.macieira.org/blog/2012/01/sorry-state-of-dynamic-libraries-on-linux.

I sometimes day dream of getting something like dllimport/dllexport on
ELF systems, but realistically I think the best we will get to is a
default like OS X with the push for position independent executables.

Cheers,
Rafael



More information about the llvm-dev mailing list