[PATCH] libio: Properly link in libio functions in static binaries
H.J. Lu
hjl.tools@gmail.com
Mon Aug 25 12:44:45 GMT 2025
On Mon, Aug 25, 2025 at 2:13 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * H. J. Lu:
>
> > On Thu, Aug 21, 2025 at 11:49 AM Florian Weimer <fweimer@redhat.com> wrote:
> >>
> >> * H. J. Lu:
> >>
> >> > commit 3020f72618e4f1d7338cd42b8bc7b2813e961b5a
> >> > Author: Adhemerval Zanella Netto <adhemerval.zanella@linaro.org>
> >> > Date: Tue Dec 27 18:11:43 2022 -0300
> >> >
> >> > libio: Remove the usage of __libc_IO_vtables
> >> >
> >> > added
> >> >
> >> > #define libio_static_fn_required(name) __asm (".globl " #name);
> >> >
> >> > to link in libio functions in static binaries. But there is no relocation
> >> > in
> >> > .globl _IO_file_open
> >> >
> >> > and "strip --strip-unneeded" will remove such unreferenced symbols which
> >> > breaks static binaries. Redefine libio_static_fn_required to create a
> >> > reference to the required function with
> >> >
> >> > .pushsection ".data.rel.ro.local","aw"
> >> > .L_IO_file_open:
> >> > .dc.a _IO_file_open
> >> > .popsection
> >> >
> >> > This fixes BZ #33300.
> >>
> >> Is it possible to use SHF_RETAIN instead?
> >
> > SHF_GNU_RETAIN is used to keep an unused section for --gc-sections while
> > this one is to include an object from libc.a. Even if the section with
> > _IO_file_doallocate is marked with SHF_GNU_RETAIN, it won't be linked in
> > without a reference to _IO_file_doallocate.
>
> Hmm. The --strip-unneeded option says this:
>
> --strip-unneeded
> Remove all symbols that are not needed for relocation processing in
> addition to debugging symbols and sections stripped by
> --strip-debug.
>
> I think it's a user error to use this on libc.a. What's the benefit of
Why can't --strip-unneeded be used on libc.a? If a symbol isn't used for
relocation processing, it is unused.
> using this option?
>
> Thanks,
> Florian
>
--
H.J.
More information about the Libc-alpha
mailing list