remove LFS64 symbol aliases; replace with dynamic linker remapping
authorRich Felker <dalias@aerifal.cx>
Mon, 26 Sep 2022 21:14:18 +0000 (17:14 -0400)
committerRich Felker <dalias@aerifal.cx>
Wed, 19 Oct 2022 18:01:31 +0000 (14:01 -0400)
originally the namespace-infringing "large file support" interfaces
were included as part of glibc-ABI-compat, with the intent that they
not be used for linking, since our off_t is and always has been
unconditionally 64-bit and since we usually do not aim to support
nonstandard interfaces when there is an equivalent standard interface.

unfortunately, having the symbols present and available for linking
caused configure scripts to detect them and attempt to use them
without declarations, producing all the expected ill effects that
entails.

as a result, commit 2dd8d5e1b8ba1118ff1782e96545cb8a2318592c was made
to prevent this, using macros to redirect the LFS64 names to the
standard names, conditional on _GNU_SOURCE or _LARGEFILE64_SOURCE.
however, this has turned out to be a source of further problems,
especially since g++ defines _GNU_SOURCE by default. in particular,
the presence of these names as macros breaks a lot of valid code.

this commit removes all the LFS64 symbols and replaces them with a
mechanism in the dynamic linker symbol lookup failure path to retry
with the spurious "64" removed from the symbol name. in the future,
if/when the rest of glibc-ABI-compat is moved out of libc, this can be
removed.

57 files changed:
compat/time32/__xstat.c
compat/time32/aio_suspend_time32.c
compat/time32/fstat_time32.c
compat/time32/fstatat_time32.c
compat/time32/lstat_time32.c
compat/time32/stat_time32.c
ldso/dynlink.c
src/aio/aio.c
src/aio/aio_suspend.c
src/aio/lio_listio.c
src/dirent/alphasort.c
src/dirent/readdir.c
src/dirent/readdir_r.c
src/dirent/scandir.c
src/dirent/versionsort.c
src/fcntl/creat.c
src/fcntl/open.c
src/fcntl/openat.c
src/fcntl/posix_fadvise.c
src/fcntl/posix_fallocate.c
src/legacy/ftw.c
src/linux/fallocate.c
src/linux/getdents.c
src/linux/prlimit.c
src/linux/sendfile.c
src/misc/getrlimit.c
src/misc/lockf.c
src/misc/nftw.c
src/misc/setrlimit.c
src/mman/mmap.c
src/regex/glob.c
src/stat/__xstat.c
src/stat/fstat.c
src/stat/fstatat.c
src/stat/lstat.c
src/stat/stat.c
src/stat/statvfs.c
src/stdio/fgetpos.c
src/stdio/fopen.c
src/stdio/freopen.c
src/stdio/fseek.c
src/stdio/fsetpos.c
src/stdio/ftell.c
src/stdio/tmpfile.c
src/temp/mkostemp.c
src/temp/mkostemps.c
src/temp/mkstemp.c
src/temp/mkstemps.c
src/unistd/ftruncate.c
src/unistd/lseek.c
src/unistd/mipsn32/lseek.c
src/unistd/pread.c
src/unistd/preadv.c
src/unistd/pwrite.c
src/unistd/pwritev.c
src/unistd/truncate.c
src/unistd/x32/lseek.c

index acfbd3c..e52b5de 100644 (file)
@@ -3,22 +3,22 @@
 
 struct stat32;
 
-int __fxstat64(int ver, int fd, struct stat32 *buf)
+int __fxstat(int ver, int fd, struct stat32 *buf)
 {
        return __fstat_time32(fd, buf);
 }
 
-int __fxstatat64(int ver, int fd, const char *path, struct stat32 *buf, int flag)
+int __fxstatat(int ver, int fd, const char *path, struct stat32 *buf, int flag)
 {
        return __fstatat_time32(fd, path, buf, flag);
 }
 
-int __lxstat64(int ver, const char *path, struct stat32 *buf)
+int __lxstat(int ver, const char *path, struct stat32 *buf)
 {
        return __lstat_time32(path, buf);
 }
 
-int __xstat64(int ver, const char *path, struct stat32 *buf)
+int __xstat(int ver, const char *path, struct stat32 *buf)
 {
        return __stat_time32(path, buf);
 }
