public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
From: Jojo R <rjiejie@linux.alibaba.com>
To: Mike Frysinger <vapier@gentoo.org>
Cc: newlib@sourceware.org
Subject: Re: Weak symbol for printf/scanf family
Date: Mon, 18 Apr 2022 10:32:11 +0800	[thread overview]
Message-ID: <219fa77c-20a3-4557-bbaf-d6d938844dcb@Spark> (raw)
In-Reply-To: <YlZfWkdn+u6IK+sv@vapier>

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

      reply	other threads:[~2022-04-18  2:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <021a47e3-b78c-4481-8d9d-b8e746091932@Spark>
2022-04-11  2:50 ` Jojo R
2022-04-13  5:27   ` Mike Frysinger
2022-04-18  2:32     ` Jojo R [this message]

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=219fa77c-20a3-4557-bbaf-d6d938844dcb@Spark \
    --to=rjiejie@linux.alibaba.com \
    --cc=newlib@sourceware.org \
    --cc=vapier@gentoo.org \
    /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).