Bug 17001 - Linker option -Wl,foo,bar causes the driver to behave unintuitively for no input files
Summary: Linker option -Wl,foo,bar causes the driver to behave unintuitively for no in...
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: driver (show other bugs)
Version: 4.0.0
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: documentation
Depends on:
Blocks:
 
Reported: 2004-08-12 13:34 UTC by Ranjit Mathew
Modified: 2005-07-23 22:39 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Known to work:
Known to fail:
Last reconfirmed: 2005-05-15 01:03:49


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ranjit Mathew 2004-08-12 13:34:45 UTC
The GCC driver allows linker options to be passed using the "-Wl," flag.

However, the way it is implemented results in an unintuitive behaviour 
when no input files are present - the normal "no input files" message
is suppressed and the linker is invoked directly causing a link failure.
(I am seeing this behaviour in a few 3.x releases and not just the
3.5 mainline.)

As I understand it (from a reading of the manual), these options
are passed to the linker *when* it is invoked - when I specify no 
input files, the linker should *not* be invoked.

Witness:
----------------------------------- 8< -----------------------------------
    ~ > $MYGCJ
    gcj: no input files

    ~ > $MYGCJ -Wl,-rpath,/usr/local/lib
    /usr/lib/crt1.o(.text+0x18): In function `_start':
    : undefined reference to `main'
    collect2: ld returned 1 exit status
----------------------------------- 8< -----------------------------------

"Business Case":
----------------
I just build the mainline GCC without installing it.
To use, say, GCJ in such a situation, I define an alias like:

alias mygcj="$BUILD/gcc/gcj -B$BUILD/gcc/
-B/home/ranmath/src/gcc/build/i686-pc-linux-gnu/libjava/
-I$BUILD/i686-pc-linux-gnu/libjava/libgcj-3.5.0.jar
-L$BUILD/i686-pc-linux-gnu/libjava/.libs"

(where $BUILD is the folder where I built GCC)

So I can compile a normal Java program like:

  mygcj --main=Hello Hello.java

However, the resulting binary needs the libgcj.so from
the build folder, so I can either use LD_LIBRARY_PATH
or use -rpath on the command line.

To save myself the trouble, I wanted to put:

  -Wl,-rpath,$BUILD/i686-pc-linux-gnu/libjava/.libs

also in the above command line, but it causes the
compiler to behave weirdly (as noted above) when I
just say:

  mygcj

The same problem is also present for a similarly 
defined alias for g++ (of course, since the driver
is the same).
Comment 1 Andrew Pinski 2004-08-12 14:49:09 UTC
Hmm, I don't know, see <http://gcc.gnu.org/ml/gcc-patches/2004-08/msg00344.html> which it was 
done for g++ on purpose to change it so it would do the link and add -lstdc++ like it should.

It seems like once you say to pass to linker all bets are off in terms of not getting the linker invoked.

Confirmed, this just needs to be documented it seems.