trippels@gcc20 nscd % cat nscd.i extern int program_invocation_name; extern void fn2(int, int); void fn1() { fn2(0, program_invocation_name); } trippels@gcc20 nscd % gcc -shared nscd.i -fpie /home/trippels/bin/ld: /home/trippels/tmp/ccoI5Lbg.o: relocation R_X86_64_PC32 against undefined symbol `program_invocation_name@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC /home/trippels/bin/ld: final link failed: Bad value collect2: error: ld returned 1 exit status
I'd say 2014-12-04 Sriraman Tallam <tmsriram@google.com> H.J. Lu <hongjiu.lu@intel.com> * configure.ac (HAVE_LD_PIE_COPYRELOC): Defined to 1 if Linux/x86-64 linker supports PIE with copy reloc. * config.in: Regenerated. * configure: Likewise. * config/i386/i386.c (legitimate_pic_address_disp_p): Allow pc-relative address for undefined, non-weak, non-function symbol reference in 64-bit PIE if linker supports PIE with copy reloc. * doc/sourcebuild.texi: Document pie_copyreloc target. ?
Started with r218397. HJ, it looks like this is now the intended behavior. Original error: /home/trippels/gcc_test/usr/local/bin/gcc -pie -Wl,-O1 -nostdlib -nostartfiles -o /home/trippels/glibc_build/nscd/nscd -Wl,-z,now -Wl,-z,combreloc -Wl,-z,relro -Wl,--hash-s tyle=both /home/trippels/glibc_build/csu/Scrt1.o /home/trippels/glibc_build/csu/crti.o `/home/trippels/gcc_test/usr/local/bin/gcc --print-file-name=crtbeginS.o` /home/trippe ls/glibc_build/nscd/nscd.o /home/trippels/glibc_build/nscd/connections.o /home/trippels/glibc_build/nscd/pwdcache.o /home/trippels/glibc_build/nscd/getpwnam_r.o /home/trippel s/glibc_build/nscd/getpwuid_r.o /home/trippels/glibc_build/nscd/grpcache.o /home/trippels/glibc_build/nscd/getgrnam_r.o /home/trippels/glibc_build/nscd/getgrgid_r.o /home/tri ppels/glibc_build/nscd/hstcache.o /home/trippels/glibc_build/nscd/gethstbyad_r.o /home/trippels/glibc_build/nscd/gethstbynm3_r.o /home/trippels/glibc_build/nscd/getsrvbynm_r. o /home/trippels/glibc_build/nscd/getsrvbypt_r.o /home/trippels/glibc_build/nscd/servicescache.o /home/trippels/glibc_build/nscd/dbg_log.o /home/trippels/glibc_build/nscd/nsc d_conf.o /home/trippels/glibc_build/nscd/nscd_stat.o /home/trippels/glibc_build/nscd/cache.o /home/trippels/glibc_build/nscd/mem.o /home/trippels/glibc_build/nscd/nscd_setup_ thread.o /home/trippels/glibc_build/nscd/xmalloc.o /home/trippels/glibc_build/nscd/xstrdup.o /home/trippels/glibc_build/nscd/aicache.o /home/trippels/glibc_build/nscd/initgrc ache.o /home/trippels/glibc_build/nscd/gai.o /home/trippels/glibc_build/nscd/res_hconf.o /home/trippels/glibc_build/nscd/netgroupcache.o /home/trippels/glibc_build/nptl/libpt hread_nonshared.a /home/trippels/glibc_build/nptl/libpthread.so /home/trippels/glibc_build/nis/libnsl.so -Wl,-dynamic-linker=/lib64/ld-linux-x86-64.so.2 -Wl,-rpath-link=/hom e/trippels/glibc_build:/home/trippels/glibc_build/math:/home/trippels/glibc_build/elf:/home/trippels/glibc_build/dlfcn:/home/trippels/glibc_build/nss:/home/trippels/glibc_bui ld/nis:/home/trippels/glibc_build/rt:/home/trippels/glibc_build/resolv:/home/trippels/glibc_build/crypt:/home/trippels/glibc_build/nptl /home/trippels/glibc_build/libc.so.6 / home/trippels/glibc_build/libc_nonshared.a -Wl,--as-needed /home/trippels/glibc_build/elf/ld.so -Wl,--no-as-needed -lgcc `/home/trippels/gcc_test/usr/local/bin/gcc --print- file-name=crtendS.o` /home/trippels/glibc_build/csu/crtn.o /home/trippels/bin/ld: /home/trippels/glibc_build/nscd/nscd.o: relocation R_X86_64_PC32 against undefined symbol `program_invocation_name@@GLIBC_2.2.5' can not be used when m aking a shared object; recompile with -fPIC /home/trippels/bin/ld: final link failed: Bad value collect2: error: ld returned 1 exit status make[2]: *** [/home/trippels/glibc_build/nscd/nscd] Error 1 make[2]: Leaving directory `/home/trippels/glibc/nscd' make[1]: *** [nscd/others] Error 2 make[1]: Leaving directory `/home/trippels/glibc' % ld -v GNU ld (GNU Binutils) 2.25.51.20141204 % CC=~/gcc_test/usr/local/bin/gcc CXX=~/gcc_test/usr/local/bin/g++ CFLAGS="-march=native -O2 -pipe" CXXFLAGS="-march=native -O2 -pipe" ../glibc/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --with-headers=/usr/include --enable-add-ons --with-tls --with-__thread --enable-bind-now --without-gd --without-cvs --disable-profile --disable-multi-arch
(In reply to Markus Trippelsdorf from comment #0) > trippels@gcc20 nscd % cat nscd.i > extern int program_invocation_name; > extern void fn2(int, int); > void > fn1() { fn2(0, program_invocation_name); } > > trippels@gcc20 nscd % gcc -shared nscd.i -fpie > /home/trippels/bin/ld: /home/trippels/tmp/ccoI5Lbg.o: relocation > R_X86_64_PC32 against undefined symbol > `program_invocation_name@@GLIBC_2.2.5' can not be used when making a shared > object; recompile with -fPIC > /home/trippels/bin/ld: final link failed: Bad value > collect2: error: ld returned 1 exit status If you use -fpie, you should use -pie. If you use -shared, you should use -fpic.
(In reply to H.J. Lu from comment #3) > (In reply to Markus Trippelsdorf from comment #0) > > trippels@gcc20 nscd % cat nscd.i > > extern int program_invocation_name; > > extern void fn2(int, int); > > void > > fn1() { fn2(0, program_invocation_name); } > > > > trippels@gcc20 nscd % gcc -shared nscd.i -fpie > > /home/trippels/bin/ld: /home/trippels/tmp/ccoI5Lbg.o: relocation > > R_X86_64_PC32 against undefined symbol > > `program_invocation_name@@GLIBC_2.2.5' can not be used when making a shared > > object; recompile with -fPIC > > /home/trippels/bin/ld: final link failed: Bad value > > collect2: error: ld returned 1 exit status > > If you use -fpie, you should use -pie. > If you use -shared, you should use -fpic. -shared was used for demonstration purpose only. Same issue with -pie: % gcc -O2 -pie nscd.i -fPIE /usr/lib/x86_64-linux-gnu/Scrt1.o: In function `_start': (.text+0x20): undefined reference to `main' /home/trippels/bin/ld: /home/trippels/tmp/ccZF5sOU.o: relocation R_X86_64_PC32 against undefined symbol `program_invocation_name@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
(In reply to Markus Trippelsdorf from comment #4) > (In reply to H.J. Lu from comment #3) > > (In reply to Markus Trippelsdorf from comment #0) > > > trippels@gcc20 nscd % cat nscd.i > > > extern int program_invocation_name; > > > extern void fn2(int, int); > > > void > > > fn1() { fn2(0, program_invocation_name); } > > > > > > trippels@gcc20 nscd % gcc -shared nscd.i -fpie > > > /home/trippels/bin/ld: /home/trippels/tmp/ccoI5Lbg.o: relocation > > > R_X86_64_PC32 against undefined symbol > > > `program_invocation_name@@GLIBC_2.2.5' can not be used when making a shared > > > object; recompile with -fPIC > > > /home/trippels/bin/ld: final link failed: Bad value > > > collect2: error: ld returned 1 exit status > > > > If you use -fpie, you should use -pie. > > If you use -shared, you should use -fpic. > > -shared was used for demonstration purpose only. > Same issue with -pie: > > % gcc -O2 -pie nscd.i -fPIE > /usr/lib/x86_64-linux-gnu/Scrt1.o: In function `_start': > (.text+0x20): undefined reference to `main' > /home/trippels/bin/ld: /home/trippels/tmp/ccZF5sOU.o: relocation > R_X86_64_PC32 against undefined symbol > `program_invocation_name@@GLIBC_2.2.5' can not be used when making a shared > object; recompile with -fPIC Does -fuse-ld=gold work?
(In reply to H.J. Lu from comment #5) > (In reply to Markus Trippelsdorf from comment #4) > > (In reply to H.J. Lu from comment #3) > > > (In reply to Markus Trippelsdorf from comment #0) > > > > trippels@gcc20 nscd % cat nscd.i > > > > extern int program_invocation_name; > > > > extern void fn2(int, int); > > > > void > > > > fn1() { fn2(0, program_invocation_name); } > > > > > > > > trippels@gcc20 nscd % gcc -shared nscd.i -fpie > > > > /home/trippels/bin/ld: /home/trippels/tmp/ccoI5Lbg.o: relocation > > > > R_X86_64_PC32 against undefined symbol > > > > `program_invocation_name@@GLIBC_2.2.5' can not be used when making a shared > > > > object; recompile with -fPIC > > > > /home/trippels/bin/ld: final link failed: Bad value > > > > collect2: error: ld returned 1 exit status > > > > > > If you use -fpie, you should use -pie. > > > If you use -shared, you should use -fpic. > > > > -shared was used for demonstration purpose only. > > Same issue with -pie: > > > > % gcc -O2 -pie nscd.i -fPIE > > /usr/lib/x86_64-linux-gnu/Scrt1.o: In function `_start': > > (.text+0x20): undefined reference to `main' > > /home/trippels/bin/ld: /home/trippels/tmp/ccZF5sOU.o: relocation > > R_X86_64_PC32 against undefined symbol > > `program_invocation_name@@GLIBC_2.2.5' can not be used when making a shared > > object; recompile with -fPIC > > Does -fuse-ld=gold work? Yes. I've configured and build gcc with gold. glibc doesn't support gold, so I had to manually switch to ld.bfd. Adding -fuse-ld=gold to the crtn.o link command posted above, also fixes the issue.
> Adding -fuse-ld=gold to the crtn.o link command posted above, also fixes the > issue. It should read: "nscd link command"
(In reply to Markus Trippelsdorf from comment #7) > > Adding -fuse-ld=gold to the crtn.o link command posted above, also fixes the > > issue. > > It should read: "nscd link command" Do you use the same ld to build GCC and glic? If yes, please open a binutils bug and I will fix it next week.
(In reply to H.J. Lu from comment #8) > (In reply to Markus Trippelsdorf from comment #7) > > > Adding -fuse-ld=gold to the crtn.o link command posted above, also fixes the > > > issue. > > > > It should read: "nscd link command" > > Do you use the same ld to build GCC and glic? > If yes, please open a binutils bug and I > will fix it next week. See comment 6.
(In reply to Markus Trippelsdorf from comment #9) > (In reply to H.J. Lu from comment #8) > > (In reply to Markus Trippelsdorf from comment #7) > > > > Adding -fuse-ld=gold to the crtn.o link command posted above, also fixes the > > > > issue. > > > > > > It should read: "nscd link command" > > > > Do you use the same ld to build GCC and glic? > > If yes, please open a binutils bug and I > > will fix it next week. > > See comment 6. Please open a binutils bug and assign it to me. I will fix it next week.
(In reply to H.J. Lu from comment #10) > (In reply to Markus Trippelsdorf from comment #9) > > (In reply to H.J. Lu from comment #8) > > > (In reply to Markus Trippelsdorf from comment #7) > > > > > Adding -fuse-ld=gold to the crtn.o link command posted above, also fixes the > > > > > issue. > > > > > > > > It should read: "nscd link command" > > > > > > Do you use the same ld to build GCC and glic? > > > If yes, please open a binutils bug and I > > > will fix it next week. > > > > See comment 6. > > Please open a binutils bug and assign it > to me. I will fix it next week. OK. Thanks. https://sourceware.org/bugzilla/show_bug.cgi?id=17689
Moved to sourceware bugzilla.
moved.