Repository navigation
Description
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.testsdies withSegmentation fault: 11under niu. Also diverges on extglob dir patterns:#20: pat=*@(/)cd/efg yes/novs GNUno/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 6vs GNUline 7for`do'syntax errorrun-braces— comsub EOF errorline 57vsline 59run-exportfunc—eval: line 84vsline 83run-func—`sys$read': not a valid identifieratline 29vsline 31run-heredoc— heredoc warnings at wrong lines (line 52/97vs98/99);ed ${TMPDIR}/foo > /dev/null <<EOFtraced in different token orderrun-nquote—quux: command not foundatline 8vsline 6run-vredir—redirection errorreported withline 13prefix vs none; extra&0: Invalid argumentline
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:vsbash: -c: line 1:run-execscript—niu: notthere:vs/tmp/bash: notthere:; alsostream did not contain valid UTF-8where GNU reads the file fine, and missingnotthere: command not founddiagnosticsrun-invocation—niu: .: Is a directoryvs.: .: Is a directory;cannot execute: required file not foundvsbad interpreterwording; missingbash_logouthandling
D. Word/parser semantic divergences
run-comsub-posix— big miss:line 2: syntax error near unexpected token ')'vs 70+ lines of expected outputrun-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 contextrun-dollars—$*/$@quoting:<123 abc def ghi\ 456>vs<123 abc> <def> <ghi\ 456>;$$/$?value differencesrun-parser—AAA\line-continuation edgerun-errors— comsub error context reprint differs (: $( for z in 1 2 3; done )')
E. Glob/quoting character handling
run-glob-test—\u03B1unicode escapes emitted literally (<A\u03B1B>) instead of decodedrun-nquote4— high-byte chars printed as UTF-8 (abÞ) vs GNU raw byte outputrun-nquote,run-posixexp*,run-glob-bracket(see A)
F. Arithmetic
run-arith— empty operand: niu errorsarithmetic syntax error: operand expectedwhere GNU producesdeclare -a a=([0]="16");`a[]': not a valid identifierorderingrun-arith-for— see C (name prefix) plus;' unexpectedwording
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 subscriptvsreadonly variablerun-assoc— (was recho-bound, residual diffs)run-attr— extrareadonly variableerrors vs GNU behaviorrun-varenv— assoc member ordering:[one][zero]vs[zero][one]; readonly enforcementrun-nameref—declareoutput ordering/dup lines
H. Builtins
run-builtins—helplisting truncated at column ~80 (expected full lines)run-complete— extraenvcompletion entriesrun-shopt—shopt -sdumps embedded diff text (1,38c1,20block inside output)run-comsub2—alias e=redefine ordering in outputrun-printf—printf: Value too large for defined data typevs GNU printingXYrun-read,run-test—/dev/tty: No such device or address(non-interactive tty handling)run-rsh— restricted mode missing:/bin/sh: restricted,sh: not foundrun-history—fc: no command found, exit-code reporting(exit 42)run-trap— missingexiting(EXIT trap output)run-jobs— job numbering/status:[3]- Runningvs[2]- Running; missingStoppedtransitionsrun-coproc— (fixed by xcase build; residual)
I. Intl / locale
run-intl—mbchar matchvsbytematch;fr_FR.ISO8859-1byte→\umapping 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
caomengxuan666 commentedon Nov 14, 2026
开工 — 按上面 A-I 分类逐条拆 PR 修,先从 A 类(glob-bracket segfault)开始。
caomengxuan666 commentedon Nov 14, 2026
Root cause found for the
run-glob-bracketSIGSEGV (class A).Minimal reproducer:
enable -fitself works —enable -plistsstrmatch. The crash is at invocation: the plugin body calls the host symbolstrmatch()(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 strmatchis 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 (
strmatchlives inlib/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 insrc/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 -fshould probably preflight a shared object for unresolvable flat-namespace symbols and refuse with a diagnostic instead of letting it crash at call time.caomengxuan666 commentedon Nov 14, 2026
进度:class A(loadable 回调宿主符号崩溃)已修,draft PR https://github.com/unixwin/rubash/pull/3630。
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 语义的的单字节移植。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。
caomengxuan666 commentedon Nov 15, 2026
进度: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]。验证(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 同红),与本改动无关。
caomengxuan666 commentedon Nov 15, 2026
进度:class H 的 run-printf(
%.TOOBIGsinline 精度溢出)已修,draft PR https://github.com/unixwin/rubash/pull/3671。int字段(xprintf.c:558-559),模 2^32 回绕:%.9223372036854775825s按%.17s渲染输出XY(vendored .right 期望)。niu 此前统一按 glibc EOVERFLOW + PRETURN 处理,丢了指令输出。%.2147483648d一类 INT_MAX 邻界值在 Darwin libc 上行为不一致(其int累加的 UB 边缘),niu 取回绕值,不去追 UB。PR #3630 / #3670 各 3 项 CI 红均为已知系统性 issue2875(master 同红),与本系列无关。
caomengxuan666 commentedon Nov 15, 2026
进度更新(class B 第一项):
前导空行行号偏差已定位并修复 —— 是 niubash host 层 bug,不是 rubash。
niubash-runtimeShell::execute_script_inner对非交互输入先script.trim()再交给 engine,line_offset没有补偿被剥掉的前导空行 → 首个真实命令前的每个空行都会让后续所有诊断行号偏低。实测:niu -c '\ndo echo x'→line 1,GNUline 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
foralias 展开差异(rubash 侧,下一个做)。其余 B 类 suite(braces/exportfunc/func/heredoc/nquote/vredir)各有独立根因,逐一来。caomengxuan666 commentedon Nov 15, 2026
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 '...'приходит с armedexpand_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.rsalias_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).caomengxuan666 commentedon Nov 15, 2026
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)。caomengxuan666 commentedon Nov 15, 2026
Class B, run-exportfunc — исправлено (draft PR #3674)
exportfunc.tests:82eval '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:345line_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)。caomengxuan666 commentedon Nov 15, 2026
Class B, run-braces — исправлено (draft PR #3675)
braces.tests:57echo "${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)。caomengxuan666 commentedon Nov 15, 2026
Progress: run-func fixed in draft PR #3676.
line_offsetrebase shiftedposition/column/logical_linebut notend_position, sofinish_compound_command'smax(position, end_position)stamped a folded{ ... }token's{line instead of its}line on later groups of the grouped driver (func5.subis grouped because its license comment contains.). GNU reports the identifier error at execution time with the ambientline_number= the def's parse-END line (execute_cmd.c:6289execute_intern_function).end_position += offsetat all five rebase sites (script_driver, builtins/source, eval, DEBUG-condition, comsub alias-splice).run-funcPASS 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).caomengxuan666 commentedon Nov 15, 2026
Class B progress: run-nquote root-caused and fixed in draft PR #3678.
shell_getc; theline_numberbump fires only on a real input fetch inyy_readline_get(parse.y:2504). A\ninside an alias value is a command separator, not a line advance —quuxinsidefoo's value stamps thefooline, not the pushed line's index. Rubash re-lexed the spliced flat text and counted every\n.expand_aliases_in_source_marked→expand_group_aliases_marked→run_source_with_line_offset_marked→tokenize_*_marked); the batch lexer skipsline_number += 1on marked terminators. Certified/reused feeder tokens are refused when marks are non-empty.run-nquotePASS.Class B remaining: run-heredoc (warning line bases + redirect order), run-vredir (
{fd}var-redirect). Then classes C–I.102 remaining items
fix(executor): resolve ${!src<op>tail} indirection for positional and…
fix(expansion): $@-class alternate rhs rejoins on ifs_firstchar like …
executor: port W_SPLITSPACE + IFS-bind freeze for unquoted $*/$@ (Refs …
fix(expansion): materialize literal <(/>( inside ${var op word} rhs (…
style(lexer): rustfmt #3605 subscript innermost-verdict pins (Refs #3605
executor: preserve quoted-\$@ element whitespace and skip SPLIT_ON_SP…
shell: bind $0 to argv[0] basename verbatim for non-face names (#1026)
fix(lexer): let inner dollar words own the EOF verdict inside [ subsc…
fix(comsub,parser): honor ANSI-C $'...' in $( walkers; split EOF exit…
operator values: dequote stored CTLNUL + quoted-null retention oracle…
caomengxuan666 commentedon Nov 18, 2026
进度:dollar-at-star9 的
IFS=+${0+ $* }空-IFS$*/affix 族已修 → draft PR #3925(devin/splitspace-affix-glue, e70eb34)。case ' '(字面 ' ' 在 ifs_is_null/W_SPLITSPACE 下 CTLESC 化)+ subst.c:10207/11535/12103-12107 W_SPLITSPACE + subst.c:3031 quoted$*join。protect_ifs/alternaterhs 走路(embedded_parameters + embedded_mutations 两条 walker)在 IFS 置空或已有 sentinel 时把字面 ' ' 发成 IFS_GLUE+' ';alternate_list_fields的$*/${*}/${name[*]}空-IFS unquoted → 逐元素、quoted → join(IFS[0]|'')。a${0+ $* }b、p${0+ $* }、${0+ p $* q }、"$@"内嵌、IFS=: 等)对 GNU 5.3.20 逐字节一致;run-dollars 目录全部dollar-*.sub重放仅余 at-star9 的\x7fcarrier 行(仍 deferred 等裁决)。残余子族(未修,已记录):
a${b-$@}c的-算子 splice、${0+ ${a[*]} }rhs 内嵌数组 star 分元素、"${0+ ${a[*]} }"标量 [*] 边例。executor: protect literal ' ' under null-IFS / W_SPLITSPACE (dollar-a…
fix(ulimit): apply a fork region's recorded limits to children at spa…
caomengxuan666 commentedon Nov 22, 2026
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-cmodes) 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:./elfbin: ./elfbin: cannot execute binary file).\x7fELF, and a\x7fELF+garbage file: both refused with the identical diagnostic — the ELF-magic arm is in place on the frozen head.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.fix(exec,path): validate ELF header structure before pre-exec ENOEXEC…