-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[libc++][Android] Disable fdsan in filebuf close.pass.cpp #102412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
061580b
285d243
9fe61c2
2825698
7f5419b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -10,11 +10,6 @@ | |
|
|
||
| // basic_filebuf<charT,traits>* close(); | ||
|
|
||
| // This test closes an fd that belongs to a std::filebuf, and Bionic's fdsan | ||
| // detects this and aborts the process, starting in Android R (API 30). | ||
| // See D137129. | ||
| // XFAIL: LIBCXX-ANDROID-FIXME && !android-device-api={{2[1-9]}} | ||
|
|
||
| #include <fstream> | ||
| #include <cassert> | ||
| #if defined(__unix__) | ||
|
|
@@ -24,6 +19,15 @@ | |
| #include "test_macros.h" | ||
| #include "platform_support.h" | ||
|
|
||
| // If we're building for a lower __ANDROID_API__, the Bionic versioner will | ||
| // omit the function declarations from fdsan.h. We might be running on a newer | ||
| // API level, though, so declare the API function here using weak. | ||
| #if defined(__BIONIC__) | ||
| #include <android/fdsan.h> | ||
| enum android_fdsan_error_level android_fdsan_set_error_level(enum android_fdsan_error_level new_level) | ||
| __attribute__((weak)); | ||
| #endif | ||
|
|
||
| int main(int, char**) | ||
| { | ||
| std::string temp = get_temp_file_name(); | ||
|
|
@@ -37,6 +41,13 @@ int main(int, char**) | |
| assert(f.close() == nullptr); | ||
| assert(!f.is_open()); | ||
| } | ||
| #if defined(__BIONIC__) | ||
| // Starting with Android API 30+, Bionic's fdsan aborts a process that | ||
| // attempts to close a file descriptor belonging to something else. Disable | ||
| // fdsan to allow closing the FD belonging to std::filebuf's FILE*. | ||
| if (android_fdsan_set_error_level != nullptr) | ||
| android_fdsan_set_error_level(ANDROID_FDSAN_ERROR_LEVEL_DISABLED); | ||
| #endif | ||
| #if defined(__unix__) | ||
| { | ||
| std::filebuf f; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is what we're doing in this test Standards conforming? If so, is there a reason why fdsan flags it? That would seem like a false positive to me.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Maybe there's a POSIX conformance question for the combination of libc++ and this test? Sometimes programs close the default input/output FDs (e.g.
This line asserts that the FD's existing tag is 0 (i.e. that the FD is unowned), and then marks the FD as owned by the new This test is intentionally doing a double-close, which is the exact thing that fdsan was created to detect. https://android.googlesource.com/platform/bionic/+/master/docs/fdsan.md#background For this test, I'd also be OK with adding
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, I'd much rather simply skip this test on Bionic. Re-reading the test, it is indeed doing something wrong but it's guarding with
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, I'm now skipping that part of the test using |
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annoying that you can't use
-D __ANDROID_UNAVAILABLE_SYMBOLS_ARE_WEAK__for this one. If you want to match that behavior more closely, instead of making this weak, pass that anyway and then use__INTRODUCED_INhere? You'd also want-Werror=unguarded-availabilty. More or less the same behavior, but the callsite would then be__builtin_availablelike it would be if this feature worked properly in bionic, and means that some day when we do fix that the change to this file will just be deleting the duplicate prototype (if even that).Not really a big deal, but it's an alternative if you prefer it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that seems like a good idea. I can try adding those two
compile_flagsarguments tollvm-libc++-android-ndk.cfg.in.