Broken RISC-V code in newlib

Jeff Law jlaw@ventanamicro.com
Tue Mar 25 13:40:27 GMT 2025


You recently put a typedef into libc/machine/riscv/sys/asm.h as well as 
including stdint.h.

That breaks code such as strcmp.S which includes sys/asm.h, but is 
processed by the assembler after pre-processing:

>   CPPAS    libc/machine/riscv/libc_a-strcmp.o
> /home/jlaw/jenkins/workspace/riscv64-elf/newlib-cygwin/newlib/libc/include/machine/_default_types.h: Assembler messages:
> /home/jlaw/jenkins/workspace/riscv64-elf/newlib-cygwin/newlib/libc/include/machine/_default_types.h:41: Error: unrecognized opcode `typedef signed char __int8_t'
> /home/jlaw/jenkins/workspace/riscv64-elf/newlib-cygwin/newlib/libc/include/machine/_default_types.h:43: Error: unrecognized opcode `typedef unsigned char __uint8_t'
> /home/jlaw/jenkins/workspace/riscv64-elf/newlib-cygwin/newlib/libc/include/machine/_default_types.h:55: Error: unrecognized opcode `typedef short int __int16_t'
> /home/jlaw/jenkins/workspace/riscv64-elf/newlib-cygwin/newlib/libc/include/machine/_default_types.h:57: Error: unrecognized opcode `typedef short unsigned int __uint16_t'
> /home/jlaw/jenkins/workspace/riscv64-elf/newlib-cygwin/newlib/libc/include/machine/_default_types.h:77: Error: unrecognized opcode `typedef int __int32_t'
> /home/jlaw/jenkins/workspace/riscv64-elf/newlib-cygwin/newlib/libc/include/machine/_default_types.h:79: Error: unrecognized opcode `typedef unsigned int __uint32_t'
[ ... ]

>   CPPAS    libc/machine/riscv/libc_a-setjmp.o
> /home/jlaw/jenkins/workspace/riscv64-elf/newlib-cygwin/newlib/libc/include/machine/_default_types.h: Assembler messages:
> /home/jlaw/jenkins/workspace/riscv64-elf/newlib-cygwin/newlib/libc/include/machine/_default_types.h:41: Error: unrecognized opcode `typedef signed char __int8_t'
> /home/jlaw/jenkins/workspace/riscv64-elf/newlib-cygwin/newlib/libc/include/machine/_default_types.h:43: Error: unrecognized opcode `typedef unsigned char __uint8_t'
> /home/jlaw/jenkins/workspace/riscv64-elf/newlib-cygwin/newlib/libc/include/machine/_default_types.h:55: Error: unrecognized opcode `typedef short int __int16_t'
> /home/jlaw/jenkins/workspace/riscv64-elf/newlib-cygwin/newlib/libc/include/machine/_default_types.h:57: Error: unrecognized opcode `typedef short unsigned int __uint16_t'
> /home/jlaw/jenkins/workspace/riscv64-elf/newlib-cygwin/newlib/libc/include/machine/_default_types.h:77: Error: unrecognized opcode `typedef int __int32_t'



Those two failures make it appear that this change has not been tested 
at all.

And it looks like you busted strcpy as well.  This probably only fails 
with gcc-15 as gcc-15 defaults to c23 where implicit declarations are 
flagged as hard errors:

>  CC       libc/machine/riscv/libc_a-strcpy.o
> ../../../..//newlib-cygwin/newlib/libc/machine/riscv/strcpy.c: In function 'strcpy':
> ../../../..//newlib-cygwin/newlib/libc/machine/riscv/strcpy.c:17:10: error: implicit declaration of function '__libc_strcpy'; did you mean '__builtin_strcpy'? [-Wimplicit-function-declaration]
>    17 |   return __libc_strcpy(dst, src, true);
>       |          ^~~~~~~~~~~~~
>       |          __builtin_strcpy
> ../../../..//newlib-cygwin/newlib/libc/machine/riscv/strcpy.c:17:10: error: returning 'int' from a function with return type 'char *' makes pointer from integer without a cast [-Wint-conversion]
>    17 |   return __libc_strcpy(dst, src, true);
>       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

And stpcpy:
>   CC       libc/machine/riscv/libc_a-stpcpy.o
> ../../../..//newlib-cygwin/newlib/libc/machine/riscv/stpcpy.c: In function 'stpcpy':
> ../../../..//newlib-cygwin/newlib/libc/machine/riscv/stpcpy.c:6:10: error: implicit declaration of function '__libc_strcpy'; did you mean '__builtin_strcpy'? [-Wimplicit-function-declaration]
>     6 |   return __libc_strcpy(dst, src, false);
>       |          ^~~~~~~~~~~~~
>       |          __builtin_strcpy
> ../../../..//newlib-cygwin/newlib/libc/machine/riscv/stpcpy.c:6:10: error: returning 'int' from a function with return type 'char *' makes pointer from integer without a cast [-Wint-conversion]
>     6 |   return __libc_strcpy(dst, src, false);
>       |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> make[1]: *** [Makefile:34809: libc/machine/riscv/libc_a-stpcpy.o] Error 1



Jeff


More information about the Newlib mailing list