public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "Fāng-ruì Sòng" <maskray@google.com>
To: GNU C Library <libc-alpha@sourceware.org>
Cc: Florian Weimer <fw@deneb.enyo.de>
Subject: Re: [PATCH] elf: Replace a --defsym trick with an object file to be compatible with lld
Date: Mon, 31 Aug 2020 16:21:01 -0700	[thread overview]
Message-ID: <CAFP8O3LnyQcUK7pD91edB5g6Z7n+tRbNE2pSWJowTR06UCDTBQ@mail.gmail.com> (raw)
In-Reply-To: <20200411221646.185882-1-maskray@google.com>

On Sat, Apr 11, 2020 at 3:16 PM Fangrui Song <maskray@google.com> wrote:
>
> The existing code specifies -Wl,--defsym=malloc=0 and other malloc.os
> definitions before libc_pic.a so that libc_pic.a(malloc.os) is not
> fetched. This trick is used to avoid multiple definition errors which
> would happen as a chain result:
>
>   dl-allobjs.os has an undefined __libc_scratch_buffer_set_array_size
>   __libc_scratch_buffer_set_array_size fetches libc_pic.a(scratch_buffer_set_array_size.os)
>   libc_pic.a(scratch_buffer_set_array_size.os) has an undefined free
>   free fetches libc_pic.a(malloc.os)
>   libc_pic.a(malloc.os) has an undefined __libc_message
>   __libc_message fetches libc_pic.a(libc_fatal.os)
>
>   libc_fatal.os will cause a multiple definition error (__GI___libc_fatal)
>   >>> defined at dl-fxstatat64.c
>   >>>            /tmp/p/glibc/Release/elf/dl-allobjs.os:(__GI___libc_fatal)
>   >>> defined at libc_fatal.c
>   >>>            libc_fatal.os:(.text+0x240) in archive /tmp/p/glibc/Release/libc_pic.a
>
> lld processes --defsym after all input files, so this trick does not
> suppress multiple definition errors with lld. Split the step into two
> and use an object file to make the intention more obvious and make lld
> work.
>
> This is conceptually more appropriate because --defsym defines a SHN_ABS
> symbol while a normal definition is relative to the image base.
>
> See https://sourceware.org/pipermail/libc-alpha/2020-March/111910.html
> for discussions about the --defsym semantics.
> ---
>  elf/Makefile | 11 ++++-------
>  1 file changed, 4 insertions(+), 7 deletions(-)
>
> diff --git a/elf/Makefile b/elf/Makefile
> index 9b1d58c7ad..de5dff649d 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile
> @@ -497,10 +497,6 @@ rtld-stubbed-symbols = \
>    malloc \
>    realloc \
>
> -# The GCC arguments that implement $(rtld-stubbed-symbols).
> -rtld-stubbed-symbols-args = \
> -  $(patsubst %,-Wl$(comma)--defsym=%=0, $(rtld-stubbed-symbols))
> -
>  ifeq ($(have-ssp),yes)
>  # rtld is not built with the stack protector, so these references will
>  # go away in the rebuilds.
> @@ -509,9 +505,10 @@ endif
>
>  $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
>         @-rm -f $@T
> -       $(reloc-link) -o $@.o $(rtld-stubbed-symbols-args) \
> -               '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
> -       rm -f $@.o
> +       echo '$(patsubst %,.globl %;,$(rtld-stubbed-symbols)) $(patsubst %,%:,$(rtld-stubbed-symbols))' | \
> +               $(CC) -o $@T.o $(ASFLAGS) -c -x assembler -
> +       $(reloc-link) -o $@.o $@T.o '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
> +       rm -f %@T.o $@.o
>         mv -f $@T $@
>
>  $(objpfx)librtld.mk: $(objpfx)librtld.map Makefile
> --
> 2.26.0.110.g2183baf09c-goog
>

Ping

      reply	other threads:[~2020-08-31 23:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-04-11 22:16 Fangrui Song
2020-08-31 23:21 ` Fāng-ruì Sòng [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=CAFP8O3LnyQcUK7pD91edB5g6Z7n+tRbNE2pSWJowTR06UCDTBQ@mail.gmail.com \
    --to=maskray@google.com \
    --cc=fw@deneb.enyo.de \
    --cc=libc-alpha@sourceware.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).