mirror of
https://sourceware.org/git/glibc.git
synced 2025-10-26 00:57:39 +03:00
libio: Properly link in libio functions in static binaries
commit 3020f72618
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
static __typeof (name) *const name##_p __attribute__((used)) = name;
This fixes BZ #33300.
Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Tested-by: Xi Ruoyao <xry111@xry111.site>
This commit is contained in:
@@ -130,6 +130,7 @@ tests = \
|
|||||||
tst-sprintf-chk-ub \
|
tst-sprintf-chk-ub \
|
||||||
tst-sprintf-ub \
|
tst-sprintf-ub \
|
||||||
tst-sscanf \
|
tst-sscanf \
|
||||||
|
tst-stdio-static \
|
||||||
tst-swscanf \
|
tst-swscanf \
|
||||||
tst-ungetwc1 \
|
tst-ungetwc1 \
|
||||||
tst-ungetwc2 \
|
tst-ungetwc2 \
|
||||||
@@ -149,6 +150,8 @@ tests = \
|
|||||||
tst_wscanf \
|
tst_wscanf \
|
||||||
# tests
|
# tests
|
||||||
|
|
||||||
|
tests-static += tst-stdio-static
|
||||||
|
|
||||||
$(objpfx)tst-popen-fork: $(shared-thread-library)
|
$(objpfx)tst-popen-fork: $(shared-thread-library)
|
||||||
|
|
||||||
tests-internal = tst-vtables tst-vtables-interposed
|
tests-internal = tst-vtables tst-vtables-interposed
|
||||||
@@ -445,3 +448,9 @@ $(objpfx)tst-bz22415-mem.out: $(objpfx)tst-bz22415.out
|
|||||||
$(objpfx)tst-bz24228-mem.out: $(objpfx)tst-bz24228.out
|
$(objpfx)tst-bz24228-mem.out: $(objpfx)tst-bz24228.out
|
||||||
$(common-objpfx)malloc/mtrace $(objpfx)tst-bz24228.mtrace > $@; \
|
$(common-objpfx)malloc/mtrace $(objpfx)tst-bz24228.mtrace > $@; \
|
||||||
$(evaluate-test)
|
$(evaluate-test)
|
||||||
|
|
||||||
|
# Test stdio.o with "strip --strip-unneeded".
|
||||||
|
$(objpfx)tst-stdio-static: $(objpfx)stdio-stripped.o
|
||||||
|
|
||||||
|
$(objpfx)stdio-stripped.o: $(objpfx)stdio.o
|
||||||
|
$(STRIP) --strip-unneeded -o $@ $<
|
||||||
|
|||||||
@@ -535,7 +535,8 @@ extern const struct _IO_jump_t __io_vtables[] attribute_hidden;
|
|||||||
#ifdef SHARED
|
#ifdef SHARED
|
||||||
# define libio_static_fn_required(name)
|
# define libio_static_fn_required(name)
|
||||||
#else
|
#else
|
||||||
# define libio_static_fn_required(name) __asm (".globl " #name);
|
# define libio_static_fn_required(name) \
|
||||||
|
static __typeof (name) *const name##_p __attribute__((used)) = name;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern int _IO_do_write (FILE *, const char *, size_t);
|
extern int _IO_do_write (FILE *, const char *, size_t);
|
||||||
|
|||||||
28
libio/tst-stdio-static.c
Normal file
28
libio/tst-stdio-static.c
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
/* Test static stdio.o with "strip --strip-unneeded".
|
||||||
|
Copyright (C) 2025 Free Software Foundation, Inc.
|
||||||
|
This file is part of the GNU C Library.
|
||||||
|
|
||||||
|
The GNU C Library is free software; you can redistribute it and/or
|
||||||
|
modify it under the terms of the GNU Lesser General Public
|
||||||
|
License as published by the Free Software Foundation; either
|
||||||
|
version 2.1 of the License, or (at your option) any later version.
|
||||||
|
|
||||||
|
The GNU C Library is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public
|
||||||
|
License along with the GNU C Library; if not, see
|
||||||
|
<https://www.gnu.org/licenses/>. */
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
/* NB: Call main directly to trigger BZ #33300. */
|
||||||
|
|
||||||
|
int
|
||||||
|
main (void)
|
||||||
|
{
|
||||||
|
printf ("OK\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user