Newlib: nano-formatted-io and libstdc++ compatibility

Mark Goncharov <[email protected]>
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
Hello.
My name is Mark.
My problem has appeared on RISC-V target, but seems to be the same for every target.

To reproduce the bug:

#include <iostream>
int main() { std::cout << "Hello world"; }

Compile: riscv64-unknown-elf-g++ --specs=nano.specs a.cpp

Have different outputs with gcc-13.2 that was built with newlib-nano and --enable-newlib-nano-formatted-io option as in https://github.com/riscv-collab/riscv-gnu-toolchain do:

1) newlib-4.3
Works good

2) newlib-4.4 without patch - https://cygwin.com/git/?p=newlib-cygwin.git;a=commit;h=61ccd3f94f92bcfc0940f0595ea5b3b72bce3c6d
Also works good

3) newlib-4.4
Fail with error
libc_nano.a(libc_a-svfwprintf.o): in function `_svfwprintf_r':
(.text._svfwprintf_r+0x7a): undefined reference to `__ssputws_r'

4) newlib-4.4 + fix regression for arm https://cygwin.com/git/?p=newlib-cygwin.git;a=commitdiff;h=3b97a5ec67a5a52c130158bb143949cd842de305
Fail with error
in function `__gnu_cxx::stdio_sync_filebuf<wchar_t, std::char_traits<wchar_t> >::uflow()':
(.text._ZN9__gnu_cxx18stdio_sync_filebufIwSt11char_traitsIwEE5uflowEv[_ZN9__gnu_cxx18stdio_sync_filebufIwSt11char_traitsIwEE5uflowEv]+0xa): undefined reference to `getwc
... // same for putwc, ungetwc and swprintf

The first patch changes newlib/libc/stdio/vfwprintf.c file and defines __ssputws_r instead of __ssputs_r. Of course, it fails, because nano-formatted-io doesn't implement this function (see newlib/libc/stdio/Makefile.inc for NEWLIB_NANO_FORMATTED_IO case)

The second patch removes every wide-char usage for nano_formatted_io, so, the simplest "Hello world" can't be compiled with newlib-nano, because libstdc++  links even with unused symbols.

----------------------------------------------------------------

Finally, I have a question.

In newlib/README:
--enable-newlib-nano-formatted-io
  This option does not affect wide-char formatted I/O functions

But current implementation affect wide-char formatted I/O. We really want to broke compatibility with nano-formatted-io and libstdc++?

I propose, we need to get back wide-char support for nano-formatted-io.

With best regards,
Mark
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.