"%" PRIu8 expands to %hhu with -specs=nano.specs

Asked by Brob on 2018-03-06

Since nano.spec doesn't support all scanf/print format specifiers, I would expect that when using nano.specs the appropriate format specifier are being used. From the object files I however can see that "%" PRIu8 still expands to %hhu.

Am I missing something in this? Are any additional defines required to make the compiler / pre-processor use the correct defines?

Question information

Language:
English Edit question
Status:
Solved
For:
GNU Arm Embedded Toolchain Edit question
Assignee:
No assignee Edit question
Solved by:
Andre Vieira
Solved:
2018-03-06
Last query:
2018-03-06
Last reply:
2018-03-06
Tejas Belagod (belagod-tejas) said : #1

Hi,

Can you please construct a minimal test case that demonstrates the unexpected behaviour. Please also mention explicitly what headers you're including and a gcc compilation command line with '-v' that shows which headers are getting pulled in.

Thanks,
Tejas.

Brob (tlj-debrouwer) said : #2

Hello Tejas,

Thanks for the prompt response, hereby:

Code:
#include <inttypes.h>
#include <stdio.h>

int main()
{
    printf("%" PRIu8 "-%" PRIu8 "-%" PRIu8, 1, 2, 4);
}

This is the compiler output (including the command):
"/usr"/bin/arm-none-eabi-g++ -v -Os -specs=nano.specs -nostdlib -fno-strict-aliasing -fno-exceptions -ffunction-sections -fdata-sections -c -Wall -Wno-unknown-pragmas -Wno-psabi -x none -D"NDEBUG" -DTARGET_STM32 -mcpu=cortex-m3 -mthumb -o test.o -std=gnu++0x test.cpp
Using built-in specs.
Reading specs from /usr/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/nano.specs
rename spec link to nano_link
rename spec link_gcc_c_sequence to nano_link_gcc_c_sequence
rename spec cpp_unique_options to nano_cpp_unique_options
COLLECT_GCC=/usr/bin/arm-none-eabi-g++
Target: arm-none-eabi
Configured with: /tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/src/gcc/configure --target=arm-none-eabi --prefix=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/install-native --libexecdir=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/install-native/lib --infodir=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/install-native/share/doc/gcc-arm-none-eabi/info --mandir=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/install-native/share/doc/gcc-arm-none-eabi/man --htmldir=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/install-native/share/doc/gcc-arm-none-eabi/html --pdfdir=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/install-native/share/doc/gcc-arm-none-eabi/pdf --enable-languages=c,c++ --enable-plugins --disable-decimal-float --disable-libffi --disable-libgomp --disable-libmudflap --disable-libquadmath --disable-libssp --disable-libstdcxx-pch --disable-nls --disable-shared --disable-threads --disable-tls --with-gnu-as --with-gnu-ld --with-newlib --with-headers=yes --with-python-dir=share/gcc-arm-none-eabi --with-sysroot=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/install-native/arm-none-eabi --build=x86_64-linux-gnu --host=x86_64-linux-gnu --with-gmp=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/build-native/host-libs/usr --with-mpfr=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/build-native/host-libs/usr --with-mpc=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/build-native/host-libs/usr --with-isl=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/build-native/host-libs/usr --with-libelf=/tmp/jenkins/jenkins-GCC-7-build_toolchain_docker-633_20171130_1512067137/build-native/host-libs/usr --with-host-libstdcxx='-static-libgcc -Wl,-Bstatic,-lstdc++,-Bdynamic -lm' --with-pkgversion='GNU Tools for Arm Embedded Processors 7-2017-q4-major' --with-multilib-list=rmprofile
Thread model: single
gcc version 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204] (GNU Tools for Arm Embedded Processors 7-2017-q4-major)
COLLECT_GCC_OPTIONS='-v' '-Os' '-specs=nano.specs' '-nostdlib' '-fno-strict-aliasing' '-fno-exceptions' '-ffunction-sections' '-fdata-sections' '-c' '-Wall' '-Wno-unknown-pragmas' '-Wno-psabi' '-D' 'NDEBUG' '-D' 'TARGET_STM32' '-mcpu=cortex-m3' '-mthumb' '-o' 'test.o' '-std=gnu++11'
 /usr/bin/../lib/gcc/arm-none-eabi/7.2.1/cc1plus -isystem =/include/newlib-nano -quiet -v -imultilib thumb/v7-m -iprefix /usr/bin/../lib/gcc/arm-none-eabi/7.2.1/ -isysroot /usr/bin/../arm-none-eabi -D__USES_INITFINI__ -D NDEBUG -D TARGET_STM32 test.cpp -quiet -dumpbase test.cpp -mcpu=cortex-m3 -mthumb -auxbase-strip test.o -Os -Wall -Wno-unknown-pragmas -Wno-psabi -std=gnu++11 -version -fno-strict-aliasing -fno-exceptions -ffunction-sections -fdata-sections -o /tmp/ccq3HLns.s
