Skip to content

Commit

Permalink
Revert upstream musl LFS64 changes.
Browse files Browse the repository at this point in the history
Revert musl patches:
 - 246f1c811448f37a44b41cd8df8d0ef9736d95f4
 - 25e6fee27f4a293728dd15b659170e7b9c7db9bc
 - 7c41047285a24a97e700b4fb5b6b69f4505e2d82
 - 718f363bc2067b6487900eddc9180c84e7739f80

In upstream musl, these patches replace the explicit LFS64 symbols with
dynamic linker symbol lookups, which wasi-libc doesn't have. To preserve
compatibility with existing code using these symbols, revert these
patches in wasi-libc.
  • Loading branch information
sunfishcode committed Dec 11, 2024
1 parent 284dd57 commit 9873691
Show file tree
Hide file tree
Showing 70 changed files with 148 additions and 54 deletions.
8 changes: 4 additions & 4 deletions libc-top-half/musl/compat/time32/__xstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@

struct stat32;

int __fxstat(int ver, int fd, struct stat32 *buf)
int __fxstat64(int ver, int fd, struct stat32 *buf)
{
return __fstat_time32(fd, buf);
}

int __fxstatat(int ver, int fd, const char *path, struct stat32 *buf, int flag)
int __fxstatat64(int ver, int fd, const char *path, struct stat32 *buf, int flag)
{
return __fstatat_time32(fd, path, buf, flag);
}

int __lxstat(int ver, const char *path, struct stat32 *buf)
int __lxstat64(int ver, const char *path, struct stat32 *buf)
{
return __lstat_time32(path, buf);
}

int __xstat(int ver, const char *path, struct stat32 *buf)
int __xstat64(int ver, const char *path, struct stat32 *buf)
{
return __stat_time32(path, buf);
}
2 changes: 2 additions & 0 deletions libc-top-half/musl/compat/time32/aio_suspend_time32.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ int __aio_suspend_time32(const struct aiocb *const cbs[], int cnt, const struct
return aio_suspend(cbs, cnt, ts32 ? (&(struct timespec){
.tv_sec = ts32->tv_sec, .tv_nsec = ts32->tv_nsec}) : 0);
}

weak_alias(aio_suspend, aio_suspend64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/compat/time32/fstat_time32.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ int __fstat_time32(int fd, struct stat32 *restrict st32)
if (!r) memcpy(st32, &st, offsetof(struct stat, st_atim));
return r;
}

