public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Force symbol inclusion in .a library
@ 2007-10-16 19:05 Dave W
  2007-10-16 23:08 ` Daniel Jacobowitz
  0 siblings, 1 reply; 2+ messages in thread
From: Dave W @ 2007-10-16 19:05 UTC (permalink / raw)
  To: binutils

My buddy is porting some code from windows to linux, and he asked me this
ar question that I couldn't answer.  Does anyone have any ideas?

Quoth my friend:
I have two 'libraries' XModule.o and XLoader.o.

XModule.o gets linked into the modules and provides a
function: extern "C" GlueFunctionThatPutsMagicPointer(void
*) { blah... }

Then when a module gets loaded the client ends up doing:
pLib = dlopen("libWhateverModule.so"); pFunc = dlsym(pLib,
"GlueFunctionThatPutsMagicPointer"); (*pFunc)(pointer);

You can see in Makefile.XModule that I stick (cp) XModule.o
into the libs directory and then when modules link (see
Makefile.IXFrameBuffer) I include XModule.o on the link
line directly.  It works fine, but what I want is to create
a static library in Makefile.XModule as follows: ar crs
libXModule.a XModule.o

which works, but when libXModule.a is linked in with a
module shared lib, the module shared lib doesn't get the
symbol GlueFunctionThatPutsMagicPointer, because it is not
statically referenced by the module itself.  So I just link
the module against the .o file to make sure the symbol is
in there.  That is ok, but I kind of wanted it to be a .a
not a .o.  Not critical but if you know how to force the
symbol in - thought I'd ask.

Works in windows because on windows the function is
declared extern "C" _declspec(dllexport) Glue(void *);
which forces the linker to include the symbol because it is
marked for dll exporting.


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

* Re: Force symbol inclusion in .a library
  2007-10-16 19:05 Force symbol inclusion in .a library Dave W
@ 2007-10-16 23:08 ` Daniel Jacobowitz
  0 siblings, 0 replies; 2+ messages in thread
From: Daniel Jacobowitz @ 2007-10-16 23:08 UTC (permalink / raw)
  To: binutils

On Tue, Oct 16, 2007 at 06:13:29PM +0000, Dave W wrote:
> Works in windows because on windows the function is
> declared extern "C" _declspec(dllexport) Glue(void *);
> which forces the linker to include the symbol because it is
> marked for dll exporting.

Your choices are --whole-archive and "-u Glue".  There's no way you
can mark the symbol.

-- 
Daniel Jacobowitz
CodeSourcery

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

end of thread, other threads:[~2007-10-16 20:36 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-10-16 19:05 Force symbol inclusion in .a library Dave W
2007-10-16 23:08 ` Daniel Jacobowitz

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