I would like to compile a common library using both character versioning and connection time optimization (LTO). However, as soon as I turn on LTO, some exported characters disappear. Here is a minimal example:
We start by defining two implementations of the fun function:
$ cat fun.c #include <stdio.h> int fun1(void); int fun2(void); __asm__(".symver fun1, fun@v1 "); int fun1() { printf("fun1 called\n"); return 1; } __asm__(".symver fun2, fun@ @v2"); int fun2() { printf("fun2 called\n"); return 2; }
Create a version of the script to ensure that only fun is exported:
$ cat versionscript v1 { global: fun; local: *; }; v2 { global: fun; } v1;
First attempt to compile without LTO:
$ gcc -o fun.o -Wall -Wextra -O2 -fPIC -c fun.c $ gcc -o libfun.so.1 -shared -fPIC -Wl,--version-script,versionscript fun.o $ nm -D --with-symbol-versions libfun.so.1 | grep fun 00000000000006b0 T fun@ @v2 0000000000000690 T fun@v1
.. exactly as it should be. But if I compile with LTO:
$ gcc -o fun.o -Wall -Wextra -flto -O2 -fPIC -c fun.c $ gcc -o libfun.so.1 -flto -shared -fPIC -Wl,--version-script,versionscript fun.o $ nm -D --with-symbol-versions libfun.so.1 | grep fun
.. no more characters exported.
What am I doing wrong?
source share