Weak symbol for printf/scanf family
Mike Frysinger
vapier@gentoo.org
Wed Apr 13 05:27:54 GMT 2022
On 11 Apr 2022 10:50, Jojo R wrote:
> Dose anyone know why libc dose not use WEAK attribution for
> some symbols like printf/scanf family ?
>
> Some developers want to reimplement sub sets of them maybe :)
weak symbols in static libs is generally a recipe for doom. the linker won't
pull in objects from an archive unless there's a strong symbol pulling it in
which means weak refs effectively never get satisfied. this is mitigated by
using --whole-archive, but that defeats the point of using a static lib with
newlib in the first place.
backing up a bit, newlib uses static linking, which means if your program
provided the printf symbol, either directly or in an object listed before
the -lc linkage, your printf symbol would be used first, and newlib's own
printf would not be pulled in. if you're still seeing newlib's printf
being pulled in (and presumably causing duplicate symbol linker errors),
then something else is going on, and weak symbols wouldn't help.
but it's hard to say without a concrete example of what you're trying to
do and how it isn't working.
-mike
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20220413/7ad0ddca/attachment.sig>
More information about the Newlib
mailing list