embeddedartistry / libc

libc targeted for embedded systems usage. Reduced set of functionality (due to embedded nature). Chosen for portability and quick bringup.
MIT License
495 stars 66 forks source link

Error building libc for Cross ARM Cortex-M4F #194

Open tdyjv opened 1 month ago

tdyjv commented 1 month ago

I'm attempting to compile libc for an STM32L4R5 (Cortex-M4F) on a Linux system running kubuntu 22.04 I cloned the latest libc from the GitHub repo. I am completely new to using the meson build system, but am willing to learn. Any help would be appreciated.

After cloning the libc repo...

$ make distclean
$ make default CROSS=arm:cortex-m4_hardfloat

It seems to fail trying to compile cmocka for the ARM STM32 complaining about a missing setjmp.h which I assume should be provided by the local libc headers not the system. setjmp.h is in the libc/include directory. The compiler invocation to compile cmocka.c does not include any reference to the local header files. Is there a simple way to add the local libc headers to the cmocka.c build command ljne ? The complete meson-log.txt file is attached here, but I don't see any reference to cmocka.c there so I'm not sure how helpful that will be.

Here is the final line of output from the build attempt

...
Embedded Artistry libc 1.0

  Subprojects
    cmocka     : YES

  User defined options
    Cross files: meson/cross/arm.txt
                 meson/cross/cortex-m4_hardfloat.txt

Found ninja-1.10.1 at /usr/bin/ninja
ninja: Entering directory `buildresults'                                                                                                                                                    
[1/543] Compiling C object subprojects/cmocka-1.1.5/src/libcmocka.so.0.5.0.p/cmocka.c.o
FAILED: subprojects/cmocka-1.1.5/src/libcmocka.so.0.5.0.p/cmocka.c.o 
arm-none-eabi-gcc -Isubprojects/cmocka-1.1.5/src/libcmocka.so.0.5.0.p -Isubprojects/cmocka-1.1.5/src -I../subprojects/cmocka-1.1.5/src -I../subprojects/cmocka-1.1.5/include -Isubprojects/cmocka-1.1.5/private -I../subprojects/cmocka-1.1.5/private -fdiagnostics-color=always -D_FILE_OFFSET_BITS=64 -Wall -Winvalid-pch -Wextra -Wpedantic -std=gnu99 -O2 -Wshadow -Wmissing-prototypes -Wcast-align -Werror=address -Werror=strict-prototypes -Werror=write-strings -Werror=implicit-function-declaration -Werror=pointer-arith -Werror=declaration-after-statement -Werror=return-type -Werror=uninitialized -Wimplicit-fallthrough -Werror=strict-overflow -Wstrict-overflow=2 -Wno-format-zero-length -Wformat -fno-common -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -mabi=aapcs -mthumb -fPIC -DHAVE_CONFIG_H=1 -MD -MQ subprojects/cmocka-1.1.5/src/libcmocka.so.0.5.0.p/cmocka.c.o -MF subprojects/cmocka-1.1.5/src/libcmocka.so.0.5.0.p/cmocka.c.o.d -o subprojects/cmocka-1.1.5/src/libcmocka.so.0.5.0.p/cmocka.c.o -c ../subprojects/cmocka-1.1.5/src/cmocka.c
../subprojects/cmocka-1.1.5/src/cmocka.c:39:10: fatal error: setjmp.h: No such file or directory
   39 | #include <setjmp.h>
      |          ^~~~~~~~~~
compilation terminated.
[13/543] Compiling C object subprojects/cmocka-1.1.5/src/libcmocka_native.so.0.5.0.p/cmocka.c.o
../subprojects/cmocka-1.1.5/src/cmocka.c: In function ‘cmocka_run_one_test_or_fixture’:
../subprojects/cmocka-1.1.5/src/cmocka.c:2768:9: warning: variable ‘rc’ might be clobbered by ‘longjmp’ or ‘vfork’ [-Wclobbered]
 2768 |     int rc = 0;
      |         ^~
[14/543] Compiling C++ object printf_tests.p/printf_test_test_suite.cpp.o
ninja: build stopped: subcommand failed.
make: *** [Makefile:57: default] Error 1

meson-log.txt

phillipjohnston commented 1 month ago

Looks like a behavioral change in Meson is causing CMocka to fail to cross-compile (previously, it was not being compiled). Working on a fork of the build rules for that project, and then will adjust this repo to use the forked version.

phillipjohnston commented 1 month ago

https://github.com/mesonbuild/meson/issues/12530

tdyjv commented 1 month ago

Would there be a quick workaround to disable the cmocka cross build ?

phillipjohnston commented 1 month ago

Just completed the changes and pushed to the repo if you want to give that a try.

tdyjv commented 1 month ago

Thanks for the quick response, libc seems to have completed. I will start on the stdc++ libs now.

I had an additional error earlier in test/meson.build at line 156 which I had to change to "native_map_file.format(meson.current_build_dir()+'/sample_app')," to continue. Not sure if that was the right thing to do or not, but it got me further.

phillipjohnston commented 1 month ago

Do you recall the error? Was that in the skeleton?

tdyjv commented 1 month ago

Output from make.....

Dependency cmocka from subproject subprojects/cmocka-1.1.7 found: YES 1.1.7
Program arm-none-eabi-objcopy found: YES (/home/jvolpe/arm-tools/bin/arm-none-eabi-objcopy)
Message: Native objcopy program not available, .hex and .bin conversion targets will be disabled.
Compiler for C supports arguments -nostdinc: YES 
Compiler for C supports arguments -fno-builtin: YES 
Compiler for C supports arguments -nostdinc: YES 
Compiler for C supports arguments -fno-builtin: YES 
Compiler for C supports arguments -nolibc: YES 
Compiler for C supports arguments -nolibc: YES (cached)
Compiler for C supports arguments -nolibc: YES (cached)
Compiler for C supports arguments -nostartfiles: YES 
Compiler for C supports arguments -nolibc: YES (cached)
Compiler for C supports arguments -Wno-unused-parameter: YES 
Compiler for C supports arguments -Wno-stringop-truncation: YES 
Compiler for C supports arguments -Wno-stringop-overflow: YES 
Message: Some tests are disabled when builtins and/or optimizations are enabled.
Program arm-none-eabi-objcopy found: YES (/home/jvolpe/arm-tools/bin/arm-none-eabi-objcopy)

test/meson.build:156:12: ERROR: Unknown method "format" in object <[ArrayHolder] holds [list]: []> of type ArrayHolder.

A full log can be found at /home/jvolpe/Projects/libc/buildresults/meson-logs/meson-log.txt
make: *** [Makefile:80: buildresults/build.ninja] Error 1