std library hooks

"Jérôme M. Berger" jeberger at free.fr
Sun Apr 15 03:43:23 PDT 2012


Manu wrote:
> How does weak linkage fit into this? If it finds a weak symbol while
> scanning for an unresolved symbol, will it then continue scanning when
> it finds the weak symbol, just in case there may be another strong one
> in there somewhere?
> 
	The way I understand it, there are two meanings for weak symbols
depending on whether it is applied to the object file where the
symbol is used or the object file where it is defined:

- When using the symbol, "weak" means: "I don't mind if the symbol
is not found". It may then get resolved later (for example by
loading a DLL manually) or never (in which case attempting to use it
will result in a NULL pointer dereference).

- When defining the symbol, "weak" means: "This may be overridden by
a later "strong" symbol". So if the linker finds the weak definition
it will tentatively use that definition, but if it later finds a
strong definition, then it will silently use the strong symbol.

> But basically, in order to override druntime implementations of
> functions in the way walter suggests, I need to carefully craft my
> linker commend line, and it should be work as he says? (not clear
> whether I should link the libs at the start or the end of the command line)
> Perhaps it would be safer to use weak linkage for those functions in
> druntime that one may want to override, and then document the
> possibility? .. It feels somewhat like an exploit otherwise :)

	Normally, druntime is automatically linked last. Therefore, you do
not need to do anything special: simply define the symbol yourself
and compile/link as usual. Your symbol should be used in preference
to druntime's.

		Jerome
-- 
mailto:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20120415/d11b6d76/attachment.pgp>


More information about the Digitalmars-d mailing list