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

Rafael Espindola espindola at google.com
Wed Jun 2 18:50:16 PDT 2010


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 --------------
A non-text attachment was scrubbed...
Name: gold-shared.patch
Type: application/octet-stream
Size: 1508 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20100602/0d6bda45/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: a.c
Type: text/x-csrc
Size: 331 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20100602/0d6bda45/attachment.c>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: a.h
Type: text/x-chdr
Size: 194 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20100602/0d6bda45/attachment.h>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: main.c
Type: text/x-csrc
Size: 144 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20100602/0d6bda45/attachment-0001.c>


More information about the llvm-commits mailing list