casaroli opened a new pull request, #20530: URL: https://github.com/apache/nuttx/pull/20530
## Summary `make export` now installs a compiler wrapper in the export package: `bin/nuttx-cc` and `bin/nuttx-c++`, with the flags of the configuration in `scripts/nuttx-cc.conf`. A program outside the tree can then be built with one compiler command: ``` nuttx-cc -O2 -o hello hello.c ./configure --host=aarch64-none-elf CC=$EXPORT/bin/nuttx-cc ``` * It compiles with `-nostdinc`, the exported headers and the compiler's own headers, so a header that NuttX does not have is reported missing and not taken from the toolchain's C library. * It keeps the CPU, ABI and define options of the configuration and leaves out its warning options (`-Werror` and others). * When it links, it adds `startup/crt0.o`, `scripts/gnu-elf.ld` (if the package has it) and, in a kernel build, the user-space libraries. Paths into the build tree, which some boards put in `LDELFFLAGS`, are left out. * In a kernel build a program is a relocatable (`-r`) ELF, and a relocatable link does not fail on an undefined symbol. Nothing resolves the symbol at load time, so the wrapper checks with `nm` and fails the link. A weak undefined symbol is allowed, as in a normal link. * It expands response files (`@file`) before it looks at the options, and drops `-pthread`: libc has the POSIX threads, and build systems such as meson and ninja pass both. * It finds the package from its own location, so the package can be moved to another computer. The first commit fixes how `mkexport.sh` removes the linker script from `LDELFFLAGS`. The pattern `-T.*ld` is greedy: it removed everything from the first `-T` to the last "ld" in the string. On xtensa, `crt0.o` comes after the script, so when the path of the tree contains "ld" (for example `.../build/nuttx`), the export got a broken `crt0.o` path that the wrapper could not leave out. Now only the `-T` options whose argument ends in `.ld` are removed. The last commit adds an empty `libpthread.a`, `librt.a` and `libdl.a` to the export of a kernel build, so that `-lpthread`, `-lrt` and `-ldl` link: libc has these functions. Documentation: `Documentation/components/tools/nuttx-cc.rst`. ## Impact `make export` and the export package only. No change to the target code. The CMake build has no export target. ## Testing * `qemu-armv8a:knsh`: export built on macOS. A test program built with `nuttx-cc` on macOS, and in a Debian arm64 container with the Linux-host Arm GNU 14.2 toolchain, runs on the target (QEMU 11) from hostfs: arguments, environment, `stat()` and floating-point `printf()` are correct. * An undefined function makes the link fail and removes the output; a weak undefined function does not; `-c` still works. * Rebased on master 17747ded0aa, `qemu-armv8a:knsh` export: `hello.c` with a thread links plain, with `-pthread`, with `-lpthread -lrt -ldl`, and through a response file (`nuttx-cc @rsp`); a link with an undefined function still fails. * `esp32s3-devkit:nsh` in a tree at `.../build-mkexport`: before the fix the export had `LDELFFLAGS = -e _start -r -mkexport/arch/xtensa/src/crt0.o`, after the fix it has the full path of `crt0.o`, and `nuttx-cc.conf` has `NUTTXCC_LDFLAGS='-e _start -r -Bstatic'` (before: `-e _start -r -mkexport/arch/xtensa/src/crt0.o -Bstatic`). * `mps2-an500:nsh` (flat build): the export works, and the wrapper compiles and links a test program (a relocatable ELF whose undefined symbols the firmware symbol table resolves). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
