Skip to content

[nanvix] fix(z): sanitize in-source libc headers for C++ runtimes#34

Merged
ppenna merged 1 commit into
nanvix/v21.0.0from
bugfix-stage1-cxx-libc-headers
Jun 30, 2026
Merged

[nanvix] fix(z): sanitize in-source libc headers for C++ runtimes#34
ppenna merged 1 commit into
nanvix/v21.0.0from
bugfix-stage1-cxx-libc-headers

Conversation

@ppenna

@ppenna ppenna commented Jun 30, 2026

Copy link
Copy Markdown

Problem

The #33 merge cleared the stage-1 configure stage; the build then failed compiling libunwind against the in-source Nanvix libc headers, which are C-only and don't parse as C++:

/opt/nanvix/usr/include/stdio.h:113: error: invalid parameter name: 'new' is a keyword
/opt/nanvix/usr/include/stdlib.h:92:  error: expected ')'        # the C99 'restrict' keyword
/opt/nanvix/usr/include/stdlib.h:163: error: invalid parameter name: 'template' is a keyword

libunwind, libc++ and libc++abi include these C headers from C++, so they must parse as C++.

Fix

Sanitize the staged sysroot copy of the headers right after staging (in z's download_steps):

  • restrict (C99, not a C++ keyword) → __restrict (valid in both C and C++);
  • drop C++-keyword parameter names (new, template) — parameter names in prototypes are optional, so this is purely syntactic.

Scope is tiny — restrict: 2 files; new: 1 decl; template: 4 decls — and harmless for compiler-rt's C consumers (both forms are valid in C).

Validation

  • bash -n z clean.
  • Verified with clang++ -fsyntax-only that the sanitized declarations parse cleanly, while the originals reproduce the exact CI errors.

Caveat

Iterative stage-1 bring-up: this clears the libunwind header blocker. The remaining libc++/libc++abi compile + link against the in-source libc may surface further issues, which I'll fix in follow-up iterations. Validated on merge (PR CI verifies stage 0 only).

The stage-1 build (PR #33 merge) got past configure and then failed
compiling libunwind against the in-source Nanvix libc headers, which are
C-only and break C++ parsing:

  stdio.h:113  error: invalid parameter name: 'new' is a keyword
  stdlib.h:92  error: expected ')'      (the C99 'restrict' keyword)
  stdlib.h:163 error: invalid parameter name: 'template' is a keyword

libunwind, libc++ and libc++abi include these C headers from C++, so they
must parse as C++. Sanitize the staged sysroot copy right after staging:
- map 'restrict' (C99, not a C++ keyword) to '__restrict' (valid in C and C++);
- drop C++-keyword parameter names ('new', 'template'); parameter names in
  prototypes are optional, so this is purely syntactic.

Scope is tiny (restrict: 2 files; new: 1 decl; template: 4 decls) and the
rewrite is harmless for compiler-rt's C consumers. Verified with clang++ that
the sanitized declarations parse cleanly while the originals reproduce the
exact CI errors.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@ppenna ppenna merged commit 252078d into nanvix/v21.0.0 Jun 30, 2026
1 check passed
@ppenna ppenna deleted the bugfix-stage1-cxx-libc-headers branch June 30, 2026 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant