* Static linking of a custom glibc [not found] <947270223.1380815.1591188243335.ref@mail.yahoo.com> @ 2020-06-03 12:44 ` Mahmood Naderan 2020-06-03 22:44 ` Jim Wilson 0 siblings, 1 reply; 4+ messages in thread From: Mahmood Naderan @ 2020-06-03 12:44 UTC (permalink / raw) To: gcc-help Hi I would like to statically link my program to a custom glibc version. As you can see below, the following commands are wrong. $ gcc -c test.c && gcc -o test -Wl,--emit-relocs /opt/glibc-2.23-install/lib/libc.a test.o /usr/bin/ld: dynamic STT_GNU_IFUNC symbol `strcmp' with pointer equality in `/opt/glibc-2.23-install/lib/libc.a(strcmp.o)' can not be used when making an executable; recompile with -fPIE and relink with -pie collect2: error: ld returned 1 exit status $ gcc -fPIE -c test.c && gcc -o test -pie -Wl,--emit-relocs /opt/glibc-2.23-install/lib/libc.a test.o /usr/bin/ld: /opt/glibc-2.23-install/lib/libc.a(libc-start.o): relocation R_X86_64_32 against `_dl_starting_up' can not be used when making a shared object; recompile with -fPIC /opt/glibc-2.23-install/lib/libc.a: error adding symbols: Bad value collect2: error: ld returned 1 exit status $ gcc -fPIC -c test.c && gcc -o test -pie -Wl,--emit-relocs /opt/glibc-2.23-install/lib/libc.a test.o /usr/bin/ld: /opt/glibc-2.23-install/lib/libc.a(libc-start.o): relocation R_X86_64_32 against `_dl_starting_up' can not be used when making a shared object; recompile with -fPIC /opt/glibc-2.23-install/lib/libc.a: error adding symbols: Bad value collect2: error: ld returned 1 exit status Regards, Mahmood ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Static linking of a custom glibc 2020-06-03 12:44 ` Static linking of a custom glibc Mahmood Naderan @ 2020-06-03 22:44 ` Jim Wilson 2020-06-04 5:17 ` Mahmood Naderan 0 siblings, 1 reply; 4+ messages in thread From: Jim Wilson @ 2020-06-03 22:44 UTC (permalink / raw) To: Mahmood Naderan; +Cc: gcc-help On Wed, Jun 3, 2020 at 5:44 AM Mahmood Naderan via Gcc-help <gcc-help@gcc.gnu.org> wrote: > I would like to statically link my program to a custom glibc version. As you can see below, the following commands are wrong. This looks like more of a glibc question than a gcc question. I would suggest reading https://sourceware.org/glibc/wiki/Testing/Builds Jim ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Static linking of a custom glibc 2020-06-03 22:44 ` Jim Wilson @ 2020-06-04 5:17 ` Mahmood Naderan 2020-06-04 11:18 ` Andrew Haley 0 siblings, 1 reply; 4+ messages in thread From: Mahmood Naderan @ 2020-06-04 5:17 UTC (permalink / raw) To: Jim Wilson; +Cc: gcc-help >This looks like more of a glibc question than a gcc question. I would >suggest reading > https://sourceware.org/glibc/wiki/Testing/Builds Yes I am able to link to the new glibc with "-Wl,-rpath" and "-Wl,--dynamic-linker ". But, even with the default libc on the system, I am not able to link statically. $ gcc -o test -Wl,--emit-relocs -Wl,-Bstatic test.o /usr/bin/ld: cannot find -lgcc_s/usr/bin/ld: cannot find -lgcc_s collect2: error: ld returned 1 exit status I ask that on glibc list, but it seems that this is a gcc related problem.I am confused... Regards, Mahmood | | | | Testing/Builds - glibc wiki | | | ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Static linking of a custom glibc 2020-06-04 5:17 ` Mahmood Naderan @ 2020-06-04 11:18 ` Andrew Haley 0 siblings, 0 replies; 4+ messages in thread From: Andrew Haley @ 2020-06-04 11:18 UTC (permalink / raw) To: Mahmood Naderan, Jim Wilson; +Cc: gcc-help On 04/06/2020 06:17, Mahmood Naderan via Gcc-help wrote: >> This looks like more of a glibc question than a gcc question. I would >> suggest reading >> https://sourceware.org/glibc/wiki/Testing/Builds > > Yes I am able to link to the new glibc with "-Wl,-rpath" and "-Wl,--dynamic-linker ". > But, even with the default libc on the system, I am not able to link statically. > $ gcc -o test -Wl,--emit-relocs -Wl,-Bstatic test.o > /usr/bin/ld: cannot find -lgcc_s/usr/bin/ld: cannot find -lgcc_s > collect2: error: ld returned 1 exit status > > I ask that on glibc list, but it seems that this is a gcc related problem.I am confused... What is that command supposed to do? You're telling GCC to compile and link dynamically dynamically, but telling the linker to link statically. if you want GCC to link statically you're going to have to use -static. You're also going to have to compile statically, with -static. If I want to link statically with a custom libc, I can do this: gcc -static hello.c -Wl,--as-needed /usr/lib64/libc.a -Wl,--no-as-needed Use the GCC option -Wl,-Map,mapfile and you'll be able to see what happens. -- Andrew Haley (he/him) Java Platform Lead Engineer Red Hat UK Ltd. <https://www.redhat.com> https://keybase.io/andrewhaley EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671 ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-06-04 11:18 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <947270223.1380815.1591188243335.ref@mail.yahoo.com> 2020-06-03 12:44 ` Static linking of a custom glibc Mahmood Naderan 2020-06-03 22:44 ` Jim Wilson 2020-06-04 5:17 ` Mahmood Naderan 2020-06-04 11:18 ` Andrew Haley
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).