GNU C++11 (GNU Tools for Arm Embedded Processors 7-2017-q4-major) version 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204] (arm-none-eabi)
 compiled by GNU C version 4.8.4, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.15-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
ignoring duplicate directory "/usr/bin/../lib/gcc/../../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/include/c++/7.2.1"
ignoring duplicate directory "/usr/bin/../lib/gcc/../../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/include/c++/7.2.1/arm-none-eabi/thumb/v7-m"
ignoring duplicate directory "/usr/bin/../lib/gcc/../../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/include/c++/7.2.1/backward"
ignoring duplicate directory "/usr/bin/../lib/gcc/../../lib/gcc/arm-none-eabi/7.2.1/include"
ignoring nonexistent directory "/usr/bin/../arm-none-eabi/usr/local/include"
ignoring duplicate directory "/usr/bin/../lib/gcc/../../lib/gcc/arm-none-eabi/7.2.1/include-fixed"
ignoring duplicate directory "/usr/bin/../lib/gcc/../../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/include"
ignoring nonexistent directory "/usr/bin/../arm-none-eabi/usr/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/bin/../arm-none-eabi/include/newlib-nano
 /usr/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/include/c++/7.2.1
 /usr/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/include/c++/7.2.1/arm-none-eabi/thumb/v7-m
 /usr/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/include/c++/7.2.1/backward
 /usr/bin/../lib/gcc/arm-none-eabi/7.2.1/include
 /usr/bin/../lib/gcc/arm-none-eabi/7.2.1/include-fixed
 /usr/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/include
End of search list.
GNU C++11 (GNU Tools for Arm Embedded Processors 7-2017-q4-major) version 7.2.1 20170904 (release) [ARM/embedded-7-branch revision 255204] (arm-none-eabi)
 compiled by GNU C version 4.8.4, GMP version 6.1.0, MPFR version 3.1.4, MPC version 1.0.3, isl version isl-0.15-GMP

GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 92377522f4e1721a565bc0ceff793996
COLLECT_GCC_OPTIONS='-v' '-Os' '-specs=nano.specs' '-nostdlib' '-fno-strict-aliasing' '-fno-exceptions' '-ffunction-sections' '-fdata-sections' '-c' '-Wall' '-Wno-unknown-pragmas' '-Wno-psabi' '-D' 'NDEBUG' '-D' 'TARGET_STM32' '-mcpu=cortex-m3' '-mthumb' '-o' 'test.o' '-std=gnu++11'
 /usr/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/as -v -mcpu=cortex-m3 -meabi=5 -o test.o /tmp/ccq3HLns.s
GNU assembler version 2.29.51 (arm-none-eabi) using BFD version (GNU Tools for Arm Embedded Processors 7-2017-q4-major) 2.29.51.20171128
COMPILER_PATH=/usr/bin/../lib/gcc/arm-none-eabi/7.2.1/:/usr/bin/../lib/gcc/:/usr/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/bin/
LIBRARY_PATH=/usr/bin/../lib/gcc/arm-none-eabi/7.2.1/thumb/v7-m/:/usr/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/thumb/v7-m/:/usr/bin/../arm-none-eabi/lib/thumb/v7-m/:/usr/bin/../lib/gcc/arm-none-eabi/7.2.1/:/usr/bin/../lib/gcc/:/usr/bin/../lib/gcc/arm-none-eabi/7.2.1/../../../../arm-none-eabi/lib/:/usr/bin/../arm-none-eabi/lib/
COLLECT_GCC_OPTIONS='-v' '-Os' '-specs=nano.specs' '-nostdlib' '-fno-strict-aliasing' '-fno-exceptions' '-ffunction-sections' '-fdata-sections' '-c' '-Wall' '-Wno-unknown-pragmas' '-Wno-psabi' '-D' 'NDEBUG' '-D' 'TARGET_STM32' '-mcpu=cortex-m3' '-mthumb' '-o' 'test.o' '-std=gnu++11'

this is the observed hex output %hhu-%hhu-%hhu for "%" PRIu8 "-%" PRIu8 "-%" PRIu8

Hi Brob,

This has been reported upstream earlier:
https://sourceware.org/ml/newlib/2016/msg00000.html

If you follow the thread it is explained why using hhu is correct for PRIu8 regardless of whether C99 types IO is supported.

Hope that helps.

Kind Regards,
Andre

Brob (tlj-debrouwer) said : #4

That is a lengthy conversation. Thanks for pointing to that!

Brob (tlj-debrouwer) said : #5

Thanks Andre Vieira, that solved my question.