[2/2] libc/stdio: fix undefined reference to `__ssputws_r'

Message ID 20240708040157.3770926-3-hau.hsu@sifive.com
State New
Headers
Series fix undefined reference to `__ssputws_r' |

Commit Message

Hau Hsu July 8, 2024, 4:01 a.m. UTC
  *Issue*
When compile a simple C++ hello world, we got undefined reference to
`__ssputws_r' error with NEWLIB_NANO_FORMATTED_IO after upgrading to
newlib-4.4 in risc-v toolchain:

svfwprintf.c:(.text._svfwprintf_r+0x8e): undefined reference to
`__ssputws_r'

*Cause*
This is because commit
"v{fs}printf/v{fs}wprintf: create external output helpers"
<https://cygwin.com/git/?p=newlib-cygwin.git;a=commit;h=61ccd3f94f92bcfc0940f0595ea5b3b72bce3c6d>
introduces a new file ssputws_r.c for a wide-char-oriented helper function.
But this file will not be built when newlib_nano_formated_io is enabled.

The problem is that the function __ssputws_r() is used by svfwprintf(),
which is compiled no matter whether newlib_nano_formated_io is enabled.

*Fix*
This patch fix the issue by building ssputws_r.c regardless of whether
newlib_nano_formated_io is enabled.

*Problem of the previous fix*
Note that we also reverts a previouls patch that tries to fix the same
link error:
<https://cygwin.com/git/?p=newlib-cygwin.git;a=commitdiff;h=3b97a5ec67a5a52c130158bb143949cd842de305>
Because we got other errors after applying this patch:

