casaroli opened a new pull request, #20805: URL: https://github.com/apache/nuttx/pull/20805
## Summary ldnxflat converted some modules into a broken image with no message. The NXFLAT linker scripts give an address only to the sections that they name. `ld -r` keeps each member of a section group (a C++ COMDAT group) as a section of its own, and it leaves `.init_array`, `.fini_array`, `.tdata` and `.tbss` unplaced too. Such a section stays at address zero, on top of `.text` or `.data`, and moves the sections that follow it. ldnxflat copied all of them into the image. Examples: a C++ module with the static `thread_local` member of a class template has its emutls control objects in two COMDAT groups. ld put both at D-Space 0 and `.bss` at 0x10, inside `.data`, and `exec()` of the module failed. `hello++3` of apps/examples/nxflat has its `.init_array` at D-Space 0 and its `.bss` at 4, and nothing runs its constructor. This PR: - tools/nxflat/ldnxflat: Refuse a module with `.init_array`, `.fini_array` or `.preinit_array`. Nothing runs these arrays in an NXFLAT module. - tools/nxflat/ldnxflat: Place the sections in ldnxflat, in the order of the section headers, data before `.bss`, and do not use the addresses of the linker script. Group members then get their own place. - tools/nxflat/ldnxflat: Refuse native TLS (`.tdata`, `.tbss`) with a message that says to use a toolchain that emulates TLS. Before, the module failed at the first TLS relocation with "arm relocation 104 ... is not handled". - tools/nxflat/testsuite.sh: Show the message of a failed conversion. The column was empty because ldnxflat does not write "error". - Documentation: The NXFLAT page gets two limitations (emulated TLS only, no static constructors) and says that ldnxflat places the sections. With a toolchain that emulates TLS (arm-none-eabi 13.2, as in CI), `__thread` and `thread_local` already work in an NXFLAT module: the module imports `__emutls_get_address()` like any other function, and its control objects and templates are relocated correctly. The new tests are in a nuttx-apps PR (APPSPR). ## Impact Host tool and documentation only. All modules of apps/examples/nxflat that converted before convert to the same bytes. `hello++3` (not built by default) is now refused instead of converted wrong. ## Testing lm3s6965-ek:qemu-nxflat with arm-none-eabi 13.2, `CONFIG_HAVE_CXX=y`, under `qemu-system-arm -M lm3s6965evb`, with the tests of APPSPR: | module | master | master + #20723 | this PR | this PR + #20723 | |---|---|---|---|---| | errno, hello, longjmp, mutex, pthread, signal, struct, task | PASS | PASS | PASS | PASS | | tls, main thread | PASS | PASS | PASS | PASS | | tls, second thread | FAIL | PASS | FAIL | PASS | | tlsxx | `exec()` fails, ENOENT | `exec()` fails, ENOENT | loads, second thread FAIL | PASS | The checks of the second thread pass only when the base code keeps a copy of each `__thread` variable per thread. libgcc's emutls keeps one copy for all threads; #20723 adds a per-thread copy to libc. With this PR and #20723, both modules pass with both linker scripts (`gnu-nxflat-pcrel.ld` and `gnu-nxflat-gotoff.ld`). `tools/nxflat/testsuite.sh` (gotoff): all modules convert as before; `hello++3` now fails with ".init_array holds static constructors or destructors, which an NXFLAT module cannot run". With arm-none-eabi 15.3 (native TLS), tls fails with ".tbss holds native TLS, which an NXFLAT module cannot use; build it with a toolchain that emulates TLS". `tools/checkpatch.sh -c -u -m -g` passes. -- 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]
