-
Notifications
You must be signed in to change notification settings - Fork 15.2k
[libc++] Fix the locale base API on Linux with musl #167980
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
base: main
Are you sure you want to change the base?
Conversation
Handle the same guards used by musl libc to conditionally compile the 'Strtonum functions'
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-libcxx Author: Mr. Walls (reactive-firewall) ChangesHandle the same guards used by musl libc to conditionally compile the 'Strtonum functions' See GHI llvm/llvm-project#167977 cc: @ldionne (Please Review) Full diff: https://github.com/llvm/llvm-project/pull/167980.diff 1 Files Affected:
diff --git a/libcxx/include/__locale_dir/support/linux.h b/libcxx/include/__locale_dir/support/linux.h
index 94a2ecb9a940d..2233c12b7af8b 100644
--- a/libcxx/include/__locale_dir/support/linux.h
+++ b/libcxx/include/__locale_dir/support/linux.h
@@ -83,15 +83,30 @@ inline _LIBCPP_HIDE_FROM_ABI __lconv_t* __localeconv(__locale_t& __loc) {
// Strtonum functions
//
inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) {
+#if !_LIBCPP_HAS_MUSL_LIBC || defined(_GNU_SOURCE)
return ::strtof_l(__nptr, __endptr, __loc);
+#else
+ (void)__loc;
+ return ::strtof(__nptr, __endptr);
+#endif
}
inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) {
+#if !_LIBCPP_HAS_MUSL_LIBC || defined(_GNU_SOURCE)
return ::strtod_l(__nptr, __endptr, __loc);
+#else
+ (void)__loc;
+ return ::strtod(__nptr, __endptr);
+#endif
}
inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) {
+#if !_LIBCPP_HAS_MUSL_LIBC || defined(_GNU_SOURCE)
return ::strtold_l(__nptr, __endptr, __loc);
+#else
+ (void)__loc;
+ return ::strtold(__nptr, __endptr);
+#endif
}
inline _LIBCPP_HIDE_FROM_ABI long long __strtoll(const char* __nptr, char** __endptr, int __base, __locale_t __loc) {
|
|
If accepted, Please Merge on my behalf (as I do not have write access) Thanks in advance |
|
|
|
Could you make the title and description of this PR (which are generally used as squashed commit message) more descriptive? |
PR Title, and description have been updated. Hopefully this helps. If accepted, Please Merge on my behalf. - Thanks in advance. |
Patch Notes
Details
[libc++] - minor refactor - Handle the same guards used by musl libc to conditionally compile the 'Strtonum functions'.
Affected Versions
Context
This pull request addresses an issue encountered when building libcxx with certain configurations (
-D_LIBCPP_HAS_MUSL_LIBC&-D__linux__) that lack the_GNU_SOURCEdefinition. Specifically, this issue arises if the system musl libc is built with_BSD_SOURCEinstead of_GNU_SOURCE. The resultant configuration leads to problems with the "Strtonum functions" in the file libcxx/include/__locale_dir/support/linux.h, affecting the following functions:__strtof__strtod__strtoldError messages displayed include:
error: no member named 'strtof_l' in the global namespaceerror: no member named 'strtod_l' in the global namespaceerror: no member named 'strtold_l' in the global namespaceFor more insight, relevant code can be accessed here.
Suggested Fix
The resolution involves implementing conditional compilation guards that align with those utilized by musl libc. This is in line with existing practices for functions like
__strtolland__strtoull, as seen in libcxx/include/__locale_dir/support/linux.h. The proposed changes to the functions are outlined below:// // Strtonum functions // inline _LIBCPP_HIDE_FROM_ABI float __strtof(const char* __nptr, char** __endptr, __locale_t __loc) { + #if !_LIBCPP_HAS_MUSL_LIBC || defined(_GNU_SOURCE) return ::strtof_l(__nptr, __endptr, __loc); + #else + (void)__loc; + return ::strtof(__nptr, __endptr); + #endif } inline _LIBCPP_HIDE_FROM_ABI double __strtod(const char* __nptr, char** __endptr, __locale_t __loc) { + #if !_LIBCPP_HAS_MUSL_LIBC || defined(_GNU_SOURCE) return ::strtod_l(__nptr, __endptr, __loc); + #else + (void)__loc; + return ::strtod(__nptr, __endptr); + #endif } inline _LIBCPP_HIDE_FROM_ABI long double __strtold(const char* __nptr, char** __endptr, __locale_t __loc) { + #if !_LIBCPP_HAS_MUSL_LIBC || defined(_GNU_SOURCE) return ::strtod_l(__nptr, __endptr, __loc); + #else + (void)__loc; + return ::strtold(__nptr, __endptr); + #endif }Note
The musl development team may consider it a defect not to check for
defined(_GNU_SOURCE). However, given the musl implementation (version circa v1.2.5), it discards the__locargument even ifdefined(_GNU_SOURCE)is present, while omittingstrto*_lfunctions entirely without it. Therefore, an optimized approach might be to omit the|| defined(_GNU_SOURCE)condition, as it currently holds no effect unless musl's implementation changes in future versions.However this implementation has opted for 'correctness' in defined behavior. This should help ensure no regression is introduced for other configurations.
References / See Also
For further investigation, see additional details in GHI #167977
cc: @ldionne (Please Review)