Skip to content

[libcxx] Only use copy_file_range on Linux or FreeBSD targets#184373

Open
TartanLlama wants to merge 3 commits intollvm:mainfrom
TartanLlama:sy/wasi-copy-file-range
Open

[libcxx] Only use copy_file_range on Linux or FreeBSD targets#184373
TartanLlama wants to merge 3 commits intollvm:mainfrom
TartanLlama:sy/wasi-copy-file-range

Conversation

@TartanLlama
Copy link
Contributor

Prior to #169405, copy_file_range was used only on Linux targets with specific libc constraints, or any FreeBSD target. The PR simplified the ifdefs, resulting in the Linux requirement being dropped. This broke libc++ builds for wasm32-wasi targets. See LLVM issue #181543.

The WASI libc implementation is based on musl libc, we just don't have support for copy_file_range, so this is not declared in wasi-libc. Prior to the PR that changed the libc++ behaviour, we supplied HAS_MUSL_LIBC when building libc++. We have temporarily disabled this (WebAssembly/wasi-sdk#585), but it would be great if we could re-enable it to benefit from any other MUSL-targeted specializations.

This PR guards the GLIBC and musl libc checks against the __linux__ define, which will suffice to disable it for wasm32-wasi targets.

@TartanLlama TartanLlama requested a review from a team as a code owner March 3, 2026 16:32
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Mar 3, 2026
@llvmbot
Copy link
Member

llvmbot commented Mar 3, 2026

@llvm/pr-subscribers-libcxx

Author: Sy Brand (TartanLlama)

Changes

Prior to #169405, copy_file_range was used only on Linux targets with specific libc constraints, or any FreeBSD target. The PR simplified the ifdefs, resulting in the Linux requirement being dropped. This broke libc++ builds for wasm32-wasi targets. See LLVM issue #181543.

The WASI libc implementation is based on musl libc, we just don't have support for copy_file_range, so this is not declared in wasi-libc. Prior to the PR that changed the libc++ behaviour, we supplied HAS_MUSL_LIBC when building libc++. We have temporarily disabled this (WebAssembly/wasi-sdk#585), but it would be great if we could re-enable it to benefit from any other MUSL-targeted specializations.

This PR guards the GLIBC and musl libc checks against the __linux__ define, which will suffice to disable it for wasm32-wasi targets.


Full diff: https://github.com/llvm/llvm-project/pull/184373.diff

1 Files Affected:

  • (modified) libcxx/src/filesystem/operations.cpp (+1-1)
diff --git a/libcxx/src/filesystem/operations.cpp b/libcxx/src/filesystem/operations.cpp
index 745db87ce3736..c1834a61b55de 100644
--- a/libcxx/src/filesystem/operations.cpp
+++ b/libcxx/src/filesystem/operations.cpp
@@ -41,7 +41,7 @@
 #include <time.h>
 
 // since Linux 4.5 and FreeBSD 13, but the Linux libc wrapper is only provided by glibc >= 2.27 and musl
-#if _LIBCPP_GLIBC_PREREQ(2, 27) || _LIBCPP_HAS_MUSL_LIBC || defined(__FreeBSD__)
+#if (defined(__linux__) && (_LIBCPP_GLIBC_PREREQ(2, 27) || _LIBCPP_HAS_MUSL_LIBC)) || defined(__FreeBSD__)
 #  define _LIBCPP_FILESYSTEM_USE_COPY_FILE_RANGE
 #endif
 

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

Labels

libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants