Application.mk: Sanitize PROGNAME to a valid identifier for _main symbol#3647
Open
ML-dev-crypto wants to merge 1 commit into
Open
Application.mk: Sanitize PROGNAME to a valid identifier for _main symbol#3647ML-dev-crypto wants to merge 1 commit into
ML-dev-crypto wants to merge 1 commit into
Conversation
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>
| 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)))) \ |
Contributor
There was a problem hiding this comment.
please fix cmake too
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The build system generates an internal entry-point symbol by concatenating
PROGNAMEwith_main. IfPROGNAMEcontains-(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 ofPROGNAME(-replaced with_), and use it only where an internal identifier is generated.PROGSYMfor the-Dmain=compiler define used by C/C++PROGSYMin the ZigRENAMEMAINpathPROGSYMfor the builtin entry-point symbol passed toREGISTERThe 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:nshConfigured the hello example with a hyphenated program name:
Before this change, the build failed because
hello-world_mainis not a valid C identifier.After applying this change, the build completed successfully:
Verified the application from NSH:
Regression test:
Verified the default configuration still works: