diff mbox series

[2/3] elf: Replace a --defsym trick with an object file to be compatible with lld

Message ID 20201228194855.510315-3-maskray@google.com
State Changes Requested
Delegated to: Carlos O'Donell
Headers show
Series Make glibc build with LLD | expand

Commit Message

Fāng-ruì Sòng Dec. 28, 2020, 7:48 p.m. UTC
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(-)

Comments

Fāng-ruì Sòng Jan. 11, 2021, 8:06 p.m. UTC | #1
On Mon, Dec 28, 2020 at 11:49 AM 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(-)

Ping on this
Fāng-ruì Sòng Jan. 18, 2021, 10:08 p.m. UTC | #2
On Mon, Jan 11, 2021 at 12:06 PM Fāng-ruì Sòng <maskray@google.com> wrote:
>
> On Mon, Dec 28, 2020 at 11:49 AM 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(-)
>
> Ping on this

PING^2

https://sourceware.org/pipermail/libc-alpha/2020-December/121144.html
You can also find the commit in
https://sourceware.org/git/?p=glibc.git;a=shortlog;h=refs/heads/maskray/lld
H.J. Lu Jan. 19, 2021, 12:03 a.m. UTC | #3
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.

> +       $(reloc-link) -o $@.o $@T.o '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
> +       rm -f %@T.o $@.o
>         mv -f $@T $@
>
>  # For lld, skip preceding addresses and values before matching the archive and the member.
> --
> 2.29.2.729.g45daf8777d-goog
>
Fāng-ruì Sòng Jan. 19, 2021, 8:50 a.m. UTC | #4
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?

