public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: "H.J. Lu" <hjl.tools@gmail.com>
To: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Cc: "Fāng-ruì Sòng" <maskray@google.com>,
	"Florian Weimer" <fweimer@redhat.com>,
	"GNU C Library" <libc-alpha@sourceware.org>
Subject: Re: [PATCH 2/3] elf: Replace a --defsym trick with an object file to be compatible with lld
Date: Fri, 29 Jan 2021 07:29:24 -0800	[thread overview]
Message-ID: <CAMe9rOq35QDRTzTY6X3=G+c9Q7uK_UhyuWJOneWPQnT6Q-cZHA@mail.gmail.com> (raw)
In-Reply-To: <4c4b4d3b-6265-7575-d1e8-879471121511@linaro.org>

On Fri, Jan 29, 2021 at 7:26 AM Adhemerval Zanella via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
>
>
> On 27/01/2021 22:03, Fāng-ruì Sòng via Libc-alpha wrote:
> > On Wed, Jan 20, 2021 at 10:51 AM Fāng-ruì Sòng <maskray@google.com> wrote:
> >>
> >> On Tue, Jan 19, 2021 at 4:31 AM H.J. Lu <hjl.tools@gmail.com> wrote:
> >>>
> >>> On Tue, Jan 19, 2021 at 12:50 AM Fāng-ruì Sòng <maskray@google.com> wrote:
> >>>>
> >>>> On Mon, Jan 18, 2021 at 4:04 PM H.J. Lu <hjl.tools@gmail.com> wrote:
> >>>>>
> >>>>> On Mon, Dec 28, 2020 at 11:50 AM Fangrui Song via Libc-alpha
> >>>>> <libc-alpha@sourceware.org> 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.
> >>>>>>
> >>>>>
> >>>>> This is irrelevant since  --defsym was used to create a temporary file which was
> >>>>> removed immediately after it was created:
> >>>>>
> >>>>> /usr/bin/gcc   -nostdlib -nostartfiles -r -o
> >>>>> /export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/elf/librtld.map.o
> >>>>> -Wl,--defsym=calloc=0 -Wl,--defsym=free=0 -Wl,--defsym=malloc=0
> >>>>> -Wl,--defsym=realloc=0 -Wl,--defsym=__stack_chk_fail=0
> >>>>> -Wl,--defsym=__stack_chk_fail_local=0 \
> >>>>>         '-Wl,-('
> >>>>> /export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/elf/dl-allobjs.os
> >>>>> /export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/libc_pic.a
> >>>>> -lgcc '-Wl,-)' -Wl,-Map,/export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/elf/librtld.mapT
> >>>>> rm -f /export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/elf/librtld.map.o
> >>>>> mv -f /export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/elf/librtld.mapT
> >>>>> /export/users/hjl/build/gnu/tools-build/glibc-gitlab/build-x86_64-linux/elf/librtld.map
> >>>>>
> >>>>>> ---
> >>>>>>  elf/Makefile | 11 ++++-------
> >>>>>>  1 file changed, 4 insertions(+), 7 deletions(-)
> >>>>>>
> >>>>>> diff --git a/elf/Makefile b/elf/Makefile
> >>>>>> index 0b4d78c874..299bf24b49 100644
> >>>>>> --- a/elf/Makefile
> >>>>>> +++ b/elf/Makefile
> >>>>>> @@ -524,10 +524,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.
> >>>>>> @@ -536,9 +532,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 -
> >>>>>
> >>>>> Please generate
> >>>>>
> >>>>> .globl symbol;
> >>>>> symbol = 0;
> >>>>>
> >>>>> to make it closer to -Wl,--defsym=symbol=0.
> >>>>
> >>>> If symbol: and symbol = 0; work, isn't symbol: slightly better because
> >>>> it looks more normal?
> >>>> Or is the intention here using SHN_ABS to make it clear these symbols
> >>>> are special?
> >>>
> >>> Generate machine independent assembly codes is tricky.   We should
> >>> make before and after the change as close as possible to avoid ANY
> >>> surprises.   BTW, you need to check HAVE_ASM_SET_DIRECTIVE
> >>> to decide using ".set" vs "=".
> >>>
> >>> --
> >>> H.J.
> >>
> >> Thanks for the tip. In this case I think the patch as is (sticking
> >> with `foo:`, don't use `foo = 0` or set) is better.
> >> foo: works everywhere.
> >
> > Ping. I think the patch as-is is better than the alternative approach
> > using either `=` or `.set`.
>
> The patch breaks both arc-linux-gnuhf and hppa-linux-gnu with recent
> ld.bfd 2.26, as below.
>
> We will need to sort these out.
>

Does my suggestion work?

-- 
H.J.

  reply	other threads:[~2021-01-29 15:30 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-28 19:48 [PATCH 0/3] Make glibc build with LLD Fangrui Song
2020-12-28 19:48 ` [PATCH 1/3] configure: Allow LD to be a linker other than GNU ld and gold Fangrui Song
2020-12-28 20:46   ` H.J. Lu
2020-12-28 21:15     ` [PATCH 1/3] configure: Allow LD to be LLD 9.0.0 or above " Fangrui Song
2020-12-28 19:48 ` [PATCH 2/3] elf: Replace a --defsym trick with an object file to be compatible with lld Fangrui Song
2021-01-11 20:06   ` Fāng-ruì Sòng
2021-01-18 22:08     ` Fāng-ruì Sòng
2021-01-19  0:03   ` H.J. Lu
2021-01-19  8:50     ` Fāng-ruì Sòng
2021-01-19 12:30       ` H.J. Lu
2021-01-20 18:51         ` Fāng-ruì Sòng
2021-01-28  1:03           ` Fāng-ruì Sòng
2021-01-29 14:38             ` Adhemerval Zanella
2021-01-29 15:29               ` H.J. Lu [this message]
2021-01-29 18:04                 ` Adhemerval Zanella
2021-01-29 19:28                   ` [PATCH v2] elf: Replace a --defsym trick with an object file to be compatible with LLD Fangrui Song
2021-02-01 13:19                     ` Adhemerval Zanella
2021-02-01 13:45                       ` H.J. Lu
2021-02-01 13:43                     ` Florian Weimer
2020-12-28 19:48 ` [PATCH 3/3] install: Replace scripts/output-format.sed with objdump -f [BZ #26559] Fangrui Song
2021-01-08 19:38   ` Adhemerval Zanella
2021-01-12 11:20     ` Florian Weimer
2021-01-12 12:00       ` Adhemerval Zanella
2021-01-12 17:46         ` Fāng-ruì Sòng
2021-01-12 11:32   ` Andreas Schwab
2021-01-12 11:58     ` Florian Weimer
2020-12-28 21:11 ` [PATCH 0/3] Make glibc build with LLD H.J. Lu
2020-12-28 21:45   ` Fangrui Song
2020-12-28 21:49     ` H.J. Lu
2020-12-28 22:54       ` H.J. Lu
2021-01-05 23:03         ` Fāng-ruì Sòng
2021-01-05 23:33           ` H.J. Lu
2021-01-05 23:41             ` Fāng-ruì Sòng
2021-01-05 23:51               ` H.J. Lu
2021-01-06  0:50                 ` Fāng-ruì Sòng
2021-01-06  1:43                   ` H.J. Lu
2021-01-06  2:00                     ` Fāng-ruì Sòng
2021-01-06  2:14                       ` H.J. Lu
2021-01-05 22:57       ` Fāng-ruì Sòng
2021-01-08  5:04 ` Fāng-ruì Sòng
2021-01-08 17:09   ` H.J. Lu
2021-01-08 18:04     ` Fāng-ruì Sòng

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='CAMe9rOq35QDRTzTY6X3=G+c9Q7uK_UhyuWJOneWPQnT6Q-cZHA@mail.gmail.com' \
    --to=hjl.tools@gmail.com \
    --cc=adhemerval.zanella@linaro.org \
    --cc=fweimer@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=maskray@google.com \
    /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).