Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 89917 - binutils:ld - latest stable patch release can cause link failures (cli option dependant)
Summary: binutils:ld - latest stable patch release can cause link failures (cli option...
Status: RESOLVED INVALID
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] Development (show other bugs)
Hardware: x86 Linux
: High normal (vote)
Assignee: Gentoo Toolchain Maintainers
URL:
Whiteboard:
Keywords:
: 89920 89922 (view as bug list)
Depends on:
Blocks:
 
Reported: 2005-04-21 05:48 UTC by Cabal
Modified: 2005-04-22 05:35 UTC (History)
0 users

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cabal 2005-04-21 05:48:37 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:18:58 UTC
*** Bug 89920 has been marked as a duplicate of this bug. ***
Comment 2 Jakub Moc (RETIRED) gentoo-dev 2005-04-21 06:39:52 UTC
*** Bug 89922 has been marked as a duplicate of this bug. ***
Comment 3 Cabal 2005-04-21 07:58:43 UTC
Apologies for that - I'll take more care refreshing the correct browser window next time.
Comment 4 SpanKY gentoo-dev 2005-04-22 05:35:47 UTC
if the last arg is -Wl,-Bstatic then the linker will assume the final binary is supposed to be static which conflicts with the request to build a -shared binary

if you want to statically link in just some libs, then you need to declare when you're done linking static libs:
gcc -shared <source code> -Wl,-Bstatic -lncurses -Wl,-Bdynamic -lreadline
this will link ncurses statically but link readline dynamically