libio: Properly link in function _IO_wfile_doallocate in static binaries

This patch addresses Bug 33935 - _IO_wfile_doallocate not linked correctly
when linking glibc statically.
https://sourceware.org/bugzilla/show_bug.cgi?id=33935

The function _IO_wfile_doallocate has been added with pragma weak in vtable.c,
while it is the only one symbol contained in wfiledoalloc.c,
and has not been directly called in libio.

In static binaries the true function symbol _IO_wfile_doallocate may not
be correctly linked when linking glibc with cases contains wchar functions,
but the weak symbol in vtable is linked instead,
and cause segmentation fault when running.

This patch fixes this with similar way to symbol _IO_file_doallocate,
that add libio_static_fn_required(_IO_wfile_doallocate) in wgenops.c
to make _IO_wfile_doallocate always link in static binaries.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
This commit is contained in:
Yunze Zhu 2026-03-10 11:29:18 +08:00 committed by Adhemerval Zanella
parent 28882c408c
commit 7a5d6adc8e
3 changed files with 37 additions and 1 deletions

View File

@ -136,6 +136,7 @@ tests = \
tst-ungetwc1 \
tst-ungetwc2 \
tst-wfile-sync \
tst-wfiledoallocate-static \
tst-widetext \
tst-wmemstream1 \
tst-wmemstream2 \
@ -151,7 +152,10 @@ tests = \
tst_wscanf \
# tests
tests-static += tst-stdio-static
tests-static += \
tst-stdio-static \
tst-wfiledoallocate-static \
# tests-static
$(objpfx)tst-popen-fork: $(shared-thread-library)

View File

@ -0,0 +1,30 @@
/* Test static link with function _IO_wfile_doallocate.
Copyright (C) 2026 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>
#include <wchar.h>
/* NB: Call main directly to trigger BZ #33935. */
int
main (void)
{
const wchar_t *string = L"Test String.";
(void) wprintf (L"%ls\n", string);
return 0;
}

View File

@ -34,6 +34,8 @@
static int save_for_wbackup (FILE *fp, wchar_t *end_p) __THROW;
libio_static_fn_required (_IO_wfile_doallocate);
/* Return minimum _pos markers
Assumes the current get area is the main get area. */
ssize_t