|
| 1 | +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Ben Noordhuis <info@bnoordhuis.nl> |
| 3 | +Date: Tue, 28 Jan 2025 09:27:58 +0100 |
| 4 | +Subject: linux: try preadv64/pwritev64 before preadv/pwritev (#4683) |
| 5 | + |
| 6 | +Fixes: https://github.com/libuv/libuv/issues/4678 |
| 7 | +Refs: https://github.com/libuv/libuv/issues/4532 |
| 8 | + |
| 9 | +diff --git a/deps/uv/src/unix/fs.c b/deps/uv/src/unix/fs.c |
| 10 | +index 239ecda16a7eb9b40453502cf0362ae66366cf72..1631d9340bc10c2ac4c3d53a63ed9bc10f3e1c7c 100644 |
| 11 | +--- a/deps/uv/src/unix/fs.c |
| 12 | ++++ b/deps/uv/src/unix/fs.c |
| 13 | +@@ -461,12 +461,7 @@ static ssize_t uv__pwritev_emul(int fd, |
| 14 | + |
| 15 | + /* The function pointer cache is an uintptr_t because _Atomic void* |
| 16 | + * doesn't work on macos/ios/etc... |
| 17 | +- * Disable optimization on armv7 to work around the bug described in |
| 18 | +- * https://github.com/libuv/libuv/issues/4532 |
| 19 | + */ |
| 20 | +-#if defined(__arm__) && (__ARM_ARCH == 7) |
| 21 | +-__attribute__((optimize("O0"))) |
| 22 | +-#endif |
| 23 | + static ssize_t uv__preadv_or_pwritev(int fd, |
| 24 | + const struct iovec* bufs, |
| 25 | + size_t nbufs, |
| 26 | +@@ -479,7 +474,12 @@ static ssize_t uv__preadv_or_pwritev(int fd, |
| 27 | + p = (void*) atomic_load_explicit(cache, memory_order_relaxed); |
| 28 | + if (p == NULL) { |
| 29 | + #ifdef RTLD_DEFAULT |
| 30 | +- p = dlsym(RTLD_DEFAULT, is_pread ? "preadv" : "pwritev"); |
| 31 | ++ /* Try _LARGEFILE_SOURCE version of preadv/pwritev first, |
| 32 | ++ * then fall back to the plain version, for libcs like musl. |
| 33 | ++ */ |
| 34 | ++ p = dlsym(RTLD_DEFAULT, is_pread ? "preadv64" : "pwritev64"); |
| 35 | ++ if (p == NULL) |
| 36 | ++ p = dlsym(RTLD_DEFAULT, is_pread ? "preadv" : "pwritev"); |
| 37 | + dlerror(); /* Clear errors. */ |
| 38 | + #endif /* RTLD_DEFAULT */ |
| 39 | + if (p == NULL) |
| 40 | +@@ -487,10 +487,7 @@ static ssize_t uv__preadv_or_pwritev(int fd, |
| 41 | + atomic_store_explicit(cache, (uintptr_t) p, memory_order_relaxed); |
| 42 | + } |
| 43 | + |
| 44 | +- /* Use memcpy instead of `f = p` to work around a compiler bug, |
| 45 | +- * see https://github.com/libuv/libuv/issues/4532 |
| 46 | +- */ |
| 47 | +- memcpy(&f, &p, sizeof(p)); |
| 48 | ++ f = p; |
| 49 | + return f(fd, bufs, nbufs, off); |
| 50 | + } |
| 51 | + |
0 commit comments