]> git.proxmox.com Git - wasi-libc.git/commitdiff
Disable the lseek optimization in C++.
authorDan Gohman <sunfish@mozilla.com>
Wed, 10 Jul 2019 00:21:38 +0000 (17:21 -0700)
committerDan Gohman <sunfish@mozilla.com>
Thu, 29 Aug 2019 14:03:29 +0000 (07:03 -0700)
The lseek optimization turns lseek calls into __wasilibc_tell calls when
possible, using macros and __builtin_constant_p. However, this isn't
safe in C++ code in the presence of namespaces and `using` declarations,
to just disable it in C++ for now.

libc-top-half/musl/include/unistd.h

index 4c7d7cc31d4a61a8fe50a964bf93ec007c8ebfd7..302e536a2fb9b672602fd320a6e591b8299a8a21 100644 (file)
@@ -55,13 +55,18 @@ int dup3(int, int, int);
 off_t lseek(int, off_t, int);
 #ifdef __wasilibc_unmodified_upstream /* Optimize the readonly case of lseek */
 #else
+off_t __wasilibc_tell(int);
+
+#ifndef __cplusplus
 /*
  * Optimize lseek in the case where it's just returning the current offset.
  * This avoids importing `__wasi_fd_seek` altogether in many common cases.
+ *
+ * But don't do this for C++ because a simple macro wouldn't handle namespaces
+ * correctly:
+ *  - User code could qualify the `lseek` call with `::`.
+ *  - There may be another `lseek` in scope from a `using` declaration.
  */
-
-off_t __wasilibc_tell(int);
-
 #define lseek(fd, offset, whence)      \
   ({                                   \
      off_t __f = (fd);                 \
@@ -75,6 +80,7 @@ off_t __wasilibc_tell(int);
      : lseek(__f, __o, __w);           \
   })
 #endif
+#endif
 int fsync(int);
 int fdatasync(int);