Skip to content

Application.mk: Give the program attributes to gcc with -Wl,. - #3884

Open
casaroli wants to merge 1 commit into
apache:masterfrom
casaroli:module-ldflags-driver
Open

casaroli wants to merge 1 commit into
apache:masterfrom
casaroli:module-ldflags-driver

Conversation

@casaroli

@casaroli casaroli commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

With CONFIG_LTO_FULL (GCC), LD is the compiler driver, and the Make build links each loadable module (and each program of a kernel build) with it, because MODULELD defaults to LD. Application.mk gives the program attributes as --defsym nx_stacksize=..., and gcc stops with unrecognized command-line option '--defsym'.

Where Application.mk sets MODLDFLAGS, it now also sets MODDEFSYM: -Wl,--defsym= when MODULELD is gcc or clang, and --defsym= for ld.

The other part of the earlier version (-flinker-output=nolto-rel and the module options in Make.defs) moved to NuttX, where the flags are first set, as asked in the review: apache/nuttx#20846. A module with LTO links only with both PRs.

depends-on: apache/nuttx/pull/20846

Impact

Only builds with CONFIG_LTO_FULL and a module or a kernel build: the modules link. A link with ld gets --defsym=sym=value in place of --defsym sym value, which GNU ld and ld.lld read the same way.

Testing

qemu-armv8a:nsh (flat, Arm GNU 14.2, QEMU HVF) with CONFIG_LTO_FULL, CONFIG_ELF, CONFIG_EXECFUNCS_SYSTEM_SYMTAB and CONFIG_EXAMPLES_HELLO=m, rebased on apps master: the link of hello has -Wl,--defsym=nx_stacksize=... and -Wl,--defsym=nx_priority=... and builds; with apache/nuttx#20846 hello loads and prints Hello, World!! (on nuttx master the module keeps LTO data only and fails with exec failed: 22). The earlier version ran the TLS tests and a Library.mk shared library with LTO on qemu-armv8a:nsh and mps2-an500:nsh, and the same programs without LTO (--defsym= with ld).

tools/checkpatch.sh -c -u -m -g passes.

cederom
cederom previously approved these changes Oct 19, 2026

@cederom cederom left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @casaroli :-)

Comment thread Application.mk Outdated
Comment thread Library.mk Outdated
Comment thread Make.defs Outdated
With CONFIG_LTO_FULL (GCC), LD is the compiler driver, and a loadable
module (and a program of a kernel build) is linked with it, because
MODULELD defaults to LD.  Application.mk gave the program attributes
as "--defsym nx_stacksize=...", and gcc stopped with "unrecognized
command-line option '--defsym'".

Where Application.mk sets MODLDFLAGS, it now also sets MODDEFSYM:
"-Wl,--defsym=" when MODULELD is gcc or clang, and "--defsym=" for ld.
A link with ld gets "--defsym=sym=value" in place of "--defsym sym
value", which GNU ld and ld.lld read the same way.

Assisted-by: Claude Code:claude-opus-5-5
Signed-off-by: Marco Casaroli <marco.casaroli@gmail.com>
@casaroli
casaroli force-pushed the module-ldflags-driver branch from af0ef1f to 85fdedd Compare October 20, 2026 22:40
@casaroli casaroli changed the title build: Link a module through the compiler driver with LTO. Application.mk: Give the program attributes to gcc with -Wl,. Oct 20, 2026
@casaroli
casaroli marked this pull request as draft October 20, 2026 23:06
@github-actions

Copy link
Copy Markdown

🔗 Cross-repo PR dependencies

The read-only Build run reported the following dependent PR(s) and fetched head SHA(s):

CI run: https://github.com/apache/nuttx-apps/actions/runs/39509862159

@casaroli casaroli closed this Oct 22, 2026
@casaroli casaroli reopened this Oct 22, 2026
@casaroli
casaroli marked this pull request as ready for review October 22, 2026 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants