-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathpatch-older-systems.diff
334 lines (318 loc) · 10.2 KB
/
patch-older-systems.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
diff --git CMake/folly-deps.cmake CMake/folly-deps.cmake
index 989259a87..7fa4cb4e5 100644
--- CMake/folly-deps.cmake
+++ CMake/folly-deps.cmake
@@ -181,14 +181,17 @@ message(STATUS "Setting FOLLY_USE_SYMBOLIZER: ${FOLLY_USE_SYMBOLIZER}")
message(STATUS "Setting FOLLY_HAVE_ELF: ${FOLLY_HAVE_ELF}")
message(STATUS "Setting FOLLY_HAVE_DWARF: ${FOLLY_HAVE_DWARF}")
-# Using clang with libstdc++ requires explicitly linking against libatomic
-check_cxx_source_compiles("
- #include <atomic>
- int main(int argc, char** argv) {
- struct Test { int val; };
- std::atomic<Test> s;
- return static_cast<int>(s.is_lock_free());
- }"
+# Using clang with libstdc++ requires explicitly linking against libatomic.
+# The same applies to GCC on some platforms.
+check_cxx_source_compiles(
+"#include <atomic>
+int main() {
+ std::atomic<uint8_t> w1;
+ std::atomic<uint16_t> w2;
+ std::atomic<uint32_t> w4;
+ std::atomic<uint64_t> w8;
+ return ++w1 + ++w2 + ++w4 + ++w8;
+}"
FOLLY_CPP_ATOMIC_BUILTIN
)
if(NOT FOLLY_CPP_ATOMIC_BUILTIN)
@@ -247,7 +250,7 @@ check_cxx_source_compiles("
FOLLY_STDLIB_LIBCPP
)
-if (APPLE)
+if (APPLE AND NOT(CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
list (APPEND CMAKE_REQUIRED_LIBRARIES c++abi)
list (APPEND FOLLY_LINK_LIBRARIES c++abi)
endif ()
diff --git CMakeLists.txt CMakeLists.txt
index dfd4c3820..d02121df0 100644
--- CMakeLists.txt
+++ CMakeLists.txt
@@ -261,6 +261,16 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
endif()
# base64 SIMD files compilation
+
+if (APPLE AND CMAKE_OSX_ARCHITECTURES MATCHES "ppc|ppc64")
+ message(
+ STATUS
+ "PowerPC Big Endian has a limited support, "
+ "skipping building Base64SWAR of base64"
+ )
+ list(REMOVE_ITEM files ${FOLLY_DIR}/detail/base64_detail/Base64SWAR.cpp)
+endif()
+
if (NOT(${IS_X86_64_ARCH}))
message(
STATUS
diff --git folly/File.cpp folly/File.cpp
index 401eb7a01..c50a6d7e5 100644
--- folly/File.cpp
+++ folly/File.cpp
@@ -120,8 +120,10 @@ File File::dupCloseOnExec() const {
int fd;
#ifdef _WIN32
fd = ::dup(fd_);
-#else
+#elif defined(F_DUPFD_CLOEXEC)
fd = ::fcntl(fd_, F_DUPFD_CLOEXEC, 0);
+#else
+ fd = ::dup(fd_);
#endif
checkUnixError(fd, "dup() failed");
diff --git folly/Portability.h folly/Portability.h
index 24ba108bb..933d240e7 100644
--- folly/Portability.h
+++ folly/Portability.h
@@ -103,12 +103,18 @@ constexpr bool kHasUnalignedAccess = false;
#define FOLLY_AARCH64 0
#endif
-#if defined(__powerpc64__)
+#if defined(__powerpc64__) || defined(__ppc64__)
#define FOLLY_PPC64 1
#else
#define FOLLY_PPC64 0
#endif
+#if defined(__ppc__)
+#define FOLLY_PPC 1
+#else
+#define FOLLY_PPC 0
+#endif
+
#if defined(__s390x__)
#define FOLLY_S390X 1
#else
@@ -120,6 +126,7 @@ constexpr bool kIsArchArm = FOLLY_ARM == 1;
constexpr bool kIsArchAmd64 = FOLLY_X64 == 1;
constexpr bool kIsArchAArch64 = FOLLY_AARCH64 == 1;
constexpr bool kIsArchPPC64 = FOLLY_PPC64 == 1;
+constexpr bool kIsArchPPC = FOLLY_PPC == 1;
constexpr bool kIsArchS390X = FOLLY_S390X == 1;
} // namespace folly
@@ -272,6 +279,9 @@ constexpr auto kIsLittleEndian = false;
#else
constexpr auto kIsLittleEndian = true;
#endif
+#elif defined(__APPLE__) && defined(__POWERPC__)
+// Darwin ppc/ppc64
+constexpr auto kIsLittleEndian = false;
#else
constexpr auto kIsLittleEndian = __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__;
#endif
diff --git folly/detail/base64_detail/Base64Api.cpp folly/detail/base64_detail/Base64Api.cpp
index 9c8493c06..4ada55281 100644
--- folly/detail/base64_detail/Base64Api.cpp
+++ folly/detail/base64_detail/Base64Api.cpp
@@ -31,10 +31,16 @@ Base64RuntimeImpl base64EncodeSelectImplementation() {
base64URLDecodeSWAR};
}
#endif
+#if defined(__POWERPC__) || (defined(__powerpc__) && defined(WORDS_BIGENDIAN)) // PowerPC BE
+ return {
+ base64EncodeScalar,
+ base64URLEncode};
+#else // Everything but PowerPC BE
return {
base64EncodeScalar,
base64URLEncodeScalar,
base64DecodeSWAR,
base64URLDecodeSWAR};
+#endif
}
} // namespace folly::detail::base64_detail
diff --git folly/io/async/AsyncUDPSocket.cpp folly/io/async/AsyncUDPSocket.cpp
index ce0e33e96..6748c9aab 100644
--- folly/io/async/AsyncUDPSocket.cpp
+++ folly/io/async/AsyncUDPSocket.cpp
@@ -262,6 +262,7 @@ void AsyncUDPSocket::init(sa_family_t family, BindOptions bindOptions) {
"failed to set IPV6_RECVTCLASS on the socket",
errno);
}
+ #ifdef IP_RECVTOS
} else if (family == AF_INET) {
if (netops::setsockopt(
socket, IPPROTO_IP, IP_RECVTOS, &flag, sizeof(flag)) != 0) {
@@ -270,6 +271,7 @@ void AsyncUDPSocket::init(sa_family_t family, BindOptions bindOptions) {
"failed to set IP_RECVTOS on the socket",
errno);
}
+ #endif
}
}
diff --git folly/net/NetOps.h folly/net/NetOps.h
index 674a216a2..c5881a7d9 100644
--- folly/net/NetOps.h
+++ folly/net/NetOps.h
@@ -261,6 +261,16 @@ struct mmsghdr {
#define F_COPY_CMSG_INT_DATA(cm, val, len) memcpy(CMSG_DATA(cm), val, len)
#endif /* _WIN32 */
+#ifndef IPV6_TCLASS
+#if defined(__APPLE__)
+#define IPV6_TCLASS 36
+#endif
+#endif
+
+#ifndef AI_NUMERICSERV
+#define AI_NUMERICSERV 0
+#endif
+
namespace folly {
namespace netops {
// Poll descriptor is intended to be byte-for-byte identical to pollfd,
diff --git folly/net/TcpInfoTypes.h folly/net/TcpInfoTypes.h
index 09a8a9907..d3a6caac4 100644
--- folly/net/TcpInfoTypes.h
+++ folly/net/TcpInfoTypes.h
@@ -179,7 +179,7 @@ struct tcp_info_legacy {
__u32 tcpi_total_retrans;
};
-#elif defined(__APPLE__)
+#elif defined(__APPLE__) && MAC_OS_X_VERSION_MIN_REQUIRED > 101003
#define FOLLY_HAVE_TCP_INFO 1
using tcp_info = ::tcp_connection_info;
const int tcp_info_sock_opt = TCP_CONNECTION_INFO;
diff --git folly/portability/Asm.h folly/portability/Asm.h
index e71da91c7..e1924c0e4 100644
--- folly/portability/Asm.h
+++ folly/portability/Asm.h
@@ -43,8 +43,10 @@ inline void asm_volatile_pause() {
asm volatile("isb");
#elif (defined(__arm__) && !(__ARM_ARCH < 7))
asm volatile("yield");
-#elif FOLLY_PPC64
+#elif FOLLY_PPC64 && !(defined(__APPLE__))
asm volatile("or 27,27,27");
+#elif (FOLLY_PPC || FOLLY_PPC64) && defined(__APPLE__)
+ __asm__ volatile ("or r27,r27,r27" ::: "memory");
#endif
}
} // namespace folly
diff --git folly/portability/Time.cpp folly/portability/Time.cpp
index 88f00150f..3f882b473 100644
--- folly/portability/Time.cpp
+++ folly/portability/Time.cpp
@@ -37,11 +37,13 @@ static void duration_to_ts(
#if !FOLLY_HAVE_CLOCK_GETTIME || FOLLY_FORCE_CLOCK_GETTIME_DEFINITION
#if __MACH__
#include <errno.h>
+#include <sys/types.h>
#include <mach/mach_init.h> // @manual
#include <mach/mach_port.h> // @manual
#include <mach/mach_time.h> // @manual
#include <mach/mach_types.h> // @manual
#include <mach/task.h> // @manual
+#include <mach/task_info.h> // for MacOS <= Lion
#include <mach/thread_act.h> // @manual
#include <mach/vm_map.h> // @manual
@@ -64,6 +66,7 @@ static int clock_process_cputime(struct timespec* ts) {
}
// Get CPU usage for terminated threads.
+#ifdef MACH_TASK_BASIC_INFO
mach_task_basic_info task_basic_info;
mach_msg_type_number_t task_basic_info_count = MACH_TASK_BASIC_INFO_COUNT;
kern_result = task_info(
@@ -74,6 +77,18 @@ static int clock_process_cputime(struct timespec* ts) {
if (UNLIKELY(kern_result != KERN_SUCCESS)) {
return -1;
}
+#else
+ task_basic_info task_basic_info;
+ mach_msg_type_number_t task_basic_info_count = TASK_BASIC_INFO_COUNT;
+ kern_result = task_info(
+ mach_task_self(),
+ TASK_BASIC_INFO,
+ (thread_info_t)&task_basic_info,
+ &task_basic_info_count);
+ if (UNLIKELY(kern_result != KERN_SUCCESS)) {
+ return -1;
+ }
+#endif
auto cputime = time_value_to_ns(thread_times_info.user_time) +
time_value_to_ns(thread_times_info.system_time) +
@@ -99,6 +114,7 @@ static int clock_thread_cputime(struct timespec* ts) {
return 0;
}
+#if defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED > 101100
FOLLY_ATTR_WEAK int clock_gettime(clockid_t clk_id, struct timespec* ts) {
switch (folly::to_underlying(clk_id)) {
case CLOCK_REALTIME: {
@@ -120,6 +136,7 @@ FOLLY_ATTR_WEAK int clock_gettime(clockid_t clk_id, struct timespec* ts) {
return -1;
}
}
+#endif
int clock_getres(clockid_t clk_id, struct timespec* ts) {
if (clk_id != CLOCK_MONOTONIC) {
@@ -190,6 +207,7 @@ extern "C" int clock_getres(clockid_t clock_id, struct timespec* res) {
res->tv_nsec = time_t(perSec * kNsPerSec);
return 0;
}
+#if defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED > 101100
case CLOCK_PROCESS_CPUTIME_ID:
case CLOCK_THREAD_CPUTIME_ID: {
DWORD adj, timeIncrement;
@@ -198,12 +216,11 @@ extern "C" int clock_getres(clockid_t clock_id, struct timespec* res) {
errno = EINVAL;
return -1;
}
-
res->tv_sec = 0;
res->tv_nsec = long(timeIncrement * 100);
return 0;
}
-
+#endif
default:
errno = EINVAL;
return -1;
@@ -236,6 +253,7 @@ extern "C" int clock_gettime(clockid_t clock_id, struct timespec* tp) {
duration_to_ts(now, tp);
return 0;
}
+#if defined(__APPLE__) && __MAC_OS_X_VERSION_MIN_REQUIRED > 101100
case CLOCK_PROCESS_CPUTIME_ID: {
if (!GetProcessTimes(
GetCurrentProcess(),
@@ -268,7 +286,7 @@ extern "C" int clock_gettime(clockid_t clock_id, struct timespec* tp) {
filetimeToUnsignedNanos(kernalTime) +
filetimeToUnsignedNanos(userTime));
}
-
+#endif
default:
errno = EINVAL;
return -1;
diff --git folly/system/ThreadId.cpp folly/system/ThreadId.cpp
index e426b39e1..b297d671f 100644
--- folly/system/ThreadId.cpp
+++ folly/system/ThreadId.cpp
@@ -40,9 +40,17 @@ namespace detail {
uint64_t getOSThreadIDSlow() {
#if __APPLE__
- uint64_t tid;
- pthread_threadid_np(nullptr, &tid);
- return tid;
+ #if MAC_OS_X_VERSION_MAX_ALLOWED < 1070
+ uint64_t tid;
+ tid = pthread_mach_thread_np(pthread_self());
+ #elif MAC_OS_X_VERSION_MIN_REQUIRED < 1070
+ uint64_t tid;
+ tid = pthread_mach_thread_np(pthread_self());
+ #else
+ uint64_t tid;
+ pthread_threadid_np(nullptr, &tid);
+ return tid;
+ #endif
#elif defined(_WIN32)
return uint64_t(GetCurrentThreadId());
#elif defined(__FreeBSD__)