what does "ld -u symbol" mean?

Nick Clifton nickc@redhat.com
Tue Aug 23 07:57:00 GMT 2005


Hi Kierf,

> hi, what does "ld -u symbol" mean?
> I look at the "ld" menual, it says:
> 
> "Force symbol to be entered in the output file as an undefined
> symbol.Doing this may-for example-trigger linking of additional
> modules from standard libraries."
> 
> who can explain this for me?

[This is a simplified explanation of what is going on.  For a more 
complete explanation I would recommend reading a book about the subject].

When the linker sees a library on the command line it does not 
immediately copy the entire contents of the library into the output 
file.  Instead it looks to see if there are any undefined symbols in the 
  object files that it has already processed and then it checks to see 
if any of these undefined symbols are defined in any of the files inside 
the library.  If they are then the linker copies those files from the 
library to the output file.

So for example suppose that the linker command line looked like this:

   ld main.o -lc

and suppose that the code in main.o calls a function called "printf" but 
that this function is not defined inside main.o.  When the linker sees 
the "-lc" switch it knows that it is should examine the library called 
"libc.a" and look for a file that contains a definition of the symbol 
"printf".  When it finds that file it adds it to the a.out file that it 
is generating.

Now suppose that the linker command line was:

   ld -u strlen main.o -lc

This time the linker will not only pull in the file containing the 
"printf" function from the C library it will also pull in the function 
containing the "strlen" function *even though it is not used by main.o*.

I hope that this makes things clearer.

Cheers
   Nick



More information about the Binutils mailing list