[libcxx] Only use copy_file_range on Linux or FreeBSD targets - #184373
[libcxx] Only use copy_file_range on Linux or FreeBSD targets#184373TartanLlama wants to merge 3 commits into
copy_file_range on Linux or FreeBSD targets#184373Conversation
|
@llvm/pr-subscribers-libcxx Author: Sy Brand (TartanLlama) ChangesPrior to #169405, The WASI libc implementation is based on musl libc, we just don't have support for This PR guards the GLIBC and musl libc checks against the Full diff: https://github.com/llvm/llvm-project/pull/184373.diff 1 Files Affected:
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
|
|
any chance this can still be merged into the 22.x branch? musl was possibly refactored out of the list of if def., all this patch does is to revert back to the original logic. |
|
The underlying difficulty here is that we have no CI for wasi. As such, it's technically not a supported platform, and so this patch is technically introducing dead code. I assume you folks have a setup for testing libc++ on wasi? Would it be possible to add that to our pre-merge CI -- then that configuration would be properly supported. |
|
@TartanLlama are you maybe able to help out with the proper informations for the last post? I'm not a dev myself, just your average linux user. |
|
I was cc'd here by @TartanLlama and I'm one of the maintainers of wasi-sdk which is one of the primary locations llvm and its tooling are all built for WASI targets. With respect to @ldionne your thoughts about CI -- personally I'm not familiar enough with LLVM and it's processes to know what it would entail to add WASI targets to CI. I'm also hesitant to try to decree that everyone else should care about the platform and ensure things work on it, so in that sense I'd at least personally be hesitant about adding it to LLVM's CI -- although this is definitely largely driven by my own ignorance of what this would mean and how to do it. Personally though what we're currently doing I think is reasonable enough. We try to update wasi-sdk when an LLVM release branch is made and test out that everything works. There are occasional build failures and such which are not the hardest things in the world to track down, and to me it feels a reasonable "balance of power" that we're the ones tracking this down right now. The main drag on things at this point is that there are a number of PRs to libcxx and related projects which don't get any movement and we end up carrying a number of patches for in the wasi-sdk repository. For example, of the current list of patches there's two PRs on LLVM that have been not seeing much activity:
In updating to LLVM 23 I've also found locally that a minor issue was introduced in #194317 which we'll have to work around as well, which I'd ideally like to send a PR for to include upstream here but I'm hesitant to do so as I'm not confident that it will merge. Putting all of this another way, I don't believe we currently have buy-in from preexisting LLVM maintainers to support WASI upstream officially in LLVM. Those of us working on wasi-sdk/WASI in general aren't preexisting LLVM maintainers so there's no know-how to do this. I realize that puts LLVM in a difficult position in the sense that there's desire to support a platform but no resources to add it to CI and such. We've got folks who are around and able to answer questions but that may not be sufficient for adding to CI (I'm not sure). Does that help answer your question as to why this isn't currently on CI, and why it's probably not the easiest to add to CI? And/or do you have thoughts on how we could improve the situation here and/or engage better? |
|
This issue is also breaking Libc++ builds for Trusty, since we also don't support |
|
(Trusty also uses musl as their C runtime). Is there libc++ premerge CI for musl support? Maybe it doesn't need to be wasi, and could just be musl on linux? Edit: ah, right Trusty is not linux (and has no Edit2: key takeaway, musl does not imply linux |
|
Generally we much prefer having CI than not having CI. This allows us to not break people and be confident in our changes. If anything platform-specific does break we expect that there is someone we can ask to help us, and that's basically it. Having back-and-forth patches to make a particular platform happy is much more hassle than simply running the CI and knowing that it works as expected. I'd be very happy to have musl on linux as well as other platforms, since that is a configuration people clearly use, but we don't have any visibility in what we might break. Adding CI is described at https://libcxx.llvm.org/AddingNewCIJobs.html#addingnewcijobs for buildkite, but you can also use GH Actions if that's easier for you. Edit: If you'd like to talk about this there is also the libc++ monthly, which might get you faster results than just messages through GitHub. |
|
What kind of CI check would you like to see that would catch issues like this? I doubt you want a CI target that builds with Trusty's Musl libc; it'd probably end up breaking because of our changes. We could add CI for something like |
If you use libc++ on Trusty (whatever that may be) I'd be very happy if there was a bot targeting Trusty. Looking at the link it may not be that different from running libc++ tests on Android, which we already do. |
|
As discussed in today's libc++ monthly, @SilensAngelusNex will work with @petrhosek to figure out how to bring up CI for Trusty. This can probably be done similarly to what's being done for the Android testers, which also run Qemu, etc. @pirama-arumuga-nainar , @Sharjeel-Khan and @nickdesaulniers are also listed as Android bot owners for libc++ and can probably provide additional support. @TartanLlama We'd love to support WASI officially, but that requires pre-commit CI to be set up for it per our policy. Otherwise platform support gets completely out of hand. I see there are Docker images like |
ldionne
left a comment
There was a problem hiding this comment.
In the meantime, requesting changes so it shows up properly in the queue.
|
Checks like this are probably broken for bionic, too. I should probably should audit libc++ to see if there's other cases like this. cc @enh-google |
android added the wrapper in api level 34 (see https://apilevels.com/ if that means nothing to you). so for us the missing disjunct would be (note that -- if anyone's thinking "how about we just check for |
(but to be clear: from the history it looks like this pr is "no functional change" for android anyway, so seems fine.) |
|
Restating something I mentioned on Discord here so it's easier to find: What does/should Looking at the uses of |
|
maybe I can write a few words of clarification here: this became an issue for everyone who, while on linux, uses musl as their the proposed fix simply restores the old libcxx-21.x behavior of the code, and it behaves just like before, which means the compile of the libcxx inside of wasi-sdk is fixed. |
The TLDR here is that any Musl support in the library is vestigial of an earlier port that ended up rotting. We haven't tried ripping it out because I expect this would have caused outcry (and I think this thread confirms it would have), but that port is neither supported nor designed. If we are to support Trusty and WASI in libc++ (I think we should, and it seems like there is demand for it), I would simply treat them as separate platforms and conditionalize on If that turns out to be wrong and we actually want to detect Musl specifically, then we probably should have llvm-project/libcxx/CMakeLists.txt Lines 821 to 830 in 5f3b907 |
Is there a reason there aren't individual knobs for these features? If we could set
I'd be happy to make that PR if you think it's a good approach; tests could run on the existing CI instead of needing a new platform. |
That would make implementation details of libc++ part of our "public API" and make it easier for people to create frankenstein configurations. I don't think having such fine-grained knobs publicly would improve your situation in the long term. We'd end up breaking them by mistake or having to give up on providing any form of stability on those knobs, which doesn't help you. For musl, following the path taken by WASI in #215384 seems to be by far the best way forward. |
Prior to #169405,
copy_file_rangewas used only on Linux targets with specific libc constraints, or any FreeBSD target. The PR simplified theifdefs, resulting in the Linux requirement being dropped. This broke libc++ builds forwasm32-wasitargets. 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 inwasi-libc. Prior to the PR that changed the libc++ behaviour, we suppliedHAS_MUSL_LIBCwhen 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 forwasm32-wasitargets.