public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* Weak symbol for printf/scanf family
       [not found] <021a47e3-b78c-4481-8d9d-b8e746091932@Spark>
@ 2022-04-11  2:50 ` Jojo R
  2022-04-13  5:27   ` Mike Frysinger
  0 siblings, 1 reply; 3+ messages in thread
From: Jojo R @ 2022-04-11  2:50 UTC (permalink / raw)
  To: newlib

Hi,
	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 :)

	Thanks.

— Jojo

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

* Re: Weak symbol for printf/scanf family
  2022-04-11  2:50 ` Weak symbol for printf/scanf family Jojo R
@ 2022-04-13  5:27   ` Mike Frysinger
  2022-04-18  2:32     ` Jojo R
  0 siblings, 1 reply; 3+ messages in thread
From: Mike Frysinger @ 2022-04-13  5:27 UTC (permalink / raw)
  To: Jojo R; +Cc: newlib

[-- Attachment #1: Type: text/plain, Size: 1110 bytes --]

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

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

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

* Re: Weak symbol for printf/scanf family
  2022-04-13  5:27   ` Mike Frysinger
@ 2022-04-18  2:32     ` Jojo R
  0 siblings, 0 replies; 3+ messages in thread
From: Jojo R @ 2022-04-18  2:32 UTC (permalink / raw)
  To: Mike Frysinger; +Cc: newlib

Hi,

	Thanks for your explanation.

	I check the root cause of the 'multiple definition’ issue again,
	the user’s printf symbol would be used first exactly.

	my issue is that there are two printf family symbols in one object,
	and user rewrite the one(vfprintf) of them, and other user function call some
	other Newlib’s function like vprintf, this will create a error of 'multiple definition’.

	I think linker will check this error by whole .o object, so Newlib should write every
	printf/scanf family function in individual object ?

	my test case is following :

a.s
-----------
.section .text.bar
.global bar
bar:
 ret
 .size bar, . - bar

.global foo
.text
.type foo, function
foo:
 call bar
 ret
 .size foo, . - foo
----------
build: ./gas/as -o a.o a.s
AR: ./binutils/as -r liba.a a.o

And the 'main' in b.s will call 'foo', and I want to rewrite function 'bar'
b.s
---------
.global foo
.global bar
.text
bar:
 nop
 nop
 ret
 .size bar, . - bar

.global main
.text
main:
 call foo
 .size main, . - main
----------
build: ./gas/as -o b.o b.s
Link: ./ld/ld-new -o a b.o -L. -la
it will report 'multi define'.

— Jojo
在 2022年4月13日 +0800 PM1:27,Mike Frysinger <vapier@gentoo.org>,写道:
> 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

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

end of thread, other threads:[~2022-04-18  2:32 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <021a47e3-b78c-4481-8d9d-b8e746091932@Spark>
2022-04-11  2:50 ` Weak symbol for printf/scanf family Jojo R
2022-04-13  5:27   ` Mike Frysinger
2022-04-18  2:32     ` Jojo R

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