Skip to content

fix: resolve shim alias to full path, preventing self-recursion#207

Merged
Sunrisepeak merged 3 commits intomainfrom
fix/shim-alias-self-recursion
Mar 15, 2026
Merged

fix: resolve shim alias to full path, preventing self-recursion#207
Sunrisepeak merged 3 commits intomainfrom
fix/shim-alias-self-recursion

Conversation

@Sunrisepeak
Copy link
Copy Markdown
Member

@Sunrisepeak Sunrisepeak commented Mar 15, 2026

Summary

  • 正常情况下 alias 保持原始行为(裸命令名通过 PATH 查找,package 目录优先于 shim_dir)
  • 当递归深度达到 8 时,打印详细诊断信息(program、alias、package path、PATH),并启动 resolve_executable() fallback 将 alias 解析为完整路径
  • 当深度达到 10 仍未解决,error 退出并提示真实二进制缺失

Root Cause

alias 分支构建的 PATH 顺序为:

expanded_path : bin_path(expanded_path/bin) : cfg_bin(shim_dir) : original_PATH

package 目录排在 shim_dir 之前,正常安装时真实二进制优先被找到,不会递归。

递归仅在异常条件下触发(真实二进制缺失,PATH 回退到 shim_dir):

  • 安装不完整(如 elfpatch 修复 PT_INTERP 失败)
  • 真实二进制被删除或损坏
  • alias 命令名与 package 目录中的文件名不匹配

Changes

File Change
src/core/xvm/shim.cppm alias 分支:depth < 8 保持原始行为,depth >= 8 启动 fallback 路径解析 + debug 日志,depth >= 10 hard stop
tests/unit/test_main.cpp 新增 ResolveAliasCommandToFullPathResolveAliasDirectPath 测试
tests/e2e/shim_alias_recursion_test.sh 新增 E2E 递归测试
docs/plans/2026-03-15-shim-alias-recursion-fix.md 更新根因分析文档

Test plan

  • xmake build — 编译通过
  • xmake run xlings_tests — 196 tests passed
  • bash tests/e2e/shim_alias_recursion_test.sh — E2E 测试
  • 手动验证: 配置 gcc alias 后运行 gcc --version

🤖 Generated with Claude Code

Sunrisepeak and others added 3 commits March 15, 2026 19:14
When a shim alias (e.g. "gcc --sysroot=...") is executed via platform::exec(),
the bare program name could resolve back to the shim itself through PATH,
causing infinite recursion up to depth=8. Now the alias command's first word
is resolved to its full path via resolve_executable() before execution.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…>= 8

Normal alias execution keeps original behavior (bare command via PATH).
When depth reaches MAX_SHIM_DEPTH (8), log diagnostic info (program,
alias, package path, PATH) and resolve alias to full path as fallback.
Hard stop at FALLBACK_DEPTH (10) if resolution still fails.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
… sync

- add_version() now accepts binding param and establishes bidirectional
  binding relationships (parent↔child) in VInfo.bindings
- installer passes op.binding through to add_version
- cmd_use recursively traverses binding tree to sync all connected
  targets' workspace versions (e.g., `xlings use gcc 15` syncs g++,
  gcc-ar, cc automatically)
- Remove runtime binding lookup in shim_dispatch; each binding target
  now has its own workspace version set by cmd_use

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Sunrisepeak Sunrisepeak merged commit a9ed63a into main Mar 15, 2026
3 checks passed
@Sunrisepeak Sunrisepeak deleted the fix/shim-alias-self-recursion branch March 15, 2026 15:21
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