index ed5119b..d99cb65 100644 (file)
@@ -7,5 +7,3 @@ 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);
index 3e08439..e5d5202 100644 (file)
@@ -13,5 +13,3 @@ 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);
index 85dcb00..31d42e6 100644 (file)
@@ -13,5 +13,3 @@ 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);
index c1257a1..28cb5a0 100644 (file)
@@ -13,5 +13,3 @@ 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);
index 8c6121d..b154b0f 100644 (file)
@@ -13,5 +13,3 @@ 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);
index 03f5fd5..7b47b16 100644 (file)
@@ -337,6 +337,39 @@ 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)
+{
+       static const char *p, 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;
@@ -390,6 +423,7 @@ 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)) {
index a1a3e79..fa24f6b 100644 (file)
@@ -409,10 +409,3 @@ void __aio_atfork(int who)
                                        map[a][b][c][d] = 0;
        pthread_rwlock_unlock(&maplock);
 }
-
-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);
index 1c1060e..95def79 100644 (file)
@@ -73,7 +73,3 @@ int aio_suspend(const struct aiocb *const cbs[], int cnt, const struct timespec
                }
        }
 }
-
-#if !_REDIR_TIME64
-weak_alias(aio_suspend, aio_suspend64);
-#endif
index 0799c15..a672812 100644 (file)
@@ -139,5 +139,3 @@ int lio_listio(int mode, struct aiocb *restrict const *restrict cbs, int cnt, st
 
        return 0;
 }
-
-weak_alias(lio_listio, lio_listio64);
index bee672e..ab2624e 100644 (file)
@@ -5,5 +5,3 @@ int alphasort(const struct dirent **a, const struct dirent **b)
 {
        return strcoll((*a)->d_name, (*b)->d_name);
 }
-
-weak_alias(alphasort, alphasort64);
index 569fc70..5a03b36 100644 (file)
@@ -25,5 +25,3 @@ struct dirent *readdir(DIR *dir)
        dir->tell = de->d_off;
        return de;
 }
-
-weak_alias(readdir, readdir64);
index e2a818f..0d5de5f 100644 (file)
@@ -25,5 +25,3 @@ int readdir_r(DIR *restrict dir, struct dirent *restrict buf, struct dirent **re
        *result = buf;
        return 0;
 }
-
-weak_alias(readdir_r, readdir64_r);
index 7ee195d..7456b9b 100644 (file)
@@ -43,5 +43,3 @@ int scandir(const char *path, struct dirent ***res,
        *res = names;
        return cnt;
 }
-
-weak_alias(scandir, scandir64);
index d4c4892..9769610 100644 (file)
@@ -6,6 +6,3 @@ int versionsort(const struct dirent **a, const struct dirent **b)
 {
        return strverscmp((*a)->d_name, (*b)->d_name);
 }
-
-#undef versionsort64
-weak_alias(versionsort, versionsort64);
index 8f8aab6..c9c4391 100644 (file)
@@ -4,5 +4,3 @@ int creat(const char *filename, mode_t mode)
 {
        return open(filename, O_CREAT|O_WRONLY|O_TRUNC, mode);
 }
-
-weak_alias(creat, creat64);
index 1d817a2..4c3c827 100644 (file)
@@ -19,5 +19,3 @@ int open(const char *filename, int flags, ...)
 
        return __syscall_ret(fd);
 }
-
-weak_alias(open, open64);
index ad165ec..83a9e0d 100644 (file)
@@ -15,5 +15,3 @@ int openat(int fd, const char *filename, int flags, ...)
 
        return syscall_cp(SYS_openat, fd, filename, flags|O_LARGEFILE, mode);
 }
-
-weak_alias(openat, openat64);
index 75b8e1a..07346d2 100644 (file)
@@ -14,5 +14,3 @@ 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);
index c57a24a..80a65cb 100644 (file)
@@ -6,5 +6,3 @@ 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);
index 506bd29..e757fc6 100644 (file)
@@ -7,5 +7,3 @@ 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);
index 7d68bc8..9146350 100644 (file)
@@ -7,6 +7,3 @@ 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);
index 796c1e5..97f76e1 100644 (file)
@@ -8,5 +8,3 @@ 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);
index 3df9ffb..fcf45aa 100644 (file)
@@ -21,6 +21,3 @@ int prlimit(pid_t pid, int resource, const struct rlimit *new_limit, struct rlim
        }
        return r;
 }
