How to combine LTO with symbol versioning

Nikolaus Rath Nikolaus@rath.org
Fri Sep 29 13:15:00 GMT 2017


Hi,

Really no one able to help with this?

Best,
-Nikolaus

On Sep 20 2017, Nikolaus Rath <Nikolaus@rath.org> wrote:
> Hello,
>
> I would like to compile a shared library using both symbol versioning
> and link-time optimization (LTO). However, as soon as I turn on LTO,
> some of the exported symbols vanish. For example:
>
> Start by defining two implementations of a function fun:
>
> $ 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 script to ensure that only fun is exported:
>
> $ cat versionscript 
> v1 {
>     global:
>         fun;
>     local:
>         *;
> };
> v2 {
>     global:
>         fun;
> } v1;
>
> First attempt, 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 symbols exported anymore.
>
> What am I doing wrong?
>
> $ gcc --version
> gcc (Debian 6.3.0-18) 6.3.0 20170516
>
> Best,
> -Nikolaus
> -- 
> GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F
>
>              »Time flies like an arrow, fruit flies like a Banana.«


-- 
GPG Fingerprint: ED31 791B 2C5C 1613 AF38 8B8A D113 FCAC 3C4E 599F

             »Time flies like an arrow, fruit flies like a Banana.«



More information about the Gcc-help mailing list