Skip to content

macOS: GNU upstream gate 48/86 — catalog of remaining divergences #3605

Open

Description

@caomengxuan666

macOS: GNU upstream gate 48/86 — catalog of remaining divergences

Follow-up to #3585 (Mach-O exec gate, PR #3586). After that fix, niu on macOS can execute external commands again, but the niubash GNU upstream gate (scripts/run-bash-upstream-with-niubash.sh, 86 suites, GNU bash .tests/.right from third_party/bash) still reports 48/86.

This issue is a tracking catalog: the 38 failing suites below are grouped by suspected root cause so they can be picked off in individual PRs.

Environment: macOS 26.6.2 arm64, niubash master (8e596cf), rubash master (6edb24c5) + PR #3586. Gate run with GNU userland (coreutils/findutils/gnu-sed/diffutils/gawk via brew). Test-side harness gaps already fixed locally: compiled recho/printenv/zecho/xcase from support/, ran ./configure + make version.h in the vendored bash tree. Not verified whether each failure also reproduces on Windows/WSL — some are likely platform-agnostic engine gaps.

A. Hard crash (highest priority)

  • run-glob-bracket — ${THIS_SH} ./glob-bracket.tests dies with Segmentation fault: 11 under niu. Also diverges on extglob dir patterns: #20: pat=*@(/)cd/efg yes/no vs GNU no/no.

B. Diagnostic line numbers off-by-one (largest class)

GNU and niu report different source line numbers for parse errors and warnings:

  • run-alias — line 6 vs GNU line 7 for `do' syntax error
  • run-braces — comsub EOF error line 57 vs line 59
  • run-exportfunc — eval: line 84 vs line 83
  • run-func — `sys$read': not a valid identifier at line 29 vs line 31
  • run-heredoc — heredoc warnings at wrong lines (line 52/97 vs 98/99); ed ${TMPDIR}/foo > /dev/null <<EOF traced in different token order
  • run-nquote — quux: command not found at line 8 vs line 6
  • run-vredir — redirection error reported with line 13 prefix vs none; extra &0: Invalid argument line

C. Diagnostic program name (niu: vs bash:)

Possibly harness-inherent (.right files were generated by bash; niu prints its own $0), but the diffs are real in the gate:

  • run-arith-for — niu: -c: line 1: vs bash: -c: line 1:
  • run-execscript — niu: notthere: vs /tmp/bash: notthere:; also stream did not contain valid UTF-8 where GNU reads the file fine, and missing notthere: command not found diagnostics
  • run-invocation — niu: .: Is a directory vs .: .: Is a directory; cannot execute: required file not found vs bad interpreter wording; missing bash_logout handling

