Many configure scripts e.g. GLIBC use -print-prog-name to check the binary utils used by GCC. Distros may face need to switch linker between bfd and gold, which is now possible thanks to -fuse-ld flag. However, -print-prog-name is not affected by -fuse-ld, and thus may lead to configure checks and actual build being performed using different linkers. $ kernelgen-gcc -fuse-ld=gold -print-prog-name=ld /home/marcusmae/rpmbuild/kernelgen/head_llvm192445_i686-linux-gnu_x86_64-linux-gnu_debug/INSTALL/bin/kernelgen-ld $ kernelgen-gcc -fuse-ld=bfd -print-prog-name=ld /home/marcusmae/rpmbuild/kernelgen/head_llvm192445_i686-linux-gnu_x86_64-linux-gnu_debug/INSTALL/bin/kernelgen-ld I think -fuse-ld should play together with -print-prog-name. In the example above with default gold, second command should point to kernelgen-ld.bfd
-print-prog-name=foobar gives the path name of program, foobar. which isn't necessarily used by the GCC driver: [hjl@gnu-6 gcc-4.6.3-x32]$ ./bin/gcc -print-prog-name=as as [hjl@gnu-6 gcc-4.6.3-x32]$ ./bin/gcc -print-prog-name=foobar foobar Should we consider -print-prog-name=ld as special case?
The driver doesn't actually call ld, but collect2, and passes -fuse-ld down to it.
I'm only saying configure scripts use -print-prog-name to determine the linker, and with introduction of -fuse-ld what's returned there could be inconsistent with what linker is actually being used.
(In reply to H.J. Lu from comment #1) > -print-prog-name=foobar gives the path name of program, foobar. > which isn't necessarily used by the GCC driver: > > [hjl@gnu-6 gcc-4.6.3-x32]$ ./bin/gcc -print-prog-name=as > as > [hjl@gnu-6 gcc-4.6.3-x32]$ ./bin/gcc -print-prog-name=foobar > foobar This is only the result if a full path cannot be determined. > gcc -print-prog-name=as /usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/bin/as > Should we consider -print-prog-name=ld as special case? Not really, -print-prog-name prints the command gcc uses if it were to use that command. It won't use 'ld' but 'ld.gold' with -fuse-ld=gold so -print-prog-name=ld is simply not the correct way to determine which linker GCC ultimately would use. Thus you'd want a -print-linker-name.
Created attachment 31333 [details] A patch This patch teaches gcc.c to append .bfd/.gold to ld if -fuse-ld=XXX is used for --print-prog-name=ld.
We can handle -fuse-ld=XXX for -print-prog-name=ld.
I got [hjl@gnu-tools-1 gcc-4.9.0]$ ./bin/gcc -print-prog-name=ld -fuse-ld=bfd /export/build/gnu/gcc/release/usr/gcc-4.9.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../x86_64-unknown-linux-gnu/bin/ld.bfd [hjl@gnu-tools-1 gcc-4.9.0]$ ./bin/gcc -print-prog-name=ld -fuse-ld=gold /export/build/gnu/gcc/release/usr/gcc-4.9.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../x86_64-unknown-linux-gnu/bin/ld.gold [hjl@gnu-tools-1 gcc-4.9.0]$ ./bin/gcc -print-prog-name=ld /export/build/gnu/gcc/release/usr/gcc-4.9.0/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.9.0/../../../../x86_64-unknown-linux-gnu/bin/ld [hjl@gnu-tools-1 gcc-4.9.0]$
Dear H.J. Lu, You patch works for me, thanks a lot! I noticed however, that with -fuse-ld ld from the different location is used for me: $ kernelgen-gcc -print-prog-name=ld .../INSTALL/bin/kernelgen-ld $ kernelgen-gcc -fuse-ld=bfd -print-prog-name=ld .../INSTALL/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.3/../../../../x86_64-unknown-linux-gnu/bin/ld.bfd $ kernelgen-gcc -fuse-ld=gold -print-prog-name=ld .../INSTALL/bin/../lib/gcc/x86_64-unknown-linux-gnu/4.8.3/../../../../x86_64-unknown-linux-gnu/bin/ld.gold I think the patch should first check if newname concatted with suffix exists, or somehow else deal with possibly prefixed-ld names.
This is not what I see with GCC 4.9.0: [hjl@gnu-tools-1 tools-4.9]$ ls release/usr/gcc-4.9.0/bin/ x86_64-linux-addr2line x86_64-linux-gcc x86_64-linux-ld.gold x86_64-linux-ar x86_64-linux-gcc-4.9.0 x86_64-linux-nm x86_64-linux-as x86_64-linux-gcc-ar x86_64-linux-objcopy x86_64-linux-c++ x86_64-linux-gcc-nm x86_64-linux-objdump x86_64-linux-c++filt x86_64-linux-gcc-ranlib x86_64-linux-ranlib x86_64-linux-cpp x86_64-linux-gcov x86_64-linux-readelf x86_64-linux-dwp x86_64-linux-gprof x86_64-linux-size x86_64-linux-elfedit x86_64-linux-ld x86_64-linux-strings x86_64-linux-g++ x86_64-linux-ld.bfd x86_64-linux-strip [hjl@gnu-tools-1 tools-4.9]$ release/usr/gcc-4.9.0/bin/x86_64-linux-gcc -print-prog-name=ld /export/build/gnu/tools-4.9/release/usr/gcc-4.9.0/bin/../lib/gcc/x86_64-linux/4.9.0/../../../../x86_64-linux/bin/ld [hjl@gnu-tools-1 tools-4.9]$
Right, I guess the reason of the difference is I'm configured with --program-prefix=kernelgen- --with-ld=$RPM_INSTALL_PREFIX/%{prefix}bin/kernelgen-ld --with-as=$RPM_INSTALL_PREFIX/%{prefix}bin/kernelgen-as In this case I expect -print-prog-name to add .gold/.bfd suffix to my --with-ld setting, rather than to .../x86_64-unknown-linux-gnu/bin/ld
Created attachment 31335 [details] An updated patch Please try this.
Created attachment 31336 [details] A patch with collect2 fix This patch also fixes collect2 when --program-prefix= is used to configure GCC.
When --program-prefix= is used to configure GCC, -fuse-ld doesn't work since DEFAULT_LINKER is defined. Patch in comment 12 also fixes collect2.
(In reply to H.J. Lu from comment #13) > When --program-prefix= is used to configure GCC, -fuse-ld > doesn't work since DEFAULT_LINKER is defined. Patch in > comment 12 also fixes collect2. The problem is GCC configured with --with-ld=, which sets DEFAULT_LINKER.
Created attachment 31338 [details] A patch with collect2 and HOST_EXECUTABLE_SUFFIX fixes This patch handles collect2 and HOST_EXECUTABLE_SUFFIX. But HOST_EXECUTABLE_SUFFIX is untested.
Created attachment 31341 [details] A patch with ChangeLog Add ChangeLog.
Works as a charm! Many thanks! $ manual-gcc -print-prog-name=ld /media/scratch/manual/binutils-2.24.51/build32_glibc/install/bin/manual-ld $ manual-gcc -fuse-ld=bfd -print-prog-name=ld /media/scratch/manual/binutils-2.24.51/build32_glibc/install/bin/manual-ld.bfd $ manual-gcc -fuse-ld=gold -print-prog-name=ld /media/scratch/manual/binutils-2.24.51/build32_glibc/install/bin/manual-ld.gold
A patch is posted at http://gcc.gnu.org/ml/gcc-patches/2013-12/msg00061.html
Author: hjl Date: Thu Dec 19 18:11:42 2013 New Revision: 206129 URL: http://gcc.gnu.org/viewcvs?rev=206129&root=gcc&view=rev Log: Improve -fuse-ld=[bfd|gold] check PR driver/59321 * collect2.c (main): Check -fuse-ld=[bfd|gold] when DEFAULT_LINKER is defined. * common.opt (fuse-ld=bfd): Add Driver. (fuse-ld=gold): Likewise. * gcc.c (use_ld): New variable. (driver_handle_option): Set use_ld for OPT_fuse_ld_bfd and OPT_fuse_ld_gold. (main): Check -fuse-ld=[bfd|gold] for -print-prog-name=ld. Modified: trunk/gcc/ChangeLog trunk/gcc/collect2.c trunk/gcc/common.opt trunk/gcc/gcc.c
Fixed.