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)