Skip to content

Application.mk: Sanitize PROGNAME to a valid identifier for _main symbol#3647

Open
ML-dev-crypto wants to merge 1 commit into
apache:masterfrom
ML-dev-crypto:fix-19447-hyphen-progname
Open

Application.mk: Sanitize PROGNAME to a valid identifier for _main symbol#3647
ML-dev-crypto wants to merge 1 commit into
apache:masterfrom
ML-dev-crypto:fix-19447-hyphen-progname

Conversation

@ML-dev-crypto

@ML-dev-crypto ML-dev-crypto commented Jul 16, 2026

Copy link
Copy Markdown

Summary

The build system generates an internal entry-point symbol by concatenating PROGNAME with _main. If PROGNAME contains - (for example, hello-world), the generated symbol (hello-world_main) is not a valid C identifier, causing the build to fail.

This can be reproduced by simply setting CONFIG_EXAMPLES_HELLO_PROGNAME="hello-world".

Changes

Introduce PROGSYM, a sanitized copy of PROGNAME (- replaced with _), and use it only where an internal identifier is generated.

  • Use PROGSYM for the -Dmain= compiler define used by C/C++
  • Use PROGSYM in the Zig RENAMEMAIN path
  • Use PROGSYM for the builtin entry-point symbol passed to REGISTER

The registered application name is unchanged, so applications continue to be invoked using their configured PROGNAME.

Issues

Fixes apache/nuttx#19447

Test log

Host: WSL2 Ubuntu 24.04 x86_64

Configuration: sim:nsh

Configured the hello example with a hyphenated program name:

kconfig-tweak --enable CONFIG_EXAMPLES_HELLO
kconfig-tweak --set-str CONFIG_EXAMPLES_HELLO_PROGNAME "hello-world"
make olddefconfig
make -j$(nproc)

Before this change, the build failed because hello-world_main is not a valid C identifier.

After applying this change, the build completed successfully:

Register: hello-world
...
LD:  nuttx
Pac SIM with dynamic libs..
SIM elf with dynamic libs archive in nuttx.tgz

Verified the application from NSH:

nsh> hello-world
Hello, World!!

Regression test:

kconfig-tweak --set-str CONFIG_EXAMPLES_HELLO_PROGNAME "hello"
make olddefconfig
make clean
make -j$(nproc)

Verified the default configuration still works:

nsh> hello
Hello, World!!

Program names containing '-' (e.g. renaming hello to hello-world via
PROGNAME) previously generated an invalid identifier <PROGNAME>_main
when constructing internal entry-point symbols. This caused build
failures for C/C++ applications due to invalid identifiers in compiler
definitions and generated builtin_proto.h.

Introduce PROGSYM, a sanitized copy of PROGNAME with '-' replaced by
'_', and use it wherever an internal C/Zig identifier is constructed
(the -Dmain= defines, the Zig RENAMEMAIN rule, and the REGISTER
call's entry-point argument). Preserve the original PROGNAME for the
registered NSH command name and builtin registry entry, where hyphens
are valid and expected.

The Zig RENAMEMAIN path is also updated to use PROGSYM for consistency.
The current hello_zig and leds_zig examples do not exercise this path,
since neither uses a literal 'fn main' entry point, but the change
keeps symbol generation consistent for future Zig applications.

Testing (WSL2 Ubuntu, x86_64, sim:nsh):
- CONFIG_EXAMPLES_HELLO_PROGNAME="hello-world": clean build,
  'hello-world' runs and prints 'Hello, World!!'
- Reverted to default PROGNAME="hello": clean build, no regression
- Confirmed by inspection that RENAMEMAIN's sed substitution does not
  fire on either current .zig source (generated _tmp.zig is
  byte-identical to the source)

Fixes #19447

Signed-off-by: Ansh Rai <anshrai331@gmail.com>
Comment thread Application.mk
NLIST := $(shell seq 1 $(words $(PROGNAME)))
$(foreach i, $(NLIST), \
$(eval PROGNAME_$(word $i,$(PROGOBJ)) := $(word $i,$(PROGNAME))) \
$(eval PROGSYM_$(word $i,$(PROGOBJ)) := $(subst -,_,$(word $i,$(PROGNAME)))) \

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.

please fix cmake too

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.

[BUG] Apps program name cannot include "-"

2 participants