This is an archive of the discontinued LLVM Phabricator instance.

[LLVMgold] add option to statically link libstdc++ and libgcc
AbandonedPublic

Authored by sugak on May 4 2017, 3:26 PM.

Details

Summary

This introduces LLVM_LINK_LIBSTDCXX_INTO_GOLD_PLUGIN cmake option to be able to statically link libstdc++ and libgcc into the LLVMgold.so plugin. It'll allow to use the plugin with the gold linker built against a different version of libstdc++.

Test Plan:
Build LLVM without specifying LLVM_LINK_LIBSTDCXX_INTO_GOLD_PLUGIN cmake option, and verify that the dynamic linker looks up libstdc++ and libgcc.

ldd lib/LLVMgold.so
        linux-vdso.so.1 =>  (0x00007ffc8bc4f000)
        librt.so.1 => /lib64/librt.so.1 (0x00007fa0be3bc000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007fa0be1b7000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007fa0bdf9b000)
        libz.so.1 => /lib64/libz.so.1 (0x00007fa0bdd85000)
        libstdc++.so.6 => /.../gcc/lib64/libstdc++.so.6 (0x00007fa0bd9f5000)
        libm.so.6 => /lib64/libm.so.6 (0x00007fa0bd6f3000)
        libgcc_s.so.1 => /.../gcc/lib64/libgcc_s.so.1 (0x00007fa0bd4dc000)
        libc.so.6 => /lib64/libc.so.6 (0x00007fa0bd11a000)
        /lib64/ld-linux-x86-64.so.2 (0x00005584b3646000)

Configure LLVM with -DLLVM_LINK_LIBSTDCXX_INTO_GOLD_PLUGIN=YES and verify that the built plugin doesn't require libstdc++ and libgcc:

ldd lib/LLVMgold.so
        linux-vdso.so.1 =>  (0x00007ffe6936a000)
        librt.so.1 => /lib64/librt.so.1 (0x00007f72a49fc000)
        libdl.so.2 => /lib64/libdl.so.2 (0x00007f72a47f7000)
        libpthread.so.0 => /lib64/libpthread.so.0 (0x00007f72a45db000)
        libz.so.1 => /lib64/libz.so.1 (0x00007f72a43c5000)
        libm.so.6 => /lib64/libm.so.6 (0x00007f72a40c2000)
        libc.so.6 => /lib64/libc.so.6 (0x00007f72a3d01000)
        /lib64/ld-linux-x86-64.so.2 (0x00005650d9129000)

Diff Detail

Event Timeline

sugak created this revision.May 4 2017, 3:26 PM
sugak edited the summary of this revision. (Show Details)May 4 2017, 3:26 PM
sugak added a subscriber: llvm-commits.
pcc edited edge metadata.May 4 2017, 3:31 PM

Does this need to be a cmake option? Can you pass these flags yourself instead with CMAKE_MODULE_LINK_FLAGS?

sugak abandoned this revision.May 4 2017, 3:57 PM

I didn't know about CMAKE_MODULE_LINK_FLAGS! Confirming that the following achieves the same result as the proposed diff:

cmake . . . -DCMAKE_MODULE_LINKER_FLAGS='-static-libgcc -static-libstdc++'

Thanks!

chapuni added a subscriber: chapuni.May 4 2017, 4:14 PM

I prefer using target property rather than LINK_LIBS.