When the linker LD does dynamic linking, it checks the SO files and does dynamic linking. However, the SO files used in linking may not be used at run time. This happens a lot in cross-compilation, for example, when I used Ubuntu X86_64 as a host to cross-compile the Hello World application for Raspberry PI 4B (using aarch64-linux-gnu-gcc), it will be linked using the libc.so.6 from the cross-compile toolchain (/usr/aarch64-linux-gnu/lib/libc.so.6 on my PC). However, it will use the libc.so.6 in the Raspberry Pi 4b's rootfs at run time.
In the example above, the libc.so.6 in Ubuntu is only used for linking, most of the content is usless. For the linker ld, it may only read the dynamic symbols table from libc.so.6. I want to save space for host(ubuntu x86-64), is there any ways to process the libc.so.6 in ubuntu, only keep the contents used during linking, and remove useless contents.
I have tried objcopy --extract-symbol libc.so.6, however, it remove the dynamic symbols table. I have also tried objcopy -j .dynsym -j .dynstr -j .dynamic libc.so.6, it seens to be work, but I don't know if there are any other bad effects.