This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
Brooks Moses <bmoses at stanford dot edu> wrote on: Tue, 11 Apr 2006 23:34:14 -0700[...]My understanding of this is that I should be able to create a libA.dll file with some code in it that references a function foo(), and define foo() as a weak symbol aliased to bar() such that, if an executable defines its own foo() or links to another dll that defines it, the libA code will use that definition of foo(), but otherwise it will use bar(). Is that actually a correct understanding? Or am I missing something somewhere?
weak symbols do not work as expected with PE DLL's. DLL's do not allow undefined symbols when they are linked together. DLLs are executables with their own startup entry point, their own main, their own at_exit table, etc. Hence a DLL built from this:
Weak extern synbols work fine in PE with static objects and archives, but I don't know how to do exactly what you want with dll's. Using LoadLibrary/GetProcAddress API might work for you.
[...]I've been trying, with a copy of the release version of gcc 4.1.0 and
the latest Cygwin version of ld (which reports GNU ld version 2.16.91
20050610 as its version), to write some code that will do that.
Everything I try seems to either give me an error like "Cannot export
.weak.__Z3foov.__Z3barv: symbol not found" or else always uses bar()
regardless of whether I supply a foo() elsewhere.
Exporting .weak._foo._bar in the above is an ld error. I think this
kind of
'.'-concatted names get interpreted as a forward export, eg the loader
will look
for a symbol 'weak' in another dll module with the unsual name
'_foo._bar'. This can be fixed easily enough by adding ".weak." to the list of
prefixes that
exclude symbols from automatic export, like so:
Thanks much! - Brooks
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |