Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 89922

Summary: binutils:ld - latest stable patch release can cause link failures (cli option dependant)
Product: Gentoo Linux Reporter: Cabal <cabal>
Component: [OLD] DevelopmentAssignee: Gentoo Linux bug wranglers <bug-wranglers>
Status: RESOLVED DUPLICATE    
Severity: normal    
Priority: High    
Version: unspecified   
Hardware: x86   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description Cabal 2005-04-21 06:37:21 UTC
re: binutils-2.15.92.0.2-r7.ebuild

invoking ld via gcc/g++ in the following form:

gcc <compiler options, object files, etc> -shared <libpaths, libs, etc> -Wl,-Bstatic <more libs to be linked statically>

causes the linker to exit with the error:

/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.5-20050130/../../../../i686-pc-linux-gnu/bin/ld: -static and -shared may not be used together

This error should *not* occur. The '-shared' directive indicates that a shared object target is desired and the '-Wl,-Bstatic' option states that libraries following this option on the command line should be linked in statically. 

This is just a guess but some patcher appears to be assuming that '-shared' and '-static' (a synonym for '-Wl,-Bstatic') both refer to the output target. This is not the case and the docs for both gcc and ld bear this out.

Reverting to binutils-2.15.92.0.2-r1.ebuild (the previous currently available stable release) fixes the issue (removes the patch presumably).

From the gcc-3.3.5 docs online at (http://gcc.gnu.org/onlinedocs/gcc-3.3.5/gcc/Link-Options.html#Link-Options)

-static
    On systems that support dynamic linking, this prevents linking with the shared libraries. On other systems, this option has no effect.
-shared
    Produce a shared object which can then be linked with other objects to form an executable. Not all systems support this option. For predictable results, you must also specify the same set of options that were used to generate code (-fpic, -fPIC, or model suboptions) when you specify this option.1 

From the binutils docs online at (http://sourceware.org/binutils/docs-2.15/ld/Options.html#Options)

-Bstatic
-dn
-non_shared
-static
    Do not link against shared libraries. This is only meaningful on platforms for which shared libraries are supported. The different variants of this option are for compatibility with various systems. You may use this option multiple times on the command line: it affects library searching for -l options which follow it. This option also implies --unresolved-symbols=report-all. 

-shared
-Bshareable
    Create a shared library. This is currently only supported on ELF, XCOFF and SunOS platforms. On SunOS, the linker will automatically create a shared library if the -e option is not used and there are undefined symbols in the link. 

Reproducible: Always
Steps to Reproduce:
1.create a dummy.o object file
2.gcc dummy.o -shared -Wl,-Bstatic -lstdc++  
3.watch the error

Actual Results:  
/usr/lib/gcc-lib/i686-pc-linux-gnu/3.3.5-20050130/../../../../i686-pc-linux-gnu/bin/ld:
-static and -shared may not be used together
collect2: ld returned 1 exit status


Expected Results:  
no error output
Comment 1 Jakub Moc (RETIRED) gentoo-dev 2005-04-21 06:39:52 UTC

*** This bug has been marked as a duplicate of 89917 ***