public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* --export-dynamic question
@ 2004-08-31 11:54 Toon Knapen
  2004-08-31 12:07 ` Paul Brook
  2004-08-31 12:09 ` Andreas Schwab
  0 siblings, 2 replies; 3+ messages in thread
From: Toon Knapen @ 2004-08-31 11:54 UTC (permalink / raw)
  To: binutils

I would suspect the symbols defined in the static libraries that I link 
into my executable to appear in the final exe when the --export-dynamic 
option is passed on the command-line. However my findings proove 
otherwise (using redhat 8, ld version 2.13.90.02)

Using following files:

<begin foo.cpp>
int foo()
{ return 99 ; }
<end foo.cpp>

<begin main.cpp>
int main()
{ return 0 ; }
<end main.cpp>

I do:

gcc -c foo.cpp
gcc -c main.cpp
ld main.o foo.o

If I now 'nm a.out', I clearly see the function 'foo' in my a.out.

Now I first put the foo.o object-file into a library and then link the 
library into the exe like so:

ar ru libfoo.a foo.o
ld main.o libfoo.a

Now the function foo does not appear anymore when I 'nm a.out' (as 
expected since it is dead code)

Now however I link a.out using following command-line:

ld --export-dynamic main.o libfoo.a

And the funtion foo does not appear either (although I would expect the 
export-dynamic flag to prevent the dead-code elimination) ?

Thanks in advance,

Toon

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

* Re: --export-dynamic question
  2004-08-31 11:54 --export-dynamic question Toon Knapen
@ 2004-08-31 12:07 ` Paul Brook
  2004-08-31 12:09 ` Andreas Schwab
  1 sibling, 0 replies; 3+ messages in thread
From: Paul Brook @ 2004-08-31 12:07 UTC (permalink / raw)
  To: binutils; +Cc: Toon Knapen

On Tuesday 31 August 2004 12:54, Toon Knapen wrote:
> ar ru libfoo.a foo.o
> ld main.o libfoo.a
>
> Now the function foo does not appear anymore when I 'nm a.out' (as
> expected since it is dead code)
>
> Now however I link a.out using following command-line:
>
> ld --export-dynamic main.o libfoo.a
>
> And the funtion foo does not appear either (although I would expect the
> export-dynamic flag to prevent the dead-code elimination) ?

Try --whole-archive.

Paul

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

* Re: --export-dynamic question
  2004-08-31 11:54 --export-dynamic question Toon Knapen
  2004-08-31 12:07 ` Paul Brook
@ 2004-08-31 12:09 ` Andreas Schwab
  1 sibling, 0 replies; 3+ messages in thread
From: Andreas Schwab @ 2004-08-31 12:09 UTC (permalink / raw)
  To: Toon Knapen; +Cc: binutils

Toon Knapen <toon.knapen@fft.be> writes:

> Now however I link a.out using following command-line:
>
> ld --export-dynamic main.o libfoo.a
>
> And the funtion foo does not appear either (although I would expect the
> export-dynamic flag to prevent the dead-code elimination) ?

--export-dynamic does not change in any way how the linker collects input
files.  Since libfoo.a(foo.o) is not linked in you also don't get any
symbols defined in that file.  If you want to force linking in the whole
archive library use --whole-archive.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux AG, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

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

end of thread, other threads:[~2004-08-31 12:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-08-31 11:54 --export-dynamic question Toon Knapen
2004-08-31 12:07 ` Paul Brook
2004-08-31 12:09 ` Andreas Schwab

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).