Bug 13764

Summary: gold doesn't take the LD_RUN_PATH environment variable into account
Product: binutils Reporter: Vincent Lefèvre <vincent-srcware>
Component: goldAssignee: Ian Lance Taylor <ian>
Status: NEW ---    
Severity: normal CC: abc.mikey, ccoutant, maxim.yegorushkin, sam
Priority: P2    
Version: 2.22   
Target Milestone: ---   
Host: Target:
Build: Last reconfirmed:
Attachments: patch to take he LD_RUN_PATH environment variable into account

Description Vincent Lefèvre 2012-02-27 14:28:05 UTC
Created attachment 6251 [details]
patch to take he LD_RUN_PATH environment variable into account

Contrary to the conventional linker, gold doesn't take the LD_RUN_PATH environment variable into account (default runpath). I've reported a bug against Debian here:

  http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=660813

and Jonathan Nieder posted a patch, which I've tested and solves the problem I've reported. It is attached.

The ld(1) man page should also mention it. The old ld(1) man page says:
* For -rpath=dir: If -rpath is not used when linking an ELF executable, the contents of the environment variable "LD_RUN_PATH" will be used if it is defined.
* For -rpath-link=dir: On an ELF system, for native linkers, if the -rpath and -rpath-link options were not used, search the contents of the environment variable "LD_RUN_PATH".
But it could be better to describe it in an ENVIRONMENT section, where environment variables are usually described.
Comment 1 Maxim Egorushkin 2012-04-26 23:57:51 UTC
I applied the patch to binutils-2.22 to build gcc-4.7.0 using gold linker and a non-standard $PREFIX. It worked for me. Thanks for the patch.
Comment 2 Vincent Lefèvre 2013-07-27 12:14:00 UTC
The bug is still present in binutils 2.23.52.20130722 (Debian). It can be reproduced by compiling MPFR with the --with-gmp configure option. For instance:

./configure --with-gmp=/usr/local/gmp-debug CFLAGS='-fuse-ld=gold'

(/usr/local/gmp-debug being a version different from the /usr one). I got:

checking if gmp.h version and libgmp version are the same... (5.0.1/5.1.2) no
configure: WARNING: ==========================================================
configure: WARNING: 'gmp.h' and 'libgmp' seem to have different versions or
configure: WARNING: we cannot run a program linked with GMP (if you cannot
configure: WARNING: see the version numbers above). A cause may be different
configure: WARNING: GMP versions with different ABI's or the use of --with-gmp
configure: WARNING: or --with-gmp-include with a system include directory
configure: WARNING: (such as /usr/include or /usr/local/include).
configure: WARNING: However since we can't use 'libtool' inside the configure,
configure: WARNING: we can't be sure. See 'config.log' for details.
configure: WARNING: CC="gcc"
configure: WARNING: CFLAGS="-fuse-ld=gold"
configure: WARNING: CPPFLAGS=" -I/usr/local/gmp-debug/include"
configure: WARNING: LDFLAGS=" -L/usr/local/gmp-debug/lib"
configure: WARNING: LIBS="-lgmp "
configure: WARNING: Temporary LD_RUN_PATH was "/usr/local/gmp-debug/lib".
configure: WARNING: ==========================================================
Comment 3 Maxim Egorushkin 2013-07-27 12:37:08 UTC
Shouldn't it be LDFLAGS='-fuse-ld=gold'?
Comment 4 Vincent Lefèvre 2013-07-27 13:26:05 UTC
(In reply to Maxim Yegorushkin from comment #3)
> Shouldn't it be LDFLAGS='-fuse-ld=gold'?

It may work, but using CFLAGS is better (this is specific to MPFR and to the way GMP builds work).

Moreover, in the gcc man page, -fuse-ld is listed under "Optimization Options", not "Linker Options".
Comment 5 Maxim Egorushkin 2013-07-27 13:29:05 UTC
(In reply to Vincent Lefèvre from comment #4)
> (In reply to Maxim Yegorushkin from comment #3)
> > Shouldn't it be LDFLAGS='-fuse-ld=gold'?
> 
> It may work, but using CFLAGS is better (this is specific to MPFR and to the
> way GMP builds work).

Is not whatever works it better? Not trolling.
Comment 6 Jackie Rosen 2014-02-16 17:47:18 UTC Comment hidden (spam)
Comment 7 Michael Green 2019-07-31 14:45:26 UTC
This is *still* an issue in 2.32!

The patch does work but needs applying by hand.
Comment 8 Vincent Lefèvre 2022-07-06 11:44:22 UTC
Still reproducible with the binutils 2.38.50.20220629-4 Debian package.