[llvm-commits] [patch][gold plugin] Don't preserve all symbols in a .so

Nick Lewycky nlewycky at google.com
Wed Jun 2 19:52:30 PDT 2010

-  // If we don't preserve any symbols, libLTO will assume that all symbols
-  // needed. Keep all symbols unless we're producing a final executable.

Please keep the first sentence of that comment, it's still pertinent. We
handle that case by calling lto_codegen_dispose later.

This patch is obviously correct given the changes in gold upstream, please


On 2 June 2010 18:50, Rafael Espindola <espindola at google.com> wrote:

> With the attached patch the plugin will no longer preserve all symbols
> in a .so and instead will trust gold to know what is needed. The
> result is that it is now able to drop unnecessary symbol from shared
> libraries. An example adapted from
> http://llvm.org/releases/2.6/docs/LinkTimeOptimization.html:
> $ clang -c a.c -emit-llvm -fdata-sections -ffunction-sections -fPIC
> $ clang -c main.c -fdata-sections -ffunction-sections -fPIC
> $ ld --no-add-needed --eh-frame-hdr --build-id -m elf_x86_64
> --hash-style=gnu -shared -o foo.so
> /usr/lib/gcc/x86_64-redhat-linux/4.4.4/../../../../lib64/crti.o
> /usr/lib/gcc/x86_64-redhat-linux/4.4.4/crtbeginS.o
> -L/usr/lib/gcc/x86_64-redhat-linux/4.4.4
> -L/usr/lib/gcc/x86_64-redhat-linux/4.4.4
> -L/usr/lib/gcc/x86_64-redhat-linux/4.4.4/../../../../lib64
> -L/lib/../lib64 -L/usr/lib/../lib64
> -L/usr/lib/gcc/x86_64-redhat-linux/4.4.4/../../.. main.o a.o -lgcc
> --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s
> --no-as-needed /usr/lib/gcc/x86_64-redhat-linux/4.4.4/crtendS.o
> /usr/lib/gcc/x86_64-redhat-linux/4.4.4/../../../../lib64/crtn.o
> -plugin=/home/espindola/llvm/build/Debug/lib/LLVMgold.so
> --gc-sections -plugin-opt=generate-api-file
> $ cat apifile.txt
> foo1
> foo5
> $ objdump  -d foo.so | grep foo4
> Gold itself is still not as aggressive as it could be, but that is
> another patch :-)
> And yes, I do have to implement support for gold plugin's in clang!
> Cheers,
> --
> Rafael Ávila de Espíndola
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20100602/de313a4a/attachment.html>

More information about the llvm-commits mailing list