bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug in "-Y" option in GNU ld


From: Joe Weening
Subject: bug in "-Y" option in GNU ld
Date: Thu, 29 Jan 2004 14:29:47 -0800 (PST)

The "-Y" option in GNU ld (version 2.14, Solaris 9 on Intel x86)
behaves differently than in the Solaris linker.  Since this option
exists for Solaris compatibility, this seems like a bug.

In the Solaris linker (/usr/ccs/bin/ld), the order of search for
libraries is:

1. paths specified by -L options
2. LD_LIBRARY_PATH
3. default paths /usr/ccs/lib:/usr/lib

The option "-Y P,path" given to the Solaris linker changes the default
paths (item 3).  But in GNU ld, "-Y P,path" has the effect of placing
path at the end of the -L options (item 1).

GCC calls the linker with "-Y P,/usr/ccs/lib:/usr/lib", which forces
/usr/ccs/lib:/usr/lib to precede LD_LIBRARY_PATH when using GNU ld but
to follow LD_LIBRARY_PATH when using the Solaris linker.

Here's a demonstration.  The following program, foo.c, calls gzopen()
in libz.so:

int main()
{
  gzopen("file", "r");
}

We have two versions of this library:

% ls -lL /usr/lib/libz.so /usr/local/lib/libz.so
-rwxr-xr-x    1 root     bin         56644 2002-03-02 00:08 /usr/lib/libz.so
-rwxr-xr-x    1 root     bin         59384 2004-01-26 13:50 
/usr/local/lib/libz.so

We now compile the program, link with each linker, and see how the
symbol is listed:

% gcc -c foo.c
% echo $LD_LIBRARY_PATH
/usr/local/lib

% /usr/ccs/bin/ld -Y P,/usr/ccs/lib:/usr/lib foo.o -lz
% nm a.out | grep gzopen
         U gzopen

% /usr/local/gnu/bin/ld -V -Y P,/usr/ccs/lib:/usr/lib foo.o -lz
GNU ld version 2.14 20030612
  Supported emulations:
   elf_i386_ldso
   elf_i386
/usr/local/gnu/bin/ld: warning: cannot find entry symbol _start; defaulting to 
08048240
% nm a.out | grep gzopen
         U gzopen@@SUNW_1.1

GNU ld linked the program with Sun's version of libz.so in /usr/lib
instead of the version in /usr/local/lib.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]