From: Brooks Moses <bmoses@stanford.edu>
To: binutils@sources.redhat.com
Subject: Re: Using "weak externals" with ld on cygwin?
Date: Mon, 17 Apr 2006 12:52:00 -0000 [thread overview]
Message-ID: <44433349.4010005@stanford.edu> (raw)
In-Reply-To: <000001c661d4$ec0e50c0$484861cb@anykey>
Danny Smith wrote:
> 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.
Thanks! Sounds like the best answer to my "How do I do this with dlls?"
question is "Don't; find a workaround instead" -- making my code work
with the LoadLibrary API would probably be as much work as simply fixing
it so I don't need the circularly-referencing dlls, and the latter is a
much more elegant solution.
>>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:
[...]
Should I file a bug report on this, then? If so, where?
Thanks much!
- Brooks
next prev parent reply other threads:[~2006-04-17 6:19 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-04-17 6:19 Danny Smith
2006-04-17 12:52 ` Brooks Moses [this message]
-- strict thread matches above, loose matches on Subject: below --
2006-04-12 8:40 Brooks Moses
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=44433349.4010005@stanford.edu \
--to=bmoses@stanford.edu \
--cc=binutils@sources.redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).