Skip to content

Draft: Emulate hard-linking symlinks on macOS hosts#239

Closed
doanbaotrung wants to merge 0 commit into
sysprog21:mainfrom
open-sources-port:linkat
Closed

Draft: Emulate hard-linking symlinks on macOS hosts#239
doanbaotrung wants to merge 0 commit into
sysprog21:mainfrom
open-sources-port:linkat

Conversation

@doanbaotrung

@doanbaotrung doanbaotrung commented Jul 23, 2026

Copy link
Copy Markdown
Collaborator

On macOS hosts, native linkat(2) returns EINVAL when linking a symbolic link directly (i.e. with AT_SYMLINK_NOFOLLOW). Linux allows this unconditionally.

Emulate this by reading the symlink target, converting any absolute target path to a relative path to keep it contained in the sysroot, and creating a new symbolic link at the destination using symlinkat.

Fix #237


Summary by cubic

Emulates Linux behavior on macOS for hard-linking a symlink: linkat(..., AT_SYMLINK_NOFOLLOW) now creates a new symlink at the destination with the same target. Absolute targets are rewritten to relative to keep links within the sysroot. Fixes #237.

  • New Features

    • Emulate symlink hard-linking on macOS by creating a new symlink when AT_SYMLINK_NOFOLLOW is set (handles EINVAL).
    • Normalize absolute symlink targets to relative in both linkat emulation and symlinkat.
  • Refactors

    • Export dirfd_guest_base_path for target normalization.
    • Add debug logging for symlinkat in the syscall dispatcher.

Written for commit 12df8f2. Summary will update on new commits.

Review in cubic

@doanbaotrung doanbaotrung changed the title Emulate hard-linking symlinks on macOS hosts Draft: Emulate hard-linking symlinks on macOS hosts Jul 23, 2026
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.

linkat fails with EINVAL on macOS hosts when linking symlinks (AT_SYMLINK_NOFOLLOW)

1 participant