Broken RISC-V code in newlib

Jeff Law jlaw@ventanamicro.com
Tue Mar 25 17:01:13 GMT 2025


On 3/25/25 9:19 AM, Eric Salem wrote:
> On 3/25/25 10:14 AM, Kito Cheng wrote:
>> BTW, I can reproduce those build issue on my clean build as well
> 
> Are there any sort of flags you set for your build? I build a stock Newlib
> library but I still can't get the build to break for me. I'm wondering how
> it knows to use the port specific includes when <> is used to include the
> header file for my build and not yours.
Nothing particularly special.

You may be running into headers being pulled out of a pre-existing 
install directory or something along those lines.

You can add "-save-temps" to gcc invocation which will save the .i (cpp 
output).  Within the .i file you can look at the line markers to tell 
you what files where used to satisfy any particular #include.  It's 
painful, but works.

Or you can add "-v" to a gcc invocation to print the command line as 
well as various internal information:

> jlaw@k1:~$ gcc -v j.c
> Using built-in specs.
> COLLECT_GCC=gcc
> COLLECT_LTO_WRAPPER=/usr/libexec/gcc/riscv64-linux-gnu/14/lto-wrapper
> Target: riscv64-linux-gnu
> Configured with: ../src/configure -v --with-pkgversion='Debian 14.2.0-17' --with-bugurl=file:///usr/share/doc/gcc-14/README.Bugs --enable-languages=c,ada,c++,go,d,fortran,objc,obj-c++,m2,rust --prefix=/usr --with-gcc-major-version-only --program-suffix=-14 --program-prefix=riscv64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/libexec --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-libstdcxx-backtrace --enable-gnu-unique-object --disable-libquadmath --disable-libquadmath-support --enable-plugin --enable-default-pie --with-system-zlib --enable-libphobos-checking=release --with-target-system-zlib=auto --enable-objc-gc=auto --enable-multiarch --disable-werror --disable-multilib --with-arch=rv64gc --with-abi=lp64d --enable-checking=release --build=riscv64-linux-gnu --host=riscv64-linux-gnu --target=riscv64-linux-gnu --with-build-config=bootstrap-lto-lean --enable-link-serialization=2
> Thread model: posix
> Supported LTO compression algorithms: zlib zstd
> gcc version 14.2.0 (Debian 14.2.0-17) 
> COLLECT_GCC_OPTIONS='-v' '-march=rv64imafdc_zicsr_zifencei' '-mabi=lp64d' '-misa-spec=20191213' '-mtls-dialect=trad' '-march=rv64imafdc_zicsr_zifencei' '-dumpdir' 'a-'
>  /usr/libexec/gcc/riscv64-linux-gnu/14/cc1 -quiet -v -imultilib . -imultiarch riscv64-linux-gnu j.c -quiet -dumpdir a- -dumpbase j.c -dumpbase-ext .c -march=rv64imafdc_zicsr_zifencei -mabi=lp64d -misa-spec=20191213 -mtls-dialect=trad -march=rv64imafdc_zicsr_zifencei -version -o /tmp/ccAChyBE.s
> GNU C17 (Debian 14.2.0-17) version 14.2.0 (riscv64-linux-gnu)
>         compiled by GNU C version 14.2.0, GMP version 6.3.0, MPFR version 4.2.1, MPC version 1.3.1, isl version isl-0.26-GMP
> 
> GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
> ignoring nonexistent directory "/usr/local/include/riscv64-linux-gnu"
> ignoring nonexistent directory "/usr/lib/gcc/riscv64-linux-gnu/14/include-fixed/riscv64-linux-gnu"
> ignoring nonexistent directory "/usr/lib/gcc/riscv64-linux-gnu/14/include-fixed"
> ignoring nonexistent directory "/usr/lib/gcc/riscv64-linux-gnu/14/../../../../riscv64-linux-gnu/include"
> #include "..." search starts here:
> #include <...> search starts here:
>  /usr/lib/gcc/riscv64-linux-gnu/14/include
>  /usr/local/include
>  /usr/include/riscv64-linux-gnu
>  /usr/include
> End of search list.


Note the last few lines.  Those show the search paths for <> includes. 
Obviously you'd need to add this to the line used when building the 
problematic file in newlib.

Jeff

ps.  And to be clear, the output above is on a native riscv64 system, 
not a cross :-)  I just wanted to show you that "-v" might help answer 
your question.


More information about the Newlib mailing list