Skip to content

Conversation

@alexcrichton
Copy link
Collaborator

This commit fixes a longstanding issue in wasi-libc where the linkat function, when both parameters are AT_FDCWD or absolute paths, would relativize the two input paths in such a way that the previous stomped over the first, meaning that the wrong actual syscall was issued. This fixes the problem in the same manner as other two-path-taking functions which is to use find_relpath for one path and find_relpath_alt for the other path.

This commit fixes a longstanding issue in wasi-libc where the `linkat`
function, when both parameters are `AT_FDCWD` or absolute paths, would
relativize the two input paths in such a way that the previous stomped
over the first, meaning that the wrong actual syscall was issued. This
fixes the problem in the same manner as other two-path-taking functions
which is to use `find_relpath` for one path and `find_relpath_alt` for
the other path.
Copy link
Contributor

@yamt yamt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

char dst[] = "/dir/b";

TEST(mkdir("dir", 0700) == 0);
TEST((fd = open(src, flags | O_WRONLY | O_CREAT | O_EXCL, 0600)) > 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tab/space issue?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm hoping to work on clang-format after #685 is merged but for now it's a bit messy all the style in the repo, this is I believe not the first test with this for example.

Copy link
Collaborator

@abrown abrown left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! And thanks for the extra tests.

@alexcrichton alexcrichton merged commit 76db324 into WebAssembly:main Dec 13, 2025
23 checks passed
@alexcrichton alexcrichton deleted the fix-link branch December 13, 2025 17:51
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 14, 2025
…joboet

std: Don't use `linkat` on the `wasm32-wasi*` targets

This commit is a follow-up to rust-lang#147572 and the issue reported at the end of that PR where the `std::fs::hard_link` function is broken after that PR landed. The true culprit and bug here is fixed in WebAssembly/wasi-libc#690 but until that's released in a wasi-sdk version it should be reasonable, on WASI, to skip the `linkat` function.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 14, 2025
…joboet

std: Don't use `linkat` on the `wasm32-wasi*` targets

This commit is a follow-up to rust-lang#147572 and the issue reported at the end of that PR where the `std::fs::hard_link` function is broken after that PR landed. The true culprit and bug here is fixed in WebAssembly/wasi-libc#690 but until that's released in a wasi-sdk version it should be reasonable, on WASI, to skip the `linkat` function.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Dec 14, 2025
…joboet

std: Don't use `linkat` on the `wasm32-wasi*` targets

This commit is a follow-up to rust-lang#147572 and the issue reported at the end of that PR where the `std::fs::hard_link` function is broken after that PR landed. The true culprit and bug here is fixed in WebAssembly/wasi-libc#690 but until that's released in a wasi-sdk version it should be reasonable, on WASI, to skip the `linkat` function.
rust-timer added a commit to rust-lang/rust that referenced this pull request Dec 15, 2025
Rollup merge of #149864 - alexcrichton:wasi-avoid-linkat, r=joboet

std: Don't use `linkat` on the `wasm32-wasi*` targets

This commit is a follow-up to #147572 and the issue reported at the end of that PR where the `std::fs::hard_link` function is broken after that PR landed. The true culprit and bug here is fixed in WebAssembly/wasi-libc#690 but until that's released in a wasi-sdk version it should be reasonable, on WASI, to skip the `linkat` function.
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Dec 18, 2025
std: Don't use `linkat` on the `wasm32-wasi*` targets

This commit is a follow-up to rust-lang/rust#147572 and the issue reported at the end of that PR where the `std::fs::hard_link` function is broken after that PR landed. The true culprit and bug here is fixed in WebAssembly/wasi-libc#690 but until that's released in a wasi-sdk version it should be reasonable, on WASI, to skip the `linkat` function.
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.

3 participants