Bug 64237 - [5 Regression] glibc build failure
Summary: [5 Regression] glibc build failure
Status: RESOLVED MOVED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 5.0
: P1 normal
Target Milestone: 5.0
Assignee: Not yet assigned to anyone
URL: https://sourceware.org/bugzilla/show_...
Keywords:
Depends on:
Blocks:
 
Reported: 2014-12-09 12:25 UTC by Markus Trippelsdorf
Modified: 2014-12-09 15:29 UTC (History)
1 user (show)

See Also:
Host:
Target: x86_64-*-*, i?86-*-*
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Trippelsdorf 2014-12-09 12:25:09 UTC
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
Comment 1 Richard Biener 2014-12-09 12:33:44 UTC
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.
?
Comment 2 Markus Trippelsdorf 2014-12-09 12:36:38 UTC
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
Comment 3 H.J. Lu 2014-12-09 14:27:59 UTC
(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.
Comment 4 Markus Trippelsdorf 2014-12-09 14:36:51 UTC
(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
Comment 5 H.J. Lu 2014-12-09 14:41:52 UTC
(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?
Comment 6 Markus Trippelsdorf 2014-12-09 14:49:01 UTC
(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.
Comment 7 Markus Trippelsdorf 2014-12-09 14:53:16 UTC
> Adding -fuse-ld=gold to the crtn.o link command posted above, also fixes the
> issue.

It should read: "nscd link command"
Comment 8 H.J. Lu 2014-12-09 15:01:42 UTC
(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.
Comment 9 Markus Trippelsdorf 2014-12-09 15:06:15 UTC
(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.
Comment 10 H.J. Lu 2014-12-09 15:12:53 UTC
(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.
Comment 11 Markus Trippelsdorf 2014-12-09 15:22:58 UTC
(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
Comment 12 Markus Trippelsdorf 2014-12-09 15:28:49 UTC
Moved to sourceware bugzilla.
Comment 13 Markus Trippelsdorf 2014-12-09 15:29:07 UTC
moved.