Bug 59321 - -fuse-ld has no effect on -print-prog-name nor on --with-ld=
Summary: -fuse-ld has no effect on -print-prog-name nor on --with-ld=
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: driver (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 4.9.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-27 21:43 UTC by maemarcus
Modified: 2013-12-19 18:12 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-11-29 00:00:00


Attachments
A patch (586 bytes, patch)
2013-11-29 21:01 UTC, H.J. Lu
Details | Diff
An updated patch (845 bytes, patch)
2013-11-30 02:34 UTC, H.J. Lu
Details | Diff
A patch with collect2 fix (895 bytes, patch)
2013-11-30 05:43 UTC, H.J. Lu
Details | Diff
A patch with collect2 and HOST_EXECUTABLE_SUFFIX fixes (1.15 KB, patch)
2013-11-30 13:53 UTC, H.J. Lu
Details | Diff
A patch with ChangeLog (1.29 KB, patch)
2013-11-30 14:37 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description maemarcus 2013-11-27 21:43:49 UTC
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
Comment 1 H.J. Lu 2013-11-27 23:25:24 UTC
-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?
Comment 2 Andreas Schwab 2013-11-28 08:32:44 UTC
The driver doesn't actually call ld, but collect2, and passes -fuse-ld down to it.
Comment 3 maemarcus 2013-11-28 09:02:37 UTC
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.
Comment 4 Richard Biener 2013-11-28 11:31:21 UTC
(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.
Comment 5 H.J. Lu 2013-11-29 21:01:18 UTC
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.
Comment 6 H.J. Lu 2013-11-29 21:02:19 UTC
We can handle -fuse-ld=XXX for -print-prog-name=ld.
Comment 7 H.J. Lu 2013-11-29 21:10:25 UTC
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]$
Comment 8 maemarcus 2013-11-29 23:04:48 UTC
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.
Comment 9 H.J. Lu 2013-11-30 00:47:20 UTC
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]$
Comment 10 maemarcus 2013-11-30 00:58:10 UTC
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
Comment 11 H.J. Lu 2013-11-30 02:34:08 UTC
Created attachment 31335 [details]
An updated patch

Please try this.
Comment 12 H.J. Lu 2013-11-30 05:43:26 UTC
Created attachment 31336 [details]
A patch with collect2 fix

This patch also fixes collect2 when --program-prefix= is used
to configure GCC.
Comment 13 H.J. Lu 2013-11-30 05:46:26 UTC
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.
Comment 14 H.J. Lu 2013-11-30 13:51:50 UTC
(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.
Comment 15 H.J. Lu 2013-11-30 13:53:17 UTC
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.
Comment 16 H.J. Lu 2013-11-30 14:37:49 UTC
Created attachment 31341 [details]
A patch with ChangeLog

Add ChangeLog.
Comment 17 maemarcus 2013-12-02 11:52:42 UTC
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
Comment 18 H.J. Lu 2013-12-02 12:50:30 UTC
A patch is posted at

http://gcc.gnu.org/ml/gcc-patches/2013-12/msg00061.html
Comment 19 hjl@gcc.gnu.org 2013-12-19 18:11:44 UTC
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
Comment 20 H.J. Lu 2013-12-19 18:12:29 UTC
Fixed.