-
-#undef prlimit64
-weak_alias(prlimit, prlimit64);
index 9afe6dd..fc1577d 100644 (file)
@@ -5,5 +5,3 @@ 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);
index bf67630..a5558d8 100644 (file)
@@ -26,5 +26,3 @@ int getrlimit(int resource, struct rlimit *rlim)
        return ret;
 #endif
 }
-
-weak_alias(getrlimit, getrlimit64);
index 16a80be..0162442 100644 (file)
@@ -28,5 +28,3 @@ int lockf(int fd, int op, off_t size)
        errno = EINVAL;
        return -1;
 }
-
-weak_alias(lockf, lockf64);
index 8dcff7f..fcd25a7 100644 (file)
@@ -138,5 +138,3 @@ int nftw(const char *path, int (*fn)(const char *, const struct stat *, int, str
        pthread_setcancelstate(cs, 0);
        return r;
 }
-
-weak_alias(nftw, nftw64);
index 5b713cf..edb413f 100644 (file)
@@ -49,5 +49,3 @@ int setrlimit(int resource, const struct rlimit *rlim)
        return __syscall_ret(ret);
 #endif
 }
-
-weak_alias(setrlimit, setrlimit64);
index eff88d8..43e5e02 100644 (file)
@@ -37,5 +37,3 @@ void *__mmap(void *start, size_t len, int prot, int flags, int fd, off_t off)
 }
 
 weak_alias(__mmap, mmap);
-
-weak_alias(mmap, mmap64);
index 9de080e..a490644 100644 (file)
@@ -306,6 +306,3 @@ void globfree(glob_t *g)
        g->gl_pathc = 0;
        g->gl_pathv = NULL;
 }
-
-weak_alias(glob, glob64);
-weak_alias(globfree, globfree64);
index 630936a..b4560df 100644 (file)
@@ -22,11 +22,6 @@ 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)
index 27db0cc..fd28b8a 100644 (file)
@@ -11,7 +11,3 @@ int __fstat(int fd, struct stat *st)
 }
 
 weak_alias(__fstat, fstat);
-
-#if !_REDIR_TIME64
-weak_alias(fstat, fstat64);
-#endif
index 74c51cf..0450637 100644 (file)
@@ -151,7 +151,3 @@ int __fstatat(int fd, const char *restrict path, struct stat *restrict st, int f
 }
 
 weak_alias(__fstatat, fstatat);
-
-#if !_REDIR_TIME64
-weak_alias(fstatat, fstatat64);
-#endif
index 6fe004d..6822fca 100644 (file)
@@ -5,7 +5,3 @@ int lstat(const char *restrict path, struct stat *restrict buf)
 {
        return fstatat(AT_FDCWD, path, buf, AT_SYMLINK_NOFOLLOW);
 }
-
-#if !_REDIR_TIME64
-weak_alias(lstat, lstat64);
-#endif
index ea70efc..23570e7 100644 (file)
@@ -5,7 +5,3 @@ int stat(const char *restrict path, struct stat *restrict buf)
 {
        return fstatat(AT_FDCWD, path, buf, 0);
 }
-
-#if !_REDIR_TIME64
-weak_alias(stat, stat64);
-#endif
index f65d1b5..bfbb5fe 100644 (file)
@@ -56,8 +56,3 @@ int fstatvfs(int fd, struct statvfs *buf)
        fixup(buf, &kbuf);
        return 0;
 }
-
-weak_alias(statvfs, statvfs64);
-weak_alias(statfs, statfs64);
-weak_alias(fstatvfs, fstatvfs64);
-weak_alias(fstatfs, fstatfs64);
index 50813d2..392f732 100644 (file)
@@ -7,5 +7,3 @@ int fgetpos(FILE *restrict f, fpos_t *restrict pos)
        *(long long *)pos = off;
        return 0;
 }
-
-weak_alias(fgetpos, fgetpos64);
index e1b91e1..80bc341 100644 (file)
@@ -29,5 +29,3 @@ FILE *fopen(const char *restrict filename, const char *restrict mode)
        __syscall(SYS_close, fd);
        return 0;
 }
-
-weak_alias(fopen, fopen64);
index 96bfbb4..1641a4c 100644 (file)
@@ -51,5 +51,3 @@ fail:
        fclose(f);
        return NULL;
 }
-
-weak_alias(freopen, freopen64);
index c07f7e9..c742580 100644 (file)
@@ -46,5 +46,3 @@ int fseek(FILE *f, long off, int whence)
 }
 
 weak_alias(__fseeko, fseeko);
