Static linking with a custom glibc version

Mahmood Naderan nt_mahmood@yahoo.com
Thu Jun 4 13:28:02 GMT 2020


>both --sysroot and -isystem require a path argument.
>and -isystem is compile time flag, not link time flag.
>i don't know how the glibc was installed or what
>--prefix it was configured with so i cannot help
>with the details.



I have installed my glibc in /opt/glibc-2.23-install
I now use

$ gcc -isystem=/opt/glibc-2.23-install/include -c test.c
$ gcc -o test.static -Wl,--emit-relocs -static -B /opt/glibc-2.23-install/lib --sysroot=/opt/glibc-2.23-install/lib test.o


I also checked the "strace -f" for the linker command and saw somethings like

 access("/opt/glibc-2.23-install/lib/crt1.o", R_OK) = 0
access("/opt/glibc-2.23-install/lib/crti.o", R_OK) = 0
access("/usr/lib/gcc/x86_64-linux-gnu/5/crtbeginT.o", R_OK) = 0
access("/usr/lib/gcc/x86_64-linux-gnu/5/crtend.o", R_OK) = 0
access("/opt/glibc-2.23-install/lib/crtn.o", R_OK) = 0
[pid 14542] stat("/opt/glibc-2.23-install/lib/libc.a", {st_mode=S_IFREG|0644, st_size=23644748, ...}) = 0
[pid 14542] open("/opt/glibc-2.23-install/lib/libc.a", O_RDONLY) = 10
...


I guess that is fine.

> >those are for dynamic linking only (and likely same for>
> >emit-relocs)>
I am still thinking about this...
Do you mean that static link doesn't need relocation information?I can verify that ".rela.text" exists in the statid elf

$ readelf -S test.static | grep rela.text
  [ 8] .rela.text        RELA             0000000000000000  00338dd8




Regards,
Mahmood


More information about the Libc-help mailing list