undefined reference to `putwc'
...
undefined reference to `getwc'
...
undefined reference to `swprintf'

The previous patch removes wchar_t functions from
NEWLIB_NANO_FORMATTED_IO, but in the newlib/README says:

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

Thus I think we shouldn't remove wchar_t functions from
newlib_nano_formated_io.

Similar bug report:
* https://inbox.sourceware.org/newlib/ed0b48da6c6c4beaacd9fad63efaddc0@syntacore.com/t/
---
 newlib/Makefile.in             | 38 ++++++++++++++++------------------
 newlib/libc/stdio/Makefile.inc |  2 +-
 2 files changed, 19 insertions(+), 21 deletions(-)
  

Patch

diff --git a/newlib/Makefile.in b/newlib/Makefile.in
index 2bd1431f9..523069ad4 100644
--- a/newlib/Makefile.in
+++ b/newlib/Makefile.in
@@ -243,7 +243,6 @@  check_PROGRAMS =
 @HAVE_STDIO_DIR_TRUE@@NEWLIB_NANO_FORMATTED_IO_FALSE@	libc/stdio/sprint_r.c \
 @HAVE_STDIO_DIR_TRUE@@NEWLIB_NANO_FORMATTED_IO_FALSE@	libc/stdio/swprint_r.c \
 @HAVE_STDIO_DIR_TRUE@@NEWLIB_NANO_FORMATTED_IO_FALSE@	libc/stdio/ssputs_r.c \
-@HAVE_STDIO_DIR_TRUE@@NEWLIB_NANO_FORMATTED_IO_FALSE@	libc/stdio/ssputws_r.c \
 @HAVE_STDIO_DIR_TRUE@@NEWLIB_NANO_FORMATTED_IO_FALSE@	libc/stdio/ssprint_r.c \
 @HAVE_STDIO_DIR_TRUE@@NEWLIB_NANO_FORMATTED_IO_FALSE@	libc/stdio/sswprint_r.c
 
@@ -278,7 +277,7 @@  check_PROGRAMS =
 @HAVE_STDIO_DIR_TRUE@	libc/stdio/setvbuf.c \
 @HAVE_STDIO_DIR_TRUE@	libc/stdio/snprintf.c \
 @HAVE_STDIO_DIR_TRUE@	libc/stdio/sprintf.c libc/stdio/sscanf.c \
-@HAVE_STDIO_DIR_TRUE@	libc/stdio/stdio.c \
+@HAVE_STDIO_DIR_TRUE@	libc/stdio/ssputws_r.c libc/stdio/stdio.c \
 @HAVE_STDIO_DIR_TRUE@	libc/stdio/svfiwprintf.c \
 @HAVE_STDIO_DIR_TRUE@	libc/stdio/svfiwscanf.c \
 @HAVE_STDIO_DIR_TRUE@	libc/stdio/svfwprintf.c \
@@ -1190,7 +1189,6 @@  am__objects_5 = libc/stdlib/libc_a-rpmatch.$(OBJEXT) \
 @HAVE_STDIO_DIR_TRUE@@NEWLIB_NANO_FORMATTED_IO_FALSE@	libc/stdio/libc_a-sprint_r.$(OBJEXT) \
 @HAVE_STDIO_DIR_TRUE@@NEWLIB_NANO_FORMATTED_IO_FALSE@	libc/stdio/libc_a-swprint_r.$(OBJEXT) \
 @HAVE_STDIO_DIR_TRUE@@NEWLIB_NANO_FORMATTED_IO_FALSE@	libc/stdio/libc_a-ssputs_r.$(OBJEXT) \
-@HAVE_STDIO_DIR_TRUE@@NEWLIB_NANO_FORMATTED_IO_FALSE@	libc/stdio/libc_a-ssputws_r.$(OBJEXT) \
 @HAVE_STDIO_DIR_TRUE@@NEWLIB_NANO_FORMATTED_IO_FALSE@	libc/stdio/libc_a-ssprint_r.$(OBJEXT) \
 @HAVE_STDIO_DIR_TRUE@@NEWLIB_NANO_FORMATTED_IO_FALSE@	libc/stdio/libc_a-sswprint_r.$(OBJEXT)
 @ELIX_LEVEL_1_FALSE@@HAVE_STDIO_DIR_TRUE@@NEWLIB_NANO_FORMATTED_IO_FALSE@am__objects_12 = libc/stdio/libc_a-asiprintf.$(OBJEXT) \
@@ -1316,6 +1314,7 @@  am__objects_5 = libc/stdlib/libc_a-rpmatch.$(OBJEXT) \
 @HAVE_STDIO_DIR_TRUE@	libc/stdio/libc_a-snprintf.$(OBJEXT) \
 @HAVE_STDIO_DIR_TRUE@	libc/stdio/libc_a-sprintf.$(OBJEXT) \
 @HAVE_STDIO_DIR_TRUE@	libc/stdio/libc_a-sscanf.$(OBJEXT) \
+@HAVE_STDIO_DIR_TRUE@	libc/stdio/libc_a-ssputws_r.$(OBJEXT) \
 @HAVE_STDIO_DIR_TRUE@	libc/stdio/libc_a-stdio.$(OBJEXT) \
 @HAVE_STDIO_DIR_TRUE@	libc/stdio/libc_a-svfiwprintf.$(OBJEXT) \
 @HAVE_STDIO_DIR_TRUE@	libc/stdio/libc_a-svfiwscanf.$(OBJEXT) \
@@ -3941,7 +3940,6 @@  pdfdir = @pdfdir@
 prefix = @prefix@
 program_transform_name = @program_transform_name@
 psdir = @psdir@
-runstatedir = @runstatedir@
 sbindir = @sbindir@
 shared_machine_dir = @shared_machine_dir@
 sharedstatedir = @sharedstatedir@
@@ -6001,8 +5999,6 @@  libc/stdio/libc_a-swprint_r.$(OBJEXT): libc/stdio/$(am__dirstamp) \
 	libc/stdio/$(DEPDIR)/$(am__dirstamp)
 libc/stdio/libc_a-ssputs_r.$(OBJEXT): libc/stdio/$(am__dirstamp) \
 	libc/stdio/$(DEPDIR)/$(am__dirstamp)
-libc/stdio/libc_a-ssputws_r.$(OBJEXT): libc/stdio/$(am__dirstamp) \
-	libc/stdio/$(DEPDIR)/$(am__dirstamp)
 libc/stdio/libc_a-ssprint_r.$(OBJEXT): libc/stdio/$(am__dirstamp) \
 	libc/stdio/$(DEPDIR)/$(am__dirstamp)
 libc/stdio/libc_a-sswprint_r.$(OBJEXT): libc/stdio/$(am__dirstamp) \
@@ -6115,6 +6111,8 @@  libc/stdio/libc_a-sprintf.$(OBJEXT): libc/stdio/$(am__dirstamp) \
 	libc/stdio/$(DEPDIR)/$(am__dirstamp)
 libc/stdio/libc_a-sscanf.$(OBJEXT): libc/stdio/$(am__dirstamp) \
 	libc/stdio/$(DEPDIR)/$(am__dirstamp)
+libc/stdio/libc_a-ssputws_r.$(OBJEXT): libc/stdio/$(am__dirstamp) \
+	libc/stdio/$(DEPDIR)/$(am__dirstamp)
 libc/stdio/libc_a-stdio.$(OBJEXT): libc/stdio/$(am__dirstamp) \
 	libc/stdio/$(DEPDIR)/$(am__dirstamp)
 libc/stdio/libc_a-svfiwprintf.$(OBJEXT): libc/stdio/$(am__dirstamp) \
@@ -24092,20 +24090,6 @@  libc/stdio/libc_a-ssputs_r.obj: libc/stdio/ssputs_r.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -c -o libc/stdio/libc_a-ssputs_r.obj `if test -f 'libc/stdio/ssputs_r.c'; then $(CYGPATH_W) 'libc/stdio/ssputs_r.c'; else $(CYGPATH_W) '$(srcdir)/libc/stdio/ssputs_r.c'; fi`
 
-libc/stdio/libc_a-ssputws_r.o: libc/stdio/ssputws_r.c
-@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/stdio/libc_a-ssputws_r.o -MD -MP -MF libc/stdio/$(DEPDIR)/libc_a-ssputws_r.Tpo -c -o libc/stdio/libc_a-ssputws_r.o `test -f 'libc/stdio/ssputws_r.c' || echo '$(srcdir)/'`libc/stdio/ssputws_r.c
-@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) libc/stdio/$(DEPDIR)/libc_a-ssputws_r.Tpo libc/stdio/$(DEPDIR)/libc_a-ssputws_r.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='libc/stdio/ssputws_r.c' object='libc/stdio/libc_a-ssputws_r.o' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -c -o libc/stdio/libc_a-ssputws_r.o `test -f 'libc/stdio/ssputws_r.c' || echo '$(srcdir)/'`libc/stdio/ssputws_r.c
-
-libc/stdio/libc_a-ssputws_r.obj: libc/stdio/ssputws_r.c
-@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/stdio/libc_a-ssputws_r.obj -MD -MP -MF libc/stdio/$(DEPDIR)/libc_a-ssputws_r.Tpo -c -o libc/stdio/libc_a-ssputws_r.obj `if test -f 'libc/stdio/ssputws_r.c'; then $(CYGPATH_W) 'libc/stdio/ssputws_r.c'; else $(CYGPATH_W) '$(srcdir)/libc/stdio/ssputws_r.c'; fi`
-@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) libc/stdio/$(DEPDIR)/libc_a-ssputws_r.Tpo libc/stdio/$(DEPDIR)/libc_a-ssputws_r.Po
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='libc/stdio/ssputws_r.c' object='libc/stdio/libc_a-ssputws_r.obj' libtool=no @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -c -o libc/stdio/libc_a-ssputws_r.obj `if test -f 'libc/stdio/ssputws_r.c'; then $(CYGPATH_W) 'libc/stdio/ssputws_r.c'; else $(CYGPATH_W) '$(srcdir)/libc/stdio/ssputws_r.c'; fi`
-
 libc/stdio/libc_a-ssprint_r.o: libc/stdio/ssprint_r.c
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/stdio/libc_a-ssprint_r.o -MD -MP -MF libc/stdio/$(DEPDIR)/libc_a-ssprint_r.Tpo -c -o libc/stdio/libc_a-ssprint_r.o `test -f 'libc/stdio/ssprint_r.c' || echo '$(srcdir)/'`libc/stdio/ssprint_r.c
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) libc/stdio/$(DEPDIR)/libc_a-ssprint_r.Tpo libc/stdio/$(DEPDIR)/libc_a-ssprint_r.Po
@@ -24890,6 +24874,20 @@  libc/stdio/libc_a-sscanf.obj: libc/stdio/sscanf.c
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
 @am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -c -o libc/stdio/libc_a-sscanf.obj `if test -f 'libc/stdio/sscanf.c'; then $(CYGPATH_W) 'libc/stdio/sscanf.c'; else $(CYGPATH_W) '$(srcdir)/libc/stdio/sscanf.c'; fi`
 
+libc/stdio/libc_a-ssputws_r.o: libc/stdio/ssputws_r.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/stdio/libc_a-ssputws_r.o -MD -MP -MF libc/stdio/$(DEPDIR)/libc_a-ssputws_r.Tpo -c -o libc/stdio/libc_a-ssputws_r.o `test -f 'libc/stdio/ssputws_r.c' || echo '$(srcdir)/'`libc/stdio/ssputws_r.c
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) libc/stdio/$(DEPDIR)/libc_a-ssputws_r.Tpo libc/stdio/$(DEPDIR)/libc_a-ssputws_r.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='libc/stdio/ssputws_r.c' object='libc/stdio/libc_a-ssputws_r.o' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -c -o libc/stdio/libc_a-ssputws_r.o `test -f 'libc/stdio/ssputws_r.c' || echo '$(srcdir)/'`libc/stdio/ssputws_r.c
+
+libc/stdio/libc_a-ssputws_r.obj: libc/stdio/ssputws_r.c
+@am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/stdio/libc_a-ssputws_r.obj -MD -MP -MF libc/stdio/$(DEPDIR)/libc_a-ssputws_r.Tpo -c -o libc/stdio/libc_a-ssputws_r.obj `if test -f 'libc/stdio/ssputws_r.c'; then $(CYGPATH_W) 'libc/stdio/ssputws_r.c'; else $(CYGPATH_W) '$(srcdir)/libc/stdio/ssputws_r.c'; fi`
+@am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) libc/stdio/$(DEPDIR)/libc_a-ssputws_r.Tpo libc/stdio/$(DEPDIR)/libc_a-ssputws_r.Po
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	$(AM_V_CC)source='libc/stdio/ssputws_r.c' object='libc/stdio/libc_a-ssputws_r.obj' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@	$(AM_V_CC@am__nodep@)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -c -o libc/stdio/libc_a-ssputws_r.obj `if test -f 'libc/stdio/ssputws_r.c'; then $(CYGPATH_W) 'libc/stdio/ssputws_r.c'; else $(CYGPATH_W) '$(srcdir)/libc/stdio/ssputws_r.c'; fi`
+
 libc/stdio/libc_a-stdio.o: libc/stdio/stdio.c
 @am__fastdepCC_TRUE@	$(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libc_a_CPPFLAGS) $(CPPFLAGS) $(libc_a_CFLAGS) $(CFLAGS) -MT libc/stdio/libc_a-stdio.o -MD -MP -MF libc/stdio/$(DEPDIR)/libc_a-stdio.Tpo -c -o libc/stdio/libc_a-stdio.o `test -f 'libc/stdio/stdio.c' || echo '$(srcdir)/'`libc/stdio/stdio.c
 @am__fastdepCC_TRUE@	$(AM_V_at)$(am__mv) libc/stdio/$(DEPDIR)/libc_a-stdio.Tpo libc/stdio/$(DEPDIR)/libc_a-stdio.Po
diff --git a/newlib/libc/stdio/Makefile.inc b/newlib/libc/stdio/Makefile.inc
index e25680212..58b40b2f5 100644
--- a/newlib/libc/stdio/Makefile.inc
+++ b/newlib/libc/stdio/Makefile.inc
@@ -39,7 +39,6 @@  libc_a_SOURCES += \
 	%D%/sprint_r.c \
 	%D%/swprint_r.c \
 	%D%/ssputs_r.c \
-	%D%/ssputws_r.c \
 	%D%/ssprint_r.c \
 	%D%/sswprint_r.c
 endif
@@ -99,6 +98,7 @@  libc_a_SOURCES += \
 	%D%/snprintf.c \
 	%D%/sprintf.c \
 	%D%/sscanf.c \
+	%D%/ssputws_r.c \
 	%D%/stdio.c \
 	%D%/svfiwprintf.c \
 	%D%/svfiwscanf.c \