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

Fāng-ruì Sòng maskray@google.com
Mon Jan 18 22:08:46 GMT 2021


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


More information about the Libc-alpha mailing list