weak_alias(fstat, fstat64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/compat/time32/fstatat_time32.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ int __fstatat_time32(int fd, const char *restrict path, struct stat32 *restrict
if (!r) memcpy(st32, &st, offsetof(struct stat, st_atim));
return r;
}

weak_alias(fstatat, fstatat64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/compat/time32/lstat_time32.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ int __lstat_time32(const char *restrict path, struct stat32 *restrict st32)
if (!r) memcpy(st32, &st, offsetof(struct stat, st_atim));
return r;
}

weak_alias(lstat, lstat64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/compat/time32/stat_time32.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ int __stat_time32(const char *restrict path, struct stat32 *restrict st32)
if (!r) memcpy(st32, &st, offsetof(struct stat, st_atim));
return r;
}

weak_alias(stat, stat64);
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/aio.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int aio_fsync(int, struct aiocb *);

int lio_listio(int, struct aiocb *__restrict const *__restrict, int, struct sigevent *__restrict);

#if defined(_LARGEFILE64_SOURCE)
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define aiocb64 aiocb
#define aio_read64 aio_read
#define aio_write64 aio_write
Expand Down
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/dirent.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ int getdents(int, struct dirent *, size_t);
int versionsort(const struct dirent **, const struct dirent **);
#endif

#if defined(_LARGEFILE64_SOURCE)
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define dirent64 dirent
#define readdir64 readdir
#ifdef __wasilibc_unmodified_upstream /* readdir_r is obsolete */
Expand Down
4 changes: 1 addition & 3 deletions libc-top-half/musl/include/fcntl.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ struct f_owner_ex {
#endif
#ifdef __wasilibc_unmodified_upstream /* WASI has no fallocate */
int fallocate(int, int, off_t, off_t);
#define posix_fallocate64 posix_fallocate
#endif
#ifdef __wasilibc_unmodified_upstream /* WASI has no name_to_handle_at */
int name_to_handle_at(int, const char *, struct file_handle *, int *, int);
Expand Down Expand Up @@ -234,9 +235,6 @@ ssize_t tee(int, int, size_t, unsigned);
#define lockf64 lockf
#endif
#define posix_fadvise64 posix_fadvise
#ifdef __wasilibc_unmodified_upstream /* WASI has no fallocate */
#define posix_fallocate64 posix_fallocate
#endif
#define off64_t off_t
#ifdef __wasilibc_unmodified_upstream /* WASI has no fallocate */
#if defined(_GNU_SOURCE)
Expand Down
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/glob.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void globfree(glob_t *);
#define GLOB_NOMATCH 3
#define GLOB_NOSYS 4

#if defined(_LARGEFILE64_SOURCE)
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define glob64 glob
#define globfree64 globfree
#define glob64_t glob_t
Expand Down
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/sys/mman.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ int mincore (void *, size_t, unsigned char *);
int shm_open (const char *, int, mode_t);
int shm_unlink (const char *);

#if defined(_LARGEFILE64_SOURCE)
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define mmap64 mmap
#define off64_t off_t
#endif
Expand Down
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/sys/resource.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ int prlimit(pid_t, int, const struct rlimit *, struct rlimit *);

#define RLIM_NLIMITS RLIMIT_NLIMITS

#if defined(_LARGEFILE64_SOURCE)
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define RLIM64_INFINITY RLIM_INFINITY
#define RLIM64_SAVED_CUR RLIM_SAVED_CUR
#define RLIM64_SAVED_MAX RLIM_SAVED_MAX
Expand Down
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/sys/sendfile.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ extern "C" {

ssize_t sendfile(int, int, off_t *, size_t);

#if defined(_LARGEFILE64_SOURCE)
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define sendfile64 sendfile
#define off64_t off_t
#endif
Expand Down
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/sys/stat.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ int statx(int, const char *__restrict, int, unsigned, struct statx *__restrict);
#endif
#endif

#if defined(_LARGEFILE64_SOURCE)
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define stat64 stat
#define fstat64 fstat
#define lstat64 lstat
Expand Down
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/sys/statfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ typedef struct __fsid_t {
int statfs (const char *, struct statfs *);
int fstatfs (int, struct statfs *);

#if defined(_LARGEFILE64_SOURCE)
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define statfs64 statfs
#define fstatfs64 fstatfs
#define fsblkcnt64_t fsblkcnt_t
Expand Down
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/sys/statvfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ int fstatvfs (int, struct statvfs *);
#define ST_NODIRATIME 2048
#define ST_RELATIME 4096

#if defined(_LARGEFILE64_SOURCE)
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define statvfs64 statvfs
#define fstatvfs64 fstatvfs
#define fsblkcnt64_t fsblkcnt_t
Expand Down
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/sys/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ typedef unsigned long long u_quad_t;
#include <sys/select.h>
#endif

#if defined(_LARGEFILE64_SOURCE)
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define blkcnt64_t blkcnt_t
#define fsblkcnt64_t fsblkcnt_t
#define fsfilcnt64_t fsfilcnt_t
Expand Down
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/sys/uio.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ssize_t writev (int, const struct iovec *, int);
#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
ssize_t preadv (int, const struct iovec *, int, off_t);
ssize_t pwritev (int, const struct iovec *, int, off_t);
#if defined(_LARGEFILE64_SOURCE)
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define preadv64 preadv
#define pwritev64 pwritev
#define off64_t off_t
Expand Down
2 changes: 1 addition & 1 deletion libc-top-half/musl/include/unistd.h
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ pid_t gettid(void);
#endif
#endif

#if defined(_LARGEFILE64_SOURCE)
#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
#define lseek64 lseek
#define pread64 pread
#define pwrite64 pwrite
Expand Down
35 changes: 0 additions & 35 deletions libc-top-half/musl/ldso/dynlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,40 +345,6 @@ static struct symdef find_sym(struct dso *dso, const char *s, int need_def)
return find_sym2(dso, s, need_def, 0);
}

static struct symdef get_lfs64(const char *name)
{
const char *p;
static const char lfs64_list[] =
"aio_cancel\0aio_error\0aio_fsync\0aio_read\0aio_return\0"
"aio_suspend\0aio_write\0alphasort\0creat\0fallocate\0"
"fgetpos\0fopen\0freopen\0fseeko\0fsetpos\0fstat\0"
"fstatat\0fstatfs\0fstatvfs\0ftello\0ftruncate\0ftw\0"
"getdents\0getrlimit\0glob\0globfree\0lio_listio\0"
"lockf\0lseek\0lstat\0mkostemp\0mkostemps\0mkstemp\0"
"mkstemps\0mmap\0nftw\0open\0openat\0posix_fadvise\0"
"posix_fallocate\0pread\0preadv\0prlimit\0pwrite\0"
"pwritev\0readdir\0scandir\0sendfile\0setrlimit\0"
"stat\0statfs\0statvfs\0tmpfile\0truncate\0versionsort\0"
"__fxstat\0__fxstatat\0__lxstat\0__xstat\0";
size_t l;
char buf[16];
for (l=0; name[l]; l++) {
if (l >= sizeof buf) goto nomatch;
buf[l] = name[l];
}
if (!strcmp(name, "readdir64_r"))
return find_sym(&ldso, "readdir_r", 1);
if (l<2 || name[l-2]!='6' || name[l-1]!='4')
goto nomatch;
buf[l-=2] = 0;
for (p=lfs64_list; *p; p++) {
if (!strcmp(buf, p)) return find_sym(&ldso, buf, 1);
while (*p) p++;
}
nomatch:
return (struct symdef){ 0 };
}

static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stride)
{
unsigned char *base = dso->base;
Expand Down Expand Up @@ -432,7 +398,6 @@ static void do_relocs(struct dso *dso, size_t *rel, size_t rel_size, size_t stri
def = (sym->st_info>>4) == STB_LOCAL
? (struct symdef){ .dso = dso, .sym = sym }
: find_sym(ctx, name, type==REL_PLT);
if (!def.sym) def = get_lfs64(name);
if (!def.sym && (sym->st_shndx != SHN_UNDEF
|| sym->st_info>>4 != STB_WEAK)) {
if (dso->lazy && (type==REL_PLT || type==REL_GOT)) {
Expand Down
7 changes: 7 additions & 0 deletions libc-top-half/musl/src/aio/aio.c
Original file line number Diff line number Diff line change
Expand Up @@ -430,3 +430,10 @@ void __aio_atfork(int who)
* We are not a lock holder anyway; the thread in the parent was. */
pthread_rwlock_init(&maplock, 0);
}

weak_alias(aio_cancel, aio_cancel64);
weak_alias(aio_error, aio_error64);
weak_alias(aio_fsync, aio_fsync64);
weak_alias(aio_read, aio_read64);
weak_alias(aio_write, aio_write64);
weak_alias(aio_return, aio_return64);
4 changes: 4 additions & 0 deletions libc-top-half/musl/src/aio/aio_suspend.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,7 @@ int aio_suspend(const struct aiocb *const cbs[], int cnt, const struct timespec
}
}
}

#if !_REDIR_TIME64
weak_alias(aio_suspend, aio_suspend64);
#endif
2 changes: 2 additions & 0 deletions libc-top-half/musl/src/aio/lio_listio.c
Original file line number Diff line number Diff line change
Expand Up @@ -139,3 +139,5 @@ int lio_listio(int mode, struct aiocb *restrict const *restrict cbs, int cnt, st

return 0;
}

weak_alias(lio_listio, lio_listio64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/src/dirent/alphasort.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ int alphasort(const struct dirent **a, const struct dirent **b)
{
return strcoll((*a)->d_name, (*b)->d_name);
}

weak_alias(alphasort, alphasort64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/src/dirent/readdir.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ struct dirent *readdir(DIR *dir)
dir->tell = de->d_off;
return de;
}

weak_alias(readdir, readdir64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/src/dirent/readdir_r.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ int readdir_r(DIR *restrict dir, struct dirent *restrict buf, struct dirent **re
*result = buf;
return 0;
}

weak_alias(readdir_r, readdir64_r);
2 changes: 2 additions & 0 deletions libc-top-half/musl/src/dirent/scandir.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,5 @@ int scandir(const char *path, struct dirent ***res,
*res = names;
return cnt;
}

weak_alias(scandir, scandir64);
3 changes: 3 additions & 0 deletions libc-top-half/musl/src/dirent/versionsort.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ int versionsort(const struct dirent **a, const struct dirent **b)
{
return strverscmp((*a)->d_name, (*b)->d_name);
}

#undef versionsort64
weak_alias(versionsort, versionsort64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/src/fcntl/creat.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ int creat(const char *filename, mode_t mode)
{
return open(filename, O_CREAT|O_WRONLY|O_TRUNC, mode);
}

weak_alias(creat, creat64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/src/fcntl/open.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,5 @@ int open(const char *filename, int flags, ...)

return __syscall_ret(fd);
}

weak_alias(open, open64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/src/fcntl/openat.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,5 @@ int openat(int fd, const char *filename, int flags, ...)

return syscall_cp(SYS_openat, fd, filename, flags|O_LARGEFILE, mode);
}

weak_alias(openat, openat64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/src/fcntl/posix_fadvise.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ int posix_fadvise(int fd, off_t base, off_t len, int advice)
__SYSCALL_LL_E(len), advice);
#endif
}

weak_alias(posix_fadvise, posix_fadvise64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/src/fcntl/posix_fallocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ int posix_fallocate(int fd, off_t base, off_t len)
return -__syscall(SYS_fallocate, fd, 0, __SYSCALL_LL_E(base),
__SYSCALL_LL_E(len));
}

weak_alias(posix_fallocate, posix_fallocate64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/src/legacy/ftw.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ int ftw(const char *path, int (*fn)(const char *, const struct stat *, int), int
* actually undefined, but works on all real-world machines. */
return nftw(path, (int (*)())fn, fd_limit, FTW_PHYS);
}

weak_alias(ftw, ftw64);
3 changes: 3 additions & 0 deletions libc-top-half/musl/src/linux/fallocate.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ int fallocate(int fd, int mode, off_t base, off_t len)
return syscall(SYS_fallocate, fd, mode, __SYSCALL_LL_E(base),
__SYSCALL_LL_E(len));
}

#undef fallocate64
weak_alias(fallocate, fallocate64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/src/linux/getdents.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ int getdents(int fd, struct dirent *buf, size_t len)
if (len>INT_MAX) len = INT_MAX;
return syscall(SYS_getdents, fd, buf, len);
}

weak_alias(getdents, getdents64);
3 changes: 3 additions & 0 deletions libc-top-half/musl/src/linux/prlimit.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,6 @@ int prlimit(pid_t pid, int resource, const struct rlimit *new_limit, struct rlim
}
return r;
}

#undef prlimit64
weak_alias(prlimit, prlimit64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/src/linux/sendfile.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ ssize_t sendfile(int out_fd, int in_fd, off_t *ofs, size_t count)
{
return syscall(SYS_sendfile, out_fd, in_fd, ofs, count);
}

weak_alias(sendfile, sendfile64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/src/misc/getrlimit.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,5 @@ int getrlimit(int resource, struct rlimit *rlim)
return ret;
#endif
}

weak_alias(getrlimit, getrlimit64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/src/misc/lockf.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ int lockf(int fd, int op, off_t size)
errno = EINVAL;
return -1;
}

weak_alias(lockf, lockf64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/src/misc/nftw.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,5 @@ int nftw(const char *path, int (*fn)(const char *, const struct stat *, int, str
#endif
return r;
}

weak_alias(nftw, nftw64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/src/misc/setrlimit.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,5 @@ int setrlimit(int resource, const struct rlimit *rlim)
return __syscall_ret(ret);
#endif
}

weak_alias(setrlimit, setrlimit64);
2 changes: 2 additions & 0 deletions libc-top-half/musl/src/mman/mmap.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,5 @@ void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off)
}

weak_alias(__mmap, mmap);

weak_alias(mmap, mmap64);
3 changes: 3 additions & 0 deletions libc-top-half/musl/src/regex/glob.c
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,6 @@ void globfree(glob_t *g)
g->gl_pathc = 0;
g->gl_pathv = NULL;
}

weak_alias(glob, glob64);
weak_alias(globfree, globfree64);
5 changes: 5 additions & 0 deletions libc-top-half/musl/src/stat/__xstat.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ int __xstat(int ver, const char *path, struct stat *buf)
return stat(path, buf);
}

weak_alias(__fxstat, __fxstat64);
weak_alias(__fxstatat, __fxstatat64);
weak_alias(__lxstat, __lxstat64);
weak_alias(__xstat, __xstat64);

#endif

int __xmknod(int ver, const char *path, mode_t mode, dev_t *dev)
Expand Down
Loading

0 comments on commit 9873691

Please sign in to comment.