[libcxx-commits] [libcxx] 1580263 - [libc++][AIX] Initial patch to unblock the libc++ build on AIX

via libcxx-commits libcxx-commits at lists.llvm.org
Wed Mar 24 15:15:00 PDT 2021


Author: jasonliu
Date: 2021-03-24T22:13:20Z
New Revision: 158026301b4842bb877fc8a6a444c348da6d9f3b

URL: https://github.com/llvm/llvm-project/commit/158026301b4842bb877fc8a6a444c348da6d9f3b
DIFF: https://github.com/llvm/llvm-project/commit/158026301b4842bb877fc8a6a444c348da6d9f3b.diff

LOG: [libc++][AIX] Initial patch to unblock the libc++ build on AIX

This path would unblock the build of libc++ library on AIX:
1. Add _AIX guard for _LIBCPP_HAS_THREAD_API_PTHREAD
2. Use uselocale to actually take the locale setting
   into account.
3. extract_mtime and extract_atime mod needed for AIX. As stat
   structure on AIX uses internal structure st_timespec to store
   time for binary compatibility reason. So we need to convert it
   back to timespec here.
4. Do not build cxa_thread_atexit.cpp for libcxxabi on AIX.

Differential Revision: https://reviews.llvm.org/D97558

Added: 
    

Modified: 
    libcxx/include/__config
    libcxx/include/__support/ibm/xlocale.h
    libcxx/src/filesystem/filesystem_common.h
    libcxxabi/src/CMakeLists.txt

Removed: 
    


################################################################################
diff  --git a/libcxx/include/__config b/libcxx/include/__config
index f4dce078e2c55..cd748fde25863 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -1145,6 +1145,7 @@ extern "C" _LIBCPP_FUNC_VIS void __sanitizer_annotate_contiguous_container(
       defined(__CloudABI__) || \
       defined(__sun__) || \
       defined(__MVS__) || \
+      defined(_AIX) || \
       (defined(__MINGW32__) && __has_include(<pthread.h>))
 #    define _LIBCPP_HAS_THREAD_API_PTHREAD
 #  elif defined(__Fuchsia__)

diff  --git a/libcxx/include/__support/ibm/xlocale.h b/libcxx/include/__support/ibm/xlocale.h
index 563b465a8f65b..ff14d2e60b0d4 100644
--- a/libcxx/include/__support/ibm/xlocale.h
+++ b/libcxx/include/__support/ibm/xlocale.h
@@ -212,11 +212,13 @@ size_t wcsxfrm_l(wchar_t *__ws1, const wchar_t *__ws2, size_t __n,
 
 // strftime_l() is defined by POSIX. However, AIX 7.1 and z/OS do not have it
 // implemented yet. z/OS retrieves it from the POSIX fallbacks.
+#if !defined(_AIX72)
 static inline
 size_t strftime_l(char *__s, size_t __size, const char *__fmt,
                   const struct tm *__tm, locale_t locale) {
   return __xstrftime(locale, __s, __size, __fmt, __tm);
 }
+#endif
 
 #elif defined(__MVS__)
 #include <wctype.h>
@@ -224,47 +226,79 @@ size_t strftime_l(char *__s, size_t __size, const char *__fmt,
 #include <__support/xlocale/__posix_l_fallback.h>
 #endif // defined(__MVS__)
 
+namespace {
+
+struct __setAndRestore {
+  explicit __setAndRestore(locale_t locale) {
+    if (locale == (locale_t)0) {
+      __cloc = newlocale(LC_ALL_MASK, "C", /* base */ (locale_t)0);
+      __stored = uselocale(__cloc);
+    } else {
+      __stored = uselocale(locale);
+    }
+  }
+
+  ~__setAndRestore() {
+    uselocale(__stored);
+    if (__cloc)
+      freelocale(__cloc);
+  }
+
+private:
+  locale_t __stored = (locale_t)0;
+  locale_t __cloc = (locale_t)0;
+};
+
+} // namespace
+
 // The following are not POSIX routines.  These are quick-and-dirty hacks
 // to make things pretend to work
 static inline
 long long strtoll_l(const char *__nptr, char **__endptr,
     int __base, locale_t locale) {
+  __setAndRestore __newloc(locale);
   return strtoll(__nptr, __endptr, __base);
 }
 
 static inline
 long strtol_l(const char *__nptr, char **__endptr,
     int __base, locale_t locale) {
+  __setAndRestore __newloc(locale);
   return strtol(__nptr, __endptr, __base);
 }
 
 static inline
 double strtod_l(const char *__nptr, char **__endptr,
     locale_t locale) {
+  __setAndRestore __newloc(locale);
   return strtod(__nptr, __endptr);
 }
 
 static inline
 float strtof_l(const char *__nptr, char **__endptr,
     locale_t locale) {
+  __setAndRestore __newloc(locale);
   return strtof(__nptr, __endptr);
 }
 
 static inline
 long double strtold_l(const char *__nptr, char **__endptr,
     locale_t locale) {
+  __setAndRestore __newloc(locale);
   return strtold(__nptr, __endptr);
 }
 
 static inline
 unsigned long long strtoull_l(const char *__nptr, char **__endptr,
     int __base, locale_t locale) {
+  __setAndRestore __newloc(locale);
   return strtoull(__nptr, __endptr, __base);
 }
 
 static inline
 unsigned long strtoul_l(const char *__nptr, char **__endptr,
     int __base, locale_t locale) {
+  __setAndRestore __newloc(locale);
   return strtoul(__nptr, __endptr, __base);
 }
 

diff  --git a/libcxx/src/filesystem/filesystem_common.h b/libcxx/src/filesystem/filesystem_common.h
index c2214d02fb809..f7f9013edb738 100644
--- a/libcxx/src/filesystem/filesystem_common.h
+++ b/libcxx/src/filesystem/filesystem_common.h
@@ -467,6 +467,15 @@ inline TimeSpec extract_atime(StatT const& st) {
   TimeSpec TS = {st.st_atime, 0};
   return TS;
 }
+#elif defined(_AIX)
+inline TimeSpec extract_mtime(StatT const& st) {
+  TimeSpec TS = {st.st_mtime, st.st_mtime_n};
+  return TS;
+}
+inline TimeSpec extract_atime(StatT const& st) {
+  TimeSpec TS = {st.st_atime, st.st_atime_n};
+  return TS;
+}
 #else
 inline TimeSpec extract_mtime(StatT const& st) { return st.st_mtim; }
 inline TimeSpec extract_atime(StatT const& st) { return st.st_atim; }

diff  --git a/libcxxabi/src/CMakeLists.txt b/libcxxabi/src/CMakeLists.txt
index a2945f00bc25a..32a998e02f482 100644
--- a/libcxxabi/src/CMakeLists.txt
+++ b/libcxxabi/src/CMakeLists.txt
@@ -36,7 +36,8 @@ else()
   )
 endif()
 
-if (LIBCXXABI_ENABLE_THREADS AND (UNIX OR FUCHSIA) AND NOT (APPLE OR CYGWIN))
+if (LIBCXXABI_ENABLE_THREADS AND (UNIX OR FUCHSIA) AND NOT (APPLE OR CYGWIN)
+    AND NOT (${CMAKE_SYSTEM_NAME} MATCHES "AIX"))
   list(APPEND LIBCXXABI_SOURCES
     cxa_thread_atexit.cpp
   )


        


More information about the libcxx-commits mailing list