> > +       $(reloc-link) -o $@.o $@T.o '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
> > +       rm -f %@T.o $@.o
> >         mv -f $@T $@
> >
> >  # For lld, skip preceding addresses and values before matching the archive and the member.
> > --
> > 2.29.2.729.g45daf8777d-goog
> >
>
>
> --
> H.J.
H.J. Lu Jan. 19, 2021, 12:30 p.m. UTC | #5
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 "=".
Fāng-ruì Sòng Jan. 20, 2021, 6:51 p.m. UTC | #6
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.
Fāng-ruì Sòng Jan. 28, 2021, 1:03 a.m. UTC | #7
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`.
Adhemerval Zanella Jan. 29, 2021, 2:38 p.m. UTC | #8
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.

arc-linux-gnuhf:
make[2]: Entering directory '/home/azanella/glibc/glibc-git/elf'
echo '.globl calloc; .globl free; .globl malloc; .globl realloc; .globl __stack_chk_fail; .globl __stack_chk_fail_local; calloc: free: malloc: realloc: __stack_chk_fail: __stack_chk_fail_local:' | \
        /home/azanella/toolchain/install/compilers/arc-linux-gnuhf/bin/arc-glibc-linux-gnuhf-gcc -o /home/azanella/glibc/build/arc-linux-gnuhf/elf/librtld.mapT.o -g -Werror=undef -Wa,--noexecstack  -c -x assembler -
/home/azanella/toolchain/install/compilers/arc-linux-gnuhf/bin/arc-glibc-linux-gnuhf-gcc   -nostdlib -nostartfiles -r -o /home/azanella/glibc/build/arc-linux-gnuhf/elf/librtld.map.o /home/azanella/glibc/build/arc-linux-gnuhf/elf/librtld.mapT.o '-Wl,-(' /home/azanella/glibc/build/arc-linux-gnuhf/elf/dl-allobjs.os /home/azanella/glibc/build/arc-linux-gnuhf/libc_pic.a -lgcc '-Wl,-)' -Wl,-Map,/home/azanella/glibc/build/arc-linux-gnuhf/elf/librtld.mapT
/home/azanella/toolchain/install/compilers/arc-linux-gnuhf/lib/gcc/arc-glibc-linux-gnuhf/10.2.1/../../../../arc-glibc-linux-gnuhf/bin/ld: /home/azanella/glibc/build/arc-linux-gnuhf/libc_pic.a(sbrk.os): in function `__GI___sbrk':
/home/azanella/glibc/glibc-git/misc/sbrk.c:37: multiple definition of `__sbrk'; /home/azanella/glibc/build/arc-linux-gnuhf/elf/dl-allobjs.os:/home/azanella/glibc/glibc-git/elf/../misc/sbrk.c:37: first defined here
/home/azanella/toolchain/install/compilers/arc-linux-gnuhf/lib/gcc/arc-glibc-linux-gnuhf/10.2.1/../../../../arc-glibc-linux-gnuhf/bin/ld: /home/azanella/glibc/build/arc-linux-gnuhf/libc_pic.a(libc_fatal.os): in function `__GI___libc_fatal':
/home/azanella/glibc/glibc-git/libio/../sysdeps/posix/libc_fatal.c:161: multiple definition of `__GI___libc_fatal'; /home/azanella/glibc/build/arc-linux-gnuhf/elf/dl-allobjs.os:/home/azanella/glibc/glibc-git/elf/dl-minimal.c:267: first defined here
/home/azanella/toolchain/install/compilers/arc-linux-gnuhf/lib/gcc/arc-glibc-linux-gnuhf/10.2.1/../../../../arc-glibc-linux-gnuhf/bin/ld: /home/azanella/glibc/build/arc-linux-gnuhf/libc_pic.a(libc_fatal.os): in function `__GI___libc_fatal':
/home/azanella/glibc/glibc-git/libio/../sysdeps/posix/libc_fatal.c:161: multiple definition of `__libc_fatal'; /home/azanella/glibc/build/arc-linux-gnuhf/elf/dl-allobjs.os:/home/azanella/glibc/glibc-git/elf/dl-minimal.c:267: first defined here
/home/azanella/toolchain/install/compilers/arc-linux-gnuhf/lib/gcc/arc-glibc-linux-gnuhf/10.2.1/../../../../arc-glibc-linux-gnuhf/bin/ld: /home/azanella/glibc/build/arc-linux-gnuhf/libc_pic.a(_itoa.os): in function `_itoa':
/home/azanella/glibc/glibc-git/stdio-common/_itoa.c:196: multiple definition of `_itoa'; /home/azanella/glibc/build/arc-linux-gnuhf/elf/dl-allobjs.os:/home/azanella/glibc/glibc-git/elf/dl-minimal.c:323: first defined here
/home/azanella/toolchain/install/compilers/arc-linux-gnuhf/lib/gcc/arc-glibc-linux-gnuhf/10.2.1/../../../../arc-glibc-linux-gnuhf/bin/ld: /home/azanella/glibc/build/arc-linux-gnuhf/libc_pic.a(getcwd.os): in function `__GI___getcwd':
/home/azanella/glibc/glibc-git/io/../sysdeps/unix/sysv/linux/getcwd.c:50: multiple definition of `__getcwd'; /home/azanella/glibc/build/arc-linux-gnuhf/elf/dl-allobjs.os:/home/azanella/glibc/glibc-git/elf/../sysdeps/unix/sysv/linux/getcwd.c:50: first defined here
/home/azanella/toolchain/install/compilers/arc-linux-gnuhf/lib/gcc/arc-glibc-linux-gnuhf/10.2.1/../../../../arc-glibc-linux-gnuhf/bin/ld: /home/azanella/glibc/build/arc-linux-gnuhf/libc_pic.a(dl-error.os): in function `__GI__dl_signal_exception':
/home/azanella/glibc/glibc-git/elf/dl-error-skeleton.c:91: multiple definition of `_dl_signal_exception'; /home/azanella/glibc/build/arc-linux-gnuhf/elf/dl-allobjs.os:/home/azanella/glibc/glibc-git/elf/dl-error-skeleton.c:91: first defined here
/home/azanella/toolchain/install/compilers/arc-linux-gnuhf/lib/gcc/arc-glibc-linux-gnuhf/10.2.1/../../../../arc-glibc-linux-gnuhf/bin/ld: /home/azanella/glibc/build/arc-linux-gnuhf/libc_pic.a(dl-error.os): in function `__GI__dl_signal_error':
/home/azanella/glibc/glibc-git/elf/dl-error-skeleton.c:109: multiple definition of `_dl_signal_error'; /home/azanella/glibc/build/arc-linux-gnuhf/elf/dl-allobjs.os:/home/azanella/glibc/glibc-git/elf/dl-error-skeleton.c:109: first defined here
/home/azanella/toolchain/install/compilers/arc-linux-gnuhf/lib/gcc/arc-glibc-linux-gnuhf/10.2.1/../../../../arc-glibc-linux-gnuhf/bin/ld: /home/azanella/glibc/build/arc-linux-gnuhf/libc_pic.a(dl-error.os): in function `__GI__dl_catch_exception':
/home/azanella/glibc/glibc-git/elf/dl-error-skeleton.c:175: multiple definition of `_dl_catch_exception'; /home/azanella/glibc/build/arc-linux-gnuhf/elf/dl-allobjs.os:/home/azanella/glibc/glibc-git/elf/dl-error-skeleton.c:175: first defined here
/home/azanella/toolchain/install/compilers/arc-linux-gnuhf/lib/gcc/arc-glibc-linux-gnuhf/10.2.1/../../../../arc-glibc-linux-gnuhf/bin/ld: /home/azanella/glibc/build/arc-linux-gnuhf/libc_pic.a(dl-error.os): in function `__GI__dl_catch_error':
/home/azanella/glibc/glibc-git/elf/dl-error-skeleton.c:225: multiple definition of `_dl_catch_error'; /home/azanella/glibc/build/arc-linux-gnuhf/elf/dl-allobjs.os:/home/azanella/glibc/glibc-git/elf/dl-error-skeleton.c:225: first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:538: /home/azanella/glibc/build/arc-linux-gnuhf/elf/librtld.map] Error 1

hppa-linux-gnu:
echo '.globl calloc; .globl free; .globl malloc; .globl realloc; calloc: free: malloc: realloc:' | \
        /home/azanella/toolchain/install/compilers/hppa-linux-gnu/bin/hppa-glibc-linux-gnu-gcc -o /home/azanella/glibc/build/hppa-linux-gnu/elf/librtld.mapT.o -g -Werror=undef   -c -x assembler -
/home/azanella/toolchain/install/compilers/hppa-linux-gnu/bin/hppa-glibc-linux-gnu-gcc   -nostdlib -nostartfiles -r -o /home/azanella/glibc/build/hppa-linux-gnu/elf/librtld.map.o /home/azanella/glibc/build/hppa-linux-gnu/elf/librtld.mapT.o '-Wl,-(' /home/azanella/glibc/build/hppa-linux-gnu/elf/dl-allobjs.os /home/azanella/glibc/build/hppa-linux-gnu/libc_pic.a -lgcc '-Wl,-)' -Wl,-Map,/home/azanella/glibc/build/hppa-linux-gnu/elf/librtld.mapT
/home/azanella/toolchain/install/compilers/hppa-linux-gnu/lib/gcc/hppa-glibc-linux-gnu/10.2.1/../../../../hppa-glibc-linux-gnu/bin/ld: /home/azanella/glibc/build/hppa-linux-gnu/libc_pic.a(sbrk.os): in function `__GI___sbrk':
/home/azanella/glibc/glibc-git/misc/sbrk.c:37: multiple definition of `__sbrk'; /home/azanella/glibc/build/hppa-linux-gnu/elf/dl-allobjs.os:/home/azanella/glibc/glibc-git/elf/../misc/sbrk.c:37: first defined here
/home/azanella/toolchain/install/compilers/hppa-linux-gnu/lib/gcc/hppa-glibc-linux-gnu/10.2.1/../../../../hppa-glibc-linux-gnu/bin/ld: /home/azanella/glibc/build/hppa-linux-gnu/libc_pic.a(libc_fatal.os): in function `__GI___libc_fatal':
/home/azanella/glibc/glibc-git/libio/../sysdeps/posix/libc_fatal.c:161: multiple definition of `__GI___libc_fatal'; /home/azanella/glibc/build/hppa-linux-gnu/elf/dl-allobjs.os:/home/azanella/glibc/glibc-git/elf/dl-minimal.c:268: first defined here
/home/azanella/toolchain/install/compilers/hppa-linux-gnu/lib/gcc/hppa-glibc-linux-gnu/10.2.1/../../../../hppa-glibc-linux-gnu/bin/ld: /home/azanella/glibc/build/hppa-linux-gnu/libc_pic.a(libc_fatal.os): in function `__GI___libc_fatal':
/home/azanella/glibc/glibc-git/libio/../sysdeps/posix/libc_fatal.c:161: multiple definition of `__libc_fatal'; /home/azanella/glibc/build/hppa-linux-gnu/elf/dl-allobjs.os:/home/azanella/glibc/glibc-git/elf/dl-minimal.c:268: first defined here
/home/azanella/toolchain/install/compilers/hppa-linux-gnu/lib/gcc/hppa-glibc-linux-gnu/10.2.1/../../../../hppa-glibc-linux-gnu/bin/ld: /home/azanella/glibc/build/hppa-linux-gnu/libc_pic.a(_itoa.os): in function `_itoa':
/home/azanella/glibc/glibc-git/stdio-common/_itoa.c:196: multiple definition of `_itoa'; /home/azanella/glibc/build/hppa-linux-gnu/elf/dl-allobjs.os:/home/azanella/glibc/glibc-git/elf/dl-minimal.c:323: first defined here
/home/azanella/toolchain/install/compilers/hppa-linux-gnu/lib/gcc/hppa-glibc-linux-gnu/10.2.1/../../../../hppa-glibc-linux-gnu/bin/ld: /home/azanella/glibc/build/hppa-linux-gnu/libc_pic.a(getcwd.os): in function `__GI___getcwd':
/home/azanella/glibc/glibc-git/io/../sysdeps/unix/sysv/linux/getcwd.c:50: multiple definition of `__getcwd'; /home/azanella/glibc/build/hppa-linux-gnu/elf/dl-allobjs.os:/home/azanella/glibc/glibc-git/elf/../sysdeps/unix/sysv/linux/getcwd.c:50: first defined here
/home/azanella/toolchain/install/compilers/hppa-linux-gnu/lib/gcc/hppa-glibc-linux-gnu/10.2.1/../../../../hppa-glibc-linux-gnu/bin/ld: /home/azanella/glibc/build/hppa-linux-gnu/libc_pic.a(dl-error.os): in function `__GI__dl_signal_exception':
/home/azanella/glibc/glibc-git/elf/dl-error-skeleton.c:91: multiple definition of `_dl_signal_exception'; /home/azanella/glibc/build/hppa-linux-gnu/elf/dl-allobjs.os:/home/azanella/glibc/glibc-git/elf/dl-error-skeleton.c:91: first defined here
/home/azanella/toolchain/install/compilers/hppa-linux-gnu/lib/gcc/hppa-glibc-linux-gnu/10.2.1/../../../../hppa-glibc-linux-gnu/bin/ld: /home/azanella/glibc/build/hppa-linux-gnu/libc_pic.a(dl-error.os): in function `__GI__dl_signal_error':
/home/azanella/glibc/glibc-git/elf/dl-error-skeleton.c:109: multiple definition of `_dl_signal_error'; /home/azanella/glibc/build/hppa-linux-gnu/elf/dl-allobjs.os:/home/azanella/glibc/glibc-git/elf/dl-error-skeleton.c:109: first defined here
/home/azanella/toolchain/install/compilers/hppa-linux-gnu/lib/gcc/hppa-glibc-linux-gnu/10.2.1/../../../../hppa-glibc-linux-gnu/bin/ld: /home/azanella/glibc/build/hppa-linux-gnu/libc_pic.a(dl-error.os): in function `__GI__dl_catch_exception':
/home/azanella/glibc/glibc-git/elf/dl-error-skeleton.c:175: multiple definition of `_dl_catch_exception'; /home/azanella/glibc/build/hppa-linux-gnu/elf/dl-allobjs.os:/home/azanella/glibc/glibc-git/elf/dl-error-skeleton.c:175: first defined here
/home/azanella/toolchain/install/compilers/hppa-linux-gnu/lib/gcc/hppa-glibc-linux-gnu/10.2.1/../../../../hppa-glibc-linux-gnu/bin/ld: /home/azanella/glibc/build/hppa-linux-gnu/libc_pic.a(dl-error.os): in function `__GI__dl_catch_error':
/home/azanella/glibc/glibc-git/elf/dl-error-skeleton.c:225: multiple definition of `_dl_catch_error'; /home/azanella/glibc/build/hppa-linux-gnu/elf/dl-allobjs.os:/home/azanella/glibc/glibc-git/elf/dl-error-skeleton.c:225: first defined here
collect2: error: ld returned 1 exit status
H.J. Lu Jan. 29, 2021, 3:29 p.m. UTC | #9
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?
Adhemerval Zanella Jan. 29, 2021, 6:04 p.m. UTC | #10
On 29/01/2021 12:29, H.J. Lu wrote:
> 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.

The issue was in fact that hppa and arc uses no default asm line separators
(represented by ASM_LINE_SEP within code): hppa uses '!' while arc '`'. 
By replacing echo with printf and issuing a new line explicit I see that
all targets build:

---

diff --git a/elf/Makefile b/elf/Makefile
index 5d666b1b0c..e5c04f682c 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -526,10 +526,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.
@@ -538,9 +534,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
+       printf '$(patsubst %,.globl %;\n,$(rtld-stubbed-symbols)) $(patsubst %,% = 0;\n,$(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 $@

 # For lld, skip preceding addresses and values before matching the archive and the member.
diff mbox series

Patch

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 -
+	$(reloc-link) -o $@.o $@T.o '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
+	rm -f %@T.o $@.o
 	mv -f $@T $@
 
 # For lld, skip preceding addresses and values before matching the archive and the member.