Skip to content

feat(configure): enable posix_dir for *-nanvix*#13

Open
esaurez wants to merge 1 commit into
pr-base-newlib-pr4from
feat/configure-host-posix-dir-enable
Open

feat(configure): enable posix_dir for *-nanvix*#13
esaurez wants to merge 1 commit into
pr-base-newlib-pr4from
feat/configure-host-posix-dir-enable

Conversation

@esaurez
Copy link
Copy Markdown

@esaurez esaurez commented May 30, 2026

Summary

Enables posix_dir=posix for *-nanvix* in newlib/configure.host so the existing newlib/libc/posix/ translation units get compiled into libc.a, together with the matching set of newlib opt-out capability macros that keep the wider compile surface clean.

This is the change that unblocks the original rpmatch.c undefined-reference chain (regcomp, regexec, regerror, regfree) we hit while statically linking cpython on Nanvix, and adds the rest of the POSIX surface that nanvix-side code (cpython, future .so extensions) expects to find in libc.

What gets enabled

After this change, libc.a for *-nanvix* now defines (previously missing):

  • Regex family: regcomp, regerror, regexec, regfree
  • Pattern matching: fnmatch
  • Misc POSIX: sleep, isatty / _isatty, creat, alphasort

Verified by rebuilding newlib under ghcr.io/nanvix/toolchain-gcc and running i686-nanvix-nm /opt/nanvix/i686-nanvix/lib/libc.a.

Why the opt-out cflags

Setting posix_dir=posix would otherwise drag in six translation units that cannot work on Nanvix today. Each one is silenced with a standard newlib capability macro — no new macro introduced. The shape mirrors the RTEMS section at configure.host:623 which uses the same idiom for a similar capability gap.

Flag File silenced Reason
-D_NO_POSIX_SPAWN posix_spawn.c needs fork / execve; also references sigprocmask unconditionally (same root cause as the prerequisite _NO_SIGPROCMASK change on this stack's base branch)
-D_NO_POPEN popen.c needs fork + pipe + execve
-D_NO_WORDEXP wordexp.c shells out to /bin/sh
-D_NO_GLOB glob.c glob / globfree reference getpwnam, issetugid, and getlogin, none of which nanvix's libposix provides today
-D_NO_EXECVE execl.c, execle.c, execv.c, execve.c, execlp.c, execvp.c all reference the SYS_execve syscall wrapper (_execve) which nanvix's libposix does not provide today
-DHAVE_OPENDIR opendir.c, readdir.c, closedir.c, scandir.c, seekdir.c, telldir.c, rewinddir.c, dirfd.c, ftw.c, nftw.c nanvix already provides its own opendir / readdir / closedir / ... in libposix, using a different struct dirent layout (no d_reclen). Newlib's BSD-style versions assume d_reclen and won't even compile against the nanvix <sys/dirent.h>. HAVE_OPENDIR makes the newlib copies empty so the symbols resolve from libposix at link time.

The dirent split is intentional on the nanvix side — see newlib/libc/sys/nanvix/include/sys/dirent.h which defines struct dirent (POSIX-API surface: d_ino + d_name) separately from struct posix_dent (on-disk form with d_reclen + d_type). The conversion happens inside libposix's own readdir.

How the _NO_* / HAVE_* macros are used

These are pre-existing newlib idioms — posix_spawn.c, popen.c, wordexp.c and the entire opendir family already wrap their bodies in #ifndef _NO_FOO / #ifndef HAVE_FOO. We're just turning the knobs the files were already prepared for.

The same pattern is used by other newlib targets (RTEMS, several embedded ports) — git grep _NO_POPEN newlib/configure.host for precedent.

Verification

Built with this branch on top of the pr-base-newlib-pr4 base branch (which carries the _NO_SIGPROCMASK / hash_page guard change this PR's diff depends on textually):

i686-nanvix-nm /opt/nanvix/i686-nanvix/lib/libc.a | grep -E ' T (regcomp|regexec|regerror|regfree|fnmatch|sleep|isatty|_isatty|creat)$'

shows all of them defined.

i686-nanvix-nm /opt/nanvix/i686-nanvix/lib/libc.a | grep -E ' U (sigprocmask|sigfillset|posix_spawn|popen|wordexp|getpwnam|issetugid|getlogin|_execve)$'

shows none — the silenced files contribute no new undefined references.

Follow-up work (tracked separately)

  • Implementing real sigprocmask / posix_spawn / popen / wordexp / glob / execve on nanvix so these opt-outs can be removed.

Dependency

This PR depends textually on the _NO_SIGPROCMASK / hash_page change being applied first (both diffs modify the same newlib_cflags line in configure.host). The base of this PR is therefore set to pr-base-newlib-pr4, a temporary base branch built from dev + that prerequisite commit. When the prerequisite PR merges into dev, this PR can be rebased directly onto dev.

Co-authored-by: Copilot 223556219+Copilot@users.noreply.github.com

Sets posix_dir=posix for *-nanvix* and adds the matching opt-out cflags
so the wider compile surface stays clean.

Newly exposed in libc.a (previously missing): regcomp, regerror,
regexec, regfree (fixes the original rpmatch.c link failure), fnmatch,
sleep, isatty, _isatty, creat, alphasort.

Opt-out cflags added alongside posix_dir=posix, using newlib's existing
_NO_* idiom (cf. RTEMS section at configure.host:623):

- _NO_SIGPROCMASK: covered separately, kept here for completeness.
- _NO_POSIX_SPAWN: posix_spawn.c needs fork/execve which nanvix does
  not provide; also references sigprocmask unconditionally.
- _NO_POPEN: popen.c needs fork+pipe+execve.
- _NO_WORDEXP: wordexp.c shells out to /bin/sh.
- _NO_GLOB: glob.c / globfree references getpwnam, issetugid, and
  getlogin, none of which nanvix's libposix provides today.
- _NO_EXECVE: execl.c, execle.c, execv.c, execve.c, execlp.c, and
  execvp.c all reference the SYS_execve syscall wrapper (_execve)
  which nanvix's libposix does not provide today.
- HAVE_OPENDIR: nanvix already provides its own opendir/readdir/
  closedir/scandir/seekdir/telldir/rewinddir/dirfd via libposix, using
  a different struct dirent layout (no d_reclen). HAVE_OPENDIR makes
  the newlib libc/posix/{opendir,readdir,closedir,...}.c files empty
  so the symbols resolve from libposix instead of the BSD
  implementations newlib ships.

All of these are well-established newlib capability macros (already
guarded with #ifndef in the corresponding .c files); no new macro is
introduced.

Real implementations of sigprocmask / posix_spawn / popen / wordexp /
glob / execve on nanvix remain the long-term path; tracked separately.

Verification: nm /opt/nanvix/i686-nanvix/lib/libc.a confirms
- regcomp/regexec/regerror/regfree, fnmatch, sleep, isatty/_isatty,
  creat are now defined (T)
- no new U references to sigprocmask, sigfillset, posix_spawn, popen,
  wordexp, getpwnam, issetugid, getlogin, or _execve were introduced
- the trivial autoconf conftest 'int main(void) { return 0; }' links
  cleanly with the resulting libc.a + libm.a + libposix.a sysroot.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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