public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* cannot undefine with -u option to ld
@ 2001-09-14  9:17 first last
  2001-09-17  8:06 ` Nick Clifton
  0 siblings, 1 reply; 4+ messages in thread
From: first last @ 2001-09-14  9:17 UTC (permalink / raw)
  To: binutils

I am trying to use the -u option of ld to force a
symbol to be undefined in order to have the
linker pull a module out of a library which it
otherwise would not.

The feature does no work consistantly.  If i use
"-u __gccmain", libraries are searched and a
module is extracted which defines the symbol. 
For every other symbol I tried, no library module
is extracted, nor does it appear a library search
is being performed (--verbose).  

The most mysterious part is that the symbol is
inserted into the symbol table from the linker
and it is labelled UND in the Ndx column of the
table.  I assume that means the symbol is
undefined.  But the linker completes with no
error and no resolution of the symbol.

________________________________________
Get your email at 
http://www.prontomail.com 

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: cannot undefine with -u option to ld
  2001-09-14  9:17 cannot undefine with -u option to ld first last
@ 2001-09-17  8:06 ` Nick Clifton
  0 siblings, 0 replies; 4+ messages in thread
From: Nick Clifton @ 2001-09-17  8:06 UTC (permalink / raw)
  To: first last; +Cc: binutils

Hi,

> The feature does no work consistantly.  If i use
> "-u __gccmain", libraries are searched and a
> module is extracted which defines the symbol. 
> For every other symbol I tried, no library module
> is extracted, nor does it appear a library search
> is being performed (--verbose).  

We really need more information in order to be able to debug this
problem properly.  In particular - which version of ld are you using ?
For which target ?  How was it configured ?  What is the command line
you are using ?

One possible explanation for the behaviour you are seeing is that the
symbols you want to pull in from the libraries are prefixed with an
extra underscore, which you do not normally see.  (This is quite
common behaviour for certain targets).  So, for example if you are
adding '-u foo' to the command line and the symbol "foo" is not being
included in the link, then try using "-u _foo" instead.

Cheers
        Nick

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: cannot undefine with -u option to ld
  2001-09-17 19:22 first last
@ 2001-09-18  2:53 ` Nick Clifton
  0 siblings, 0 replies; 4+ messages in thread
From: Nick Clifton @ 2001-09-18  2:53 UTC (permalink / raw)
  To: first last; +Cc: binutils, bug-binutils

Hi,

> It appears that when "-u" is used, ld will
> attempt to define the symbol in the usual way
> (library searches, etc), but , if it cannot, it
> fails silently.  It inserts the symbol in the
> symbol table, annotates it with UND (to indicate
> that it is undefined), but then completes without
> indicating a warning or an error.

This is actually the accepted behaviour and probably should not be
changed.  (There can be quite a few undefined symbol references even
in a fully resolved link).

If you need to force a symbol to be resolved, simply place it into an
object file and then include it on the link command line.  eg to force
a reference to "foo":

  % cat foo.c
  int foo_ref asm ("foo");

  % gcc -c foo.c

  % gcc myprog.o foo.o


Cheers
        Nick

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: cannot undefine with -u option to ld
@ 2001-09-17 19:22 first last
  2001-09-18  2:53 ` Nick Clifton
  0 siblings, 1 reply; 4+ messages in thread
From: first last @ 2001-09-17 19:22 UTC (permalink / raw)
  To: nickc; +Cc: binutils, bug-binutils

I have resolved my immediate problem, but the
larger issue of "silent failure" should probably
be addressed.

Silent Failure ---
It appears that when "-u" is used, ld will
attempt to define the symbol in the usual way
(library searches, etc), but , if it cannot, it
fails silently.  It inserts the symbol in the
symbol table, annotates it with UND (to indicate
that it is undefined), but then completes without
indicating a warning or an error.

How I Fixed Things ---
In my case, I do not remember exactly how I fixed
the problem, but it was definitely caused by 
operator error.  Possibly the symbol was spelled
differently on the ld command line than in the
module where it was defined.  Possibly the
library search order was incorrect.  Once all the
ducks were lined up, "ld -u" worked. 
Unfortunately the silent failure of "-u"
misdirected me for several days.

In my first email, I reported that "-u" worked
for __gccmain but for no other symbol that I
tried.  This was a red herring.  "-u" failed with
__gccmain just as well.  However,__gccmain became
defined later in the link process for other
reasons, unrelated to "-u".  This lead me to
believe that "-u" worked for this one symbol but
for no others.

Recommendation ---
I would like to recommend that ld be modified to
end with an error (or at least a noticeable
warning) when a symbol is undefined with "-u" and
ld never resolves the problem.

(For reference, this thread started in
binutils@sources.redhat.com.)

________________________________________
Get your email at 
http://www.prontomail.com 

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-09-18  2:53 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2001-09-14  9:17 cannot undefine with -u option to ld first last
2001-09-17  8:06 ` Nick Clifton
2001-09-17 19:22 first last
2001-09-18  2:53 ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).