D. Word/parser semantic divergences

  • run-comsub-posix — big miss: line 2: syntax error near unexpected token ')' vs 70+ lines of expected output
  • run-posixexp, run-posixexp2 — ${x##'}-class brace/quoting edge cases; unexpected EOF while looking for matching '"'
  • run-new-exp — cat <(echo a) parsed as literal words (cat: '<(echo': No such file or directory) — process substitution not recognized in this context
  • run-dollars — $*/$@ quoting: <123 abc def ghi\ 456> vs <123 abc> <def> <ghi\ 456>; $$/$? value differences
  • run-parser — AAA\ line-continuation edge
  • run-errors — comsub error context reprint differs (: $( for z in 1 2 3; done )')

E. Glob/quoting character handling

  • run-glob-test — \u03B1 unicode escapes emitted literally (<A\u03B1B>) instead of decoded
  • run-nquote4 — high-byte chars printed as UTF-8 (abÞ) vs GNU raw byte output
  • run-nquote, run-posixexp*, run-glob-bracket (see A)

F. Arithmetic

  • run-arith — empty operand: niu errors arithmetic syntax error: operand expected where GNU produces declare -a a=([0]="16"); `a[]': not a valid identifier ordering
  • run-arith-for — see C (name prefix) plus ;' unexpected wording

G. Arrays / variables / declare output

  • run-array — ${f[@]} unquoted join vs split: single element " bdef hello world test ninth element" vs 4 elements; c[-2]: bad array subscript vs readonly variable
  • run-assoc — (was recho-bound, residual diffs)
  • run-attr — extra readonly variable errors vs GNU behavior
  • run-varenv — assoc member ordering: [one][zero] vs [zero][one]; readonly enforcement
  • run-nameref — declare output ordering/dup lines

H. Builtins

  • run-builtins — help listing truncated at column ~80 (expected full lines)
  • run-complete — extra env completion entries
  • run-shopt — shopt -s dumps embedded diff text (1,38c1,20 block inside output)
  • run-comsub2 — alias e= redefine ordering in output
  • run-printf — printf: Value too large for defined data type vs GNU printing XY
  • run-read, run-test — /dev/tty: No such device or address (non-interactive tty handling)
  • run-rsh — restricted mode missing: /bin/sh: restricted, sh: not found
  • run-history — fc: no command found, exit-code reporting (exit 42)
  • run-trap — missing exiting (EXIT trap output)
  • run-jobs — job numbering/status: [3]- Running vs [2]- Running; missing Stopped transitions
  • run-coproc — (fixed by xcase build; residual)

I. Intl / locale

  • run-intl — mbchar match vs bytematch; fr_FR.ISO8859-1 byte→\u mapping diverges wholesale (likely iconv/platform locale difference, may be environment-bound)

Suspected engine subsystems

Executor diagnostics (line tracking, $0 name), comsub/PST_NOEXPAND parse paths, ${...} quote removal, extglob/bracket matching (incl. the segfault), procsub word position, array field splitting, declare ordering, job-control state machine, /dev/tty fallback, restricted mode.

Raw logs: target/bash-upstream-tests/logs/*.unexpected.log on the test machine; happy to attach any suite's full diff on request.

Activity

  1. caomengxuan666 commented on Nov 14, 2026

    @caomengxuan666
    MemberAuthor

    开工 — 按上面 A-I 分类逐条拆 PR 修,先从 A 类(glob-bracket segfault)开始。

  2. caomengxuan666 commented on Nov 14, 2026

    @caomengxuan666
    MemberAuthor

    Root cause found for the run-glob-bracket SIGSEGV (class A).

    Minimal reproducer:

    # build strmatch.so exactly like glob-bracket.tests does (support/ Makefile flags)
    gcc -fno-common -c -o strmatch.o strmatch.c
    gcc -dynamiclib -dynamic -undefined dynamic_lookup -o strmatch.so strmatch.o
    niu -c 'enable -f ./strmatch.so strmatch; strmatch foo foo'   # -> Segmentation fault: 11

    enable -f itself works — enable -p lists strmatch. The crash is at invocation: the plugin body calls the host symbol strmatch() (declared extern in the generated .c, linked with -undefined dynamic_lookup). niu is a Rust binary and exports no such C symbol — nm -gU niu | grep strmatch is empty — so dyld binds the call site to an unbound address and the process dies at first use.

    GNU bash exports its internals for loadables (strmatch lives in lib/glob/strmatch.c -> sm_loop.c; bash is linked so loadables resolve against the running image). Matching that means exporting a C ABI from rubash/niu. A faithful first slice: #[no_mangle] extern "C" fn strmatch(pat, str, flags) mapped onto the existing sm_loop ports in src/executor/glob.rs — requires unifying FNM_PATHNAME slash rules (strmatch_pathname) with the extglob engine (gmatch/extmatch) under the FNM flag set.

    Plan: first PR = export strmatch (partial GNU loadable host-ABI coverage) + the glob-bracket suite as the diff oracle. A separate hardening question worth its own PR: enable -f should probably preflight a shared object for unresolvable flat-namespace symbols and refuse with a diagnostic instead of letting it crash at call time.

  3. added
    gnu-baseline
    on Nov 14, 2026
  4. added this to the 1.5.1 milestone on Nov 14, 2026
  5. caomengxuan666 commented on Nov 14, 2026

    @caomengxuan666
    MemberAuthor

    进度:class A(loadable 回调宿主符号崩溃)已修,draft PR https://github.com/unixwin/rubash/pull/3630。

    • 根因 1:enable -f 的插件经 -undefined dynamic_lookup 调用宿主 strmatch(),niu 不导出 C 符号 → dyld 绑到未解析地址 → 首次调用 SIGSEGV。修复:src/executor/strmatch.rs 导出 #[no_mangle] extern "C" strmatch,为 lib/glob/strmatch.c+smatch.c+sm_loop.c 完整 FNM flag 语义的的单字节移植。
    • 根因 2(附带修掉):GLOBIGNORE 的 extglob spec 此前走 conditional case 引擎,缺 pathexp.c:546 的 strmatch(FNM_PATHNAME|EXTFLAG|NOCASEGLOB) 语义——*@(/)cd/efg 错误匹配 ab/cd/efg(sm_loop.c:284-290 的 n < endp 排他界)。现 ignore_pattern_matches 统一走 strmatch 移植。

    验证:run-glob-bracket PASS(原 exit 139);run-extglob/extglob2/extglob3/globstar/quote 无回归;新增 tests/issue3605 端到端固定 PATHNAME 边界。macOS gate 48 -> 49。

  6. caomengxuan666 commented on Nov 15, 2026

    @caomengxuan666
    MemberAuthor

    进度:class H 的 run-trap(EXIT trap 末尾丢失 exiting)已修,draft PR https://github.com/unixwin/rubash/pull/3670。

    • 根因:${THIS_SH} ./trap6.sub 这类同 shell 脚本调用在库宿主上走 execute_direct_shell_script 的 in-process 路径;子脚本 EOF 时的 run_exit_trap_for_status 在共享 executor 上置位 exit_trap_ran,该 latch 无 save/restore → 父 shell 之后重新 arm 的 trap 'echo exiting' 0 在 exit 时被静默吞掉。GNU 的子 shell 是独立进程(execute_cmd.c:6139 fork+exec),run_exit_trap (trap.c:1027-1050) 只看子进程自己的 sigmodes[EXIT_TRAP]。
    • 修法:child 边界 park 父 latch、给 fresh-shell child 清零、子 run_exit_trap 后恢复——与该边界其余 per-process state 的 save/restore 契约一致。

    验证(macOS gate):run-trap PASS(diff 清零,原缺末尾 exiting);run-glob-bracket PASS 无回归;新增 tests/issue3605_this_sh_child_exit_trap.rs 固定单/多 child 下的父 latch 隔离。gate 48 -> 50(含 PR #3630 的 glob-bracket)。

    另注:PR #3630 的 3 项 CI 红均为已知系统性 issue2875_input_procsub_child_runs_as_rubash_shell(master 同红),与本改动无关。

  7. caomengxuan666 commented on Nov 15, 2026

    @caomengxuan666
    MemberAuthor

    进度:class H 的 run-printf(%.TOOBIGs inline 精度溢出)已修,draft PR https://github.com/unixwin/rubash/pull/3671。

    • 根因:GNU 的 PF()(printf.def:152-175)把整个指令原样交给宿主 libc 的 printf(3),inline 数字串由 libc 自己解析。BSD/Darwin libc 对 inline 域宽做 INT_MAX 边界检查(超界 → EOVERFLOW),但精度数字直接累加进 int 字段(xprintf.c:558-559),模 2^32 回绕:%.9223372036854775825s 按 %.17s 渲染输出 XY(vendored .right 期望)。niu 此前统一按 glibc EOVERFLOW + PRETURN 处理,丢了指令输出。
    • 修法:非 printstr 指示符的 inline 精度溢出改为二补码 i32 回绕(正值作精度、负值按"missing");inline 域宽溢出保留 EOVERFLOW + PRETURN;printstr 系(b/q/Q/T/S/C/wide)的 decodeint erange 语义不变。
    • 验证:macOS arm64 vs GNU bash 5.3.20 与 niubash gate——run-printf PASS(残余 diff 仅 Mach-O exec,见 PR fix(executor): admit Mach-O images in the exec gates on macOS (Refs #3585) #3586);新增单测固定回绕、负回绕与宽度 EOVERFLOW 边界。
    • 未验证边界:%.2147483648d 一类 INT_MAX 邻界值在 Darwin libc 上行为不一致(其 int 累加的 UB 边缘),niu 取回绕值,不去追 UB。

    PR #3630 / #3670 各 3 项 CI 红均为已知系统性 issue2875(master 同红),与本系列无关。

  8. caomengxuan666 commented on Nov 15, 2026

    @caomengxuan666
    MemberAuthor

    进度更新(class B 第一项):

    前导空行行号偏差已定位并修复 —— 是 niubash host 层 bug,不是 rubash。

    niubash-runtime Shell::execute_script_inner 对非交互输入先 script.trim() 再交给 engine,line_offset 没有补偿被剥掉的前导空行 → 首个真实命令前的每个空行都会让后续所有诊断行号偏低。实测:

    • niu -c '\ndo echo x' → line 1,GNU line 2(已验证 lexer/parser 标记 do@line2 正确,是 host 入口裁行问题)
    • 脚本文件同理(\n\ndo echo x → niu 1 / GNU 3)

    修复:保留 trim(is_empty 短路需要),把剥掉的前导换行数计入 line_offset。stdin batch 循环不受影响(它自己已经通过 lines_read 补偿)。

    Draft PR(niubash 侧): unixwin/niubash#1014 — 与 GNU bash 5.3.20 四种输入逐字节一致。

    run-alias diff 从 10 → 6 行;剩余为 class B 的 posix-mode for alias 展开差异(rubash 侧,下一个做)。其余 B 类 suite(braces/exportfunc/func/heredoc/nquote/vredir)各有独立根因,逐一来。

  9. caomengxuan666 commented on Nov 15, 2026

    @caomengxuan666
    MemberAuthor

    Class B, run-alias — исправлено (draft PR #3672)

    Root cause оказался не в самой раскладке reserved-word/alias (она уже корректна с #414), а в admission'е Session::run (api/session.rs): grouped driver требовал непустую таблицу алиасов сверх флага expand_aliases. -o posix -c '...' приходит с armed expand_aliases (shell.c:1853 init_noninteractive: expand_aliases = posixly_correct) и пустой таблицей → строка уходила в whole-source route, чей word-level fallback разворачивал for → echo без posix-порядка (parse.y:5751-5769) → foo in v + syntax error вместо foo=v bar=.

    Фикс однострочный: alias_live = alias_expansion_enabled(), без проверки таблицы — как в main.rs alias_live_at_start. Гейт run-alias теперь PASS полностью (вместе с unixwin/niubash#1014 на стороне хоста для line_offset).

    Остаток class B: comsub EOF line (run-braces), eval line (run-exportfunc), identifier error line (run-func), command-not-found line over-count (run-nquote), heredoc warning lines (run-heredoc), {fd} var-redirect semantics (run-vredir).

  10. caomengxuan666 commented on Nov 15, 2026

    @caomengxuan666
    MemberAuthor

    Class B, run-parser — исправлено (draft PR #3673)

    parser1.sub 的最后一行 eval "array=(foo bar)" ; echo AAA\<newline>:niu 打 AAA\(字面反斜杠),GNU 打 AAA。根因:grouped reader 的 run_history_group 把每行 strip 掉 \n 后用 \n 重 join,最后一行真实存在的换行字节丢了 → \<newline> 续行被重解析成 \<EOF>(GNU 只在真 EOF 时保留字面反斜杠,parse.y:5379)。修复:pending span 本来就知道末行是否带 \n,exec_text 重建时补回。

    一个 eval/source/. 标记触发 grouped driver 才踩得到(fast path 直接喂原文本)。附带 tests/issue3605_grouped_trailing_continuation.rs 三个 pin:grouped 折叠、fast-path 对齐、\<EOF> 字面量不变。run-parser 现在 PASS。

    Class B 剩余:comsub EOF line (run-braces)、eval line (run-exportfunc)、identifier error line (run-func)、command-not-found line over-count (run-nquote)、heredoc warning lines (run-heredoc)、{fd} var-redirect semantics (run-vredir)。

  11. caomengxuan666 commented on Nov 15, 2026

    @caomengxuan666
    MemberAuthor

    Class B, run-exportfunc — исправлено (draft PR #3674)

    exportfunc.tests:82 eval 'foo() { _; } >_[${ $() }] ;{ echo eval ok; }':niu 报 eval: line 84,GNU 报 83。根因:eval 的 close-char EOF 路径把 unclosed_input_close_char_posix 的 eof_line(= 末行 +1,一个行号索引)按 caller_line + eof_line 映射 —— 比 GNU 的 yyerror(parse.y:6883-6891 报 EOF 时 line_number)多 1。eval 行号约定是 caller_line + i - 1(evalstring.c:345 line_number--),同文件 open_line 分支和另两个调用点(command_substitution.rs、command_input_scope.rs)都已是 base + index - 1。一行修:else 分支改成 eof_line.saturating_sub(1)。

    验证:run-exportfunc gate PASS(零 diff);${/]/"/反引号/$(/$(( 各 close 家族 × 多行 eval × 不同 caller 行,与 GNU 5.3.20 逐字节一致;新增 3 个回归测试;eval EOF 诊断族 46/46 绿。

    Class B 剩余:comsub EOF line(run-braces 57 vs 59,niu 偏低 2)、identifier error line(run-func 29 vs 31)、alias 换行行号映射(run-nquote)、heredoc 警告行基 + redirect 顺序(run-heredoc)、{fd} var-redirect(run-vredir)。

  12. caomengxuan666 commented on Nov 15, 2026

    @caomengxuan666
    MemberAuthor

    Class B, run-braces — исправлено (draft PR #3675)

    braces.tests:57 echo "${a+'$(\'}"(a=4 已置):'...' 里的 $( 在解析期是字面量,但 ${a+word} 的 word 展开把它重新当成真 comsub → 抽取 body 到 EOF 无 )。niu 报 line 57,GNU 报 59。GNU 机制:command_substitute 把 body 交给 parse_and_execute("command substitution", pflags|SEVAL_NOHIST)(subst.c:7413),非交互 pflags=0(subst.c:7210,无 SEVAL_RESETLINE)→ push_stream(0) 保留脚本 line_number,evalstring.c:345 的 line_number-- 减一,body 行数 + EOF 共读使结果为 exec_line + body_lines + 1。niu 算的是 current + body_lines - 1,少 2。一行改:+ source.lines().count() + 1。

    验证:run-braces gate PASS(零 diff);${a-'$(\'} / ${a+'$(\'} × 不同行位置与 GNU 5.3.20 逐字节一致;新增 3 个回归测试;comsub/heredoc/eval EOF 诊断族 84/84 绿。已知残留:'...' 里含 \<newline> 的多行 body 仍差 1(dequote 先折叠了续行)——机制不同,留给下一轮。

    Class B 剩余:identifier error line(run-func 29 vs 31)、alias 换行行号映射(run-nquote)、heredoc 警告行基 + redirect 顺序(run-heredoc)、{fd} var-redirect(run-vredir)。

  13. caomengxuan666 commented on Nov 15, 2026

    @caomengxuan666
    MemberAuthor

    Progress: run-func fixed in draft PR #3676.

    • Root cause: the line_offset rebase shifted position/column/logical_line but not end_position, so finish_compound_command's max(position, end_position) stamped a folded { ... } token's { line instead of its } line on later groups of the grouped driver (func5.sub is grouped because its license comment contains . ). GNU reports the identifier error at execution time with the ambient line_number = the def's parse-END line (execute_cmd.c:6289 execute_intern_function).
    • Fix: end_position += offset at all five rebase sites (script_driver, builtins/source, eval, DEBUG-condition, comsub alias-splice).
    • Verified vs GNU bash 5.3.20 on fast path, grouped path, and full func5.sub; niubash gate run-func PASS on macOS arm64; regression file pins all three shapes.

    Class B remaining: run-nquote (alias-embedded newline line map), run-heredoc (warning line bases + redirect-order), run-vredir ({fd} var-redirect semantics).

  14. caomengxuan666 commented on Nov 15, 2026

    @caomengxuan666
    MemberAuthor

    Class B progress: run-nquote root-caused and fixed in draft PR #3678.

    • Root cause: GNU consumes pushed alias text through shell_getc; the line_number bump fires only on a real input fetch in yy_readline_get (parse.y:2504). A \n inside an alias value is a command separator, not a line advance — quux inside foo's value stamps the foo line, not the pushed line's index. Rubash re-lexed the spliced flat text and counted every \n.
    • Fix: alias splices now record byte offsets of expansion-introduced newlines (expand_aliases_in_source_marked → expand_group_aliases_marked → run_source_with_line_offset_marked → tokenize_*_marked); the batch lexer skips line_number += 1 on marked terminators. Certified/reused feeder tokens are refused when marks are non-empty.
    • Verified vs GNU 5.3.20 on nquote4.sh + mid-line/multi-newline variants; niubash gate run-nquote PASS.

    Class B remaining: run-heredoc (warning line bases + redirect order), run-vredir ({fd} var-redirect). Then classes C–I.

  15. 102 remaining items

  16. caomengxuan666 commented on Nov 18, 2026

    @caomengxuan666
    MemberAuthor

    进度:dollar-at-star9 的 IFS=+${0+ $* } 空-IFS $*/affix 族已修 → draft PR #3925(devin/splitspace-affix-glue, e70eb34)。

    • GNU 依据:subst.c:11939-11949 case ' '(字面 ' ' 在 ifs_is_null/W_SPLITSPACE 下 CTLESC 化)+ subst.c:10207/11535/12103-12107 W_SPLITSPACE + subst.c:3031 quoted $* join。
    • 落地:protect_ifs/alternate rhs 走路(embedded_parameters + embedded_mutations 两条 walker)在 IFS 置空或已有 sentinel 时把字面 ' ' 发成 IFS_GLUE+' ';alternate_list_fields 的 $*/${*}/${name[*]} 空-IFS unquoted → 逐元素、quoted → join(IFS[0]|'')。
    • 验证:probe 矩阵(affix a${0+ $* }b、p${0+ $* }、${0+ p $* q }、"$@" 内嵌、IFS=: 等)对 GNU 5.3.20 逐字节一致;run-dollars 目录全部 dollar-*.sub 重放仅余 at-star9 的 \x7f carrier 行(仍 deferred 等裁决)。

    残余子族(未修,已记录):a${b-$@}c 的 - 算子 splice、${0+ ${a[*]} } rhs 内嵌数组 star 分元素、"${0+ ${a[*]} }" 标量 [*] 边例。

  17. caomengxuan666 commented on Nov 22, 2026

    @caomengxuan666
    MemberAuthor

    CAPTAIN — Linux evidence for the ELF-operand face (execscript cluster), re-probed on the 1.5.1 frozen head

    This comment covers only the Linux face of the binary-classification (ENOEXEC) gate tracked here; the macOS catalog above and any Windows face remain accounted separately.

    Earlier Linux re-probe (master f7c783dc, 2026-11-22, script-file and -c modes) found exactly one divergent face: an ELF file given as a script operand was run as a script by rubash (via the /bin/sh fallback, rc 127), where GNU refuses it (rc 126, cannot execute binary file: Exec format error) — i.e. the binary-classification gate lacked an ELF-magic arm. The NUL-first-line, MZ, and plain-text faces already matched GNU.

    Re-probe on the frozen head eeb424da6cc7b286639dd315f341c4c54250ca8c (cloud Linux, debug build) against the true GNU Bash 5.3.20 oracle, script-operand mode, byte-compared:

    • Real ELF operand (copy of /bin/true): both rc 126, identical diagnostic (./elfbin: ./elfbin: cannot execute binary file).
    • File containing only the 4 bytes \x7fELF, and a \x7fELF+garbage file: both refused with the identical diagnostic — the ELF-magic arm is in place on the frozen head.
    • Controls unchanged: plain-text script runs identically on both (rc 0); MZ-headed text behaves identically on both (treated as a script).

    So the Linux ELF divergence recorded earlier no longer reproduces on the frozen head; it was covered during the 1.5.1 merge wave (no per-PR attribution claimed here). The pin elf_operand_is_refused_not_run_as_script (tests, issue3605_enoexec_binary_gate) encodes this face. Leaving this issue open for its macOS catalog; the Linux ELF face can be read as closed by this evidence.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

gnu-baseline

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions