Skip to content

Commit 7d2354e

Browse files
committed
Disable the lseek optimization in C++.
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.
1 parent 255e6f7 commit 7d2354e

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,18 @@ int dup3(int, int, int);
5555
off_t lseek(int, off_t, int);
5656
#ifdef __wasilibc_unmodified_upstream /* Optimize the readonly case of lseek */
5757
#else
58+
off_t __wasilibc_tell(int);
59+
60+
#ifndef __cplusplus
5861
/*
5962
* Optimize lseek in the case where it's just returning the current offset.
6063
* This avoids importing `__wasi_fd_seek` altogether in many common cases.
64+
*
65+
* But don't do this for C++ because a simple macro wouldn't handle namespaces
66+
* correctly:
67+
* - User code could qualify the `lseek` call with `::`.
68+
* - There may be another `lseek` in scope from a `using` declaration.
6169
*/
62-
63-
off_t __wasilibc_tell(int);
64-
6570
#define lseek(fd, offset, whence) \
6671
({ \
6772
off_t __f = (fd); \
@@ -75,6 +80,7 @@ off_t __wasilibc_tell(int);
7580
: lseek(__f, __o, __w); \
7681
})
7782
#endif
83+
#endif
7884
int fsync(int);
7985
int fdatasync(int);
8086

0 commit comments

Comments
 (0)