-
-weak_alias(fseeko, fseeko64);
index 77ab8d8..779cb3c 100644 (file)
@@ -4,5 +4,3 @@ int fsetpos(FILE *f, const fpos_t *pos)
 {
        return __fseeko(f, *(const long long *)pos, SEEK_SET);
 }
-
-weak_alias(fsetpos, fsetpos64);
index 1a2afbb..1e1a08d 100644 (file)
@@ -37,5 +37,3 @@ long ftell(FILE *f)
 }
 
 weak_alias(__ftello, ftello);
-
-weak_alias(ftello, ftello64);
index ae49398..2fa8803 100644 (file)
@@ -27,5 +27,3 @@ FILE *tmpfile(void)
        }
        return 0;
 }
-
-weak_alias(tmpfile, tmpfile64);
index d8dcb80..e3dfdd9 100644 (file)
@@ -5,5 +5,3 @@ int mkostemp(char *template, int flags)
 {
        return __mkostemps(template, 0, flags);
 }
-
-weak_alias(mkostemp, mkostemp64);
index ef24eea..093d238 100644 (file)
@@ -26,4 +26,3 @@ int __mkostemps(char *template, int len, int flags)
 }
 
 weak_alias(__mkostemps, mkostemps);
-weak_alias(__mkostemps, mkostemps64);
index 166b8af..76c835b 100644 (file)
@@ -4,5 +4,3 @@ int mkstemp(char *template)
 {
        return __mkostemps(template, 0, 0);
 }
-
-weak_alias(mkstemp, mkstemp64);
index 6b7531b..f8eabfe 100644 (file)
@@ -5,5 +5,3 @@ int mkstemps(char *template, int len)
 {
        return __mkostemps(template, len, 0);
 }
-
-weak_alias(mkstemps, mkstemps64);
index b41be0f..54ff34b 100644 (file)
@@ -5,5 +5,3 @@ int ftruncate(int fd, off_t length)
 {
        return syscall(SYS_ftruncate, fd, __SYSCALL_LL_O(length));
 }
-
-weak_alias(ftruncate, ftruncate64);
index b4984f3..f5b6668 100644 (file)
@@ -12,4 +12,3 @@ off_t __lseek(int fd, off_t offset, int whence)
 }
 
 weak_alias(__lseek, lseek);
-weak_alias(__lseek, lseek64);
index 60e74a5..0f6cbca 100644 (file)
@@ -17,4 +17,3 @@ off_t __lseek(int fd, off_t offset, int whence)
 }
 
 weak_alias(__lseek, lseek);
-weak_alias(__lseek, lseek64);
index 5681b04..b03fb0a 100644 (file)
@@ -5,5 +5,3 @@ ssize_t pread(int fd, void *buf, size_t size, off_t ofs)
 {
        return syscall_cp(SYS_pread, fd, buf, size, __SYSCALL_LL_PRW(ofs));
 }
-
-weak_alias(pread, pread64);
index 8376d60..890ab40 100644 (file)
@@ -8,5 +8,3 @@ ssize_t preadv(int fd, const struct iovec *iov, int count, off_t ofs)
        return syscall_cp(SYS_preadv, fd, iov, count,
                (long)(ofs), (long)(ofs>>32));
 }
-
-weak_alias(preadv, preadv64);
index ca37657..869b69f 100644 (file)
@@ -5,5 +5,3 @@ ssize_t pwrite(int fd, const void *buf, size_t size, off_t ofs)
 {
        return syscall_cp(SYS_pwrite, fd, buf, size, __SYSCALL_LL_PRW(ofs));
 }
-
-weak_alias(pwrite, pwrite64);
index f5a612c..becf9de 100644 (file)
@@ -8,5 +8,3 @@ ssize_t pwritev(int fd, const struct iovec *iov, int count, off_t ofs)
        return syscall_cp(SYS_pwritev, fd, iov, count,
                (long)(ofs), (long)(ofs>>32));
 }
-
-weak_alias(pwritev, pwritev64);
index 9729680..077351e 100644 (file)
@@ -5,5 +5,3 @@ int truncate(const char *path, off_t length)
 {
        return syscall(SYS_truncate, path, __SYSCALL_LL_O(length));
 }
-
-weak_alias(truncate, truncate64);
index 3263642..5f93292 100644 (file)
@@ -12,4 +12,3 @@ off_t __lseek(int fd, off_t offset, int whence)
 }
 
 weak_alias(__lseek, lseek);
-weak_alias(__lseek, lseek64);