[PATCH v3] libio: Properly link in function _IO_wfile_doallocate in static binaries

H.J. Lu hjl.tools@gmail.com
Mon Mar 9 13:15:07 GMT 2026


On Mon, Mar 9, 2026 at 6:06 AM <yunzezhu@linux.alibaba.com> wrote:
>
> From: Yunze Zhu <yunzezhu@linux.alibaba.com>
>
> Changes from V2:
> Fix no newline at end of file error in tst-wfiledoallocate-static.
> Put test tst-wfiledoallocate-static in Makefile into a new line.
>
> Changes from V1:
> Add a simple testcase that triggers Bug #33935.
>
> 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.
> ---
>  libio/Makefile                     |  3 +++
>  libio/tst-wfiledoallocate-static.c | 29 +++++++++++++++++++++++++++++
>  libio/wgenops.c                    |  2 ++
>  3 files changed, 34 insertions(+)
>  create mode 100644 libio/tst-wfiledoallocate-static.c
>
> diff --git a/libio/Makefile b/libio/Makefile
> index 4f4dd9f275..6cdd658412 100644
> --- a/libio/Makefile
> +++ b/libio/Makefile
> @@ -136,6 +136,7 @@ tests = \
>    tst-ungetwc1 \
>    tst-ungetwc2 \
>    tst-wfile-sync \
> +  tst-wfiledoallocate-static \
>    tst-widetext \
>    tst-wmemstream1 \
>    tst-wmemstream2 \
> @@ -153,6 +154,8 @@ tests = \
>
>  tests-static += tst-stdio-static
>
> +tests-static += tst-wfiledoallocate-static
> +

Please do

tests-static += \
   tst-stdio-static \
   tst-wfiledoallocate-static \
# tests-static

>  $(objpfx)tst-popen-fork: $(shared-thread-library)
>
>  tests-internal = tst-vtables tst-vtables-interposed
> diff --git a/libio/tst-wfiledoallocate-static.c b/libio/tst-wfiledoallocate-static.c
> new file mode 100644
> index 0000000000..8cdba1bf75
> --- /dev/null
> +++ b/libio/tst-wfiledoallocate-static.c
> @@ -0,0 +1,29 @@
> +/* 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()
> +{
> +       const wchar_t *string = L"Test String.";
> +       int res = wprintf(L"%ls\n", string);
> +        return 0;
> +}
> diff --git a/libio/wgenops.c b/libio/wgenops.c
> index 7a8466ea44..064d71266d 100644
> --- a/libio/wgenops.c
> +++ b/libio/wgenops.c
> @@ -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
> --
> 2.47.1
>


-- 
H.J.


More information about the Libc-alpha mailing list