mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Revisiting LFS64 removal
@ 2022-09-26  1:03 Rich Felker
  2022-09-26 16:03 ` Markus Wichmann
  2022-09-26 22:04 ` Rich Felker
  0 siblings, 2 replies; 17+ messages in thread
From: Rich Felker @ 2022-09-26  1:03 UTC (permalink / raw)
  To: musl

Seeing a recent wrong-fix commit in binutils
(https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=fe39ffdc202f04397f31557f17170b40bc42b77a)
reminded me of the longstanding "we need to remove LFS64" issue.

To recap the story here, musl originally include the LFS64 (open64,
lseek64, etc.) interfaces as a glibc-ABI-compat measure. I can't find
the exact location where it's discussed in the project history, but my
recollection of what happened was that this caused configure scripts
doing link-only testing to determine that these functions exist then
try to use them (without declarations, leading to catastrophic
breakage like truncation of pointers in return values.

Then commit 2dd8d5e1b8ba1118ff1782e96545cb8a2318592c came along and
exposed these as public interfaces, but only as macros, to avoid
further linking to the unwanted symbols. (I'll note that the commit
message seems wrong, as it talks about possibly eventually adding weak
alias symbols, but those already existed since the start.)

It turns out that adding the macros was a really bad idea. While
they're only exposed with _GNU_SOURCE, g++ always defines _GNU_SOURCE,
and various things have broken in the same mode as the above binutils
commit was trying to fix.

Of course these interfaces should not be used, and we never intended
for them to be used just there for linking-compat. So, I've wanted to
get rid of them for a long time now.

I believe the simplest short-term way is probably going to be just
having the dynamic linker symbol lookup error path make one final
check before bailing out with an error:

- If the symbol to lookup ends in "64"..
- ..and it's in a hard-coded list of LFS64-compat symbols..
- ..and looking up the name with the "64" removed in libc succeeds..

Then use the version without the "64" suffix and go on with relocation
processing.

Hopefully this will not affect performance in non-error code paths
whatsoever.

In the long term, I still want to aim to move *all* the
glibc-ABI-compat symbols out of musl and into the gcompat project's
jurisdiction, and work on mechanisms for ldso to automatically load
gcompat where "libc.so.6" is referenced.

Does the above plan present any non-obvious problems? The only
limitation I'm aware of is that it only works for dynamic linking not
static. I don't really see this as a problem, as if you're static
linking .a's/.o's made for glibc, you can use tooling to patch them up
first.

Rich

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [musl] Revisiting LFS64 removal
  2022-09-26  1:03 [musl] Revisiting LFS64 removal Rich Felker
@ 2022-09-26 16:03 ` Markus Wichmann
  2022-09-26 16:47   ` Rich Felker
  2022-09-26 22:04 ` Rich Felker
  1 sibling, 1 reply; 17+ messages in thread
From: Markus Wichmann @ 2022-09-26 16:03 UTC (permalink / raw)
  To: musl

On Sun, Sep 25, 2022 at 09:03:40PM -0400, Rich Felker wrote:
> Seeing a recent wrong-fix commit in binutils
> (https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=fe39ffdc202f04397f31557f17170b40bc42b77a)
> reminded me of the longstanding "we need to remove LFS64" issue.
>

Whenever I see stuff like that, it makes me break out in hives. The
stupidest part is that the commit is adding configure tests, so they
could just test for the things they want. But no, they test for
something unrelated and then assume that that has the implications they
want.

> I believe the simplest short-term way is probably going to be just
> having the dynamic linker symbol lookup error path make one final
> check before bailing out with an error:
>
> - If the symbol to lookup ends in "64"..
> - ..and it's in a hard-coded list of LFS64-compat symbols..
> - ..and looking up the name with the "64" removed in libc succeeds..
>
> Then use the version without the "64" suffix and go on with relocation
> processing.
>

Took me a while to figure out what you were trying to do here: You want
to hide the LFS64 symbols at link-time. At compile-time, the macros
prevent actual use of those symbols, at link-time, access will fail, but
the symbols will still be there at dynamic load-time, so existing
binaries don't break.

Of course, that means that you will have to keep the kludge around for
the foreseeable future, as even if those symbols are added to
libgcompat, existing binaries would break if it were removed (since
existing binaries do not depend on libgcompat), which violates the musl
ABI stability goals. Oh well, it's not going to be the last bit of
legacy cruft in the library.

Ciao,
Markus

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [musl] Revisiting LFS64 removal
  2022-09-26 16:03 ` Markus Wichmann
@ 2022-09-26 16:47   ` Rich Felker
  0 siblings, 0 replies; 17+ messages in thread
From: Rich Felker @ 2022-09-26 16:47 UTC (permalink / raw)
  To: Markus Wichmann; +Cc: musl

On Mon, Sep 26, 2022 at 06:03:32PM +0200, Markus Wichmann wrote:
> On Sun, Sep 25, 2022 at 09:03:40PM -0400, Rich Felker wrote:
> > Seeing a recent wrong-fix commit in binutils
> > (https://sourceware.org/git/?p=binutils-gdb.git;a=commitdiff;h=fe39ffdc202f04397f31557f17170b40bc42b77a)
> > reminded me of the longstanding "we need to remove LFS64" issue.
> >
> 
> Whenever I see stuff like that, it makes me break out in hives. The
> stupidest part is that the commit is adding configure tests, so they
> could just test for the things they want. But no, they test for
> something unrelated and then assume that that has the implications they
> want.

Exactly.

> > I believe the simplest short-term way is probably going to be just
> > having the dynamic linker symbol lookup error path make one final
> > check before bailing out with an error:
> >
> > - If the symbol to lookup ends in "64"..
> > - ..and it's in a hard-coded list of LFS64-compat symbols..
> > - ..and looking up the name with the "64" removed in libc succeeds..
> >
> > Then use the version without the "64" suffix and go on with relocation
> > processing.
> >
> 
> Took me a while to figure out what you were trying to do here: You want
> to hide the LFS64 symbols at link-time. At compile-time, the macros
> prevent actual use of those symbols, at link-time, access will fail, but
> the symbols will still be there at dynamic load-time, so existing
> binaries don't break.
> 
> Of course, that means that you will have to keep the kludge around for
> the foreseeable future, as even if those symbols are added to
> libgcompat, existing binaries would break if it were removed (since
> existing binaries do not depend on libgcompat), which violates the musl
> ABI stability goals. Oh well, it's not going to be the last bit of
> legacy cruft in the library.

No, that's not the case. ABI stability is only guaranteed for ABIs
that result from use of the public APIs. If you pull in a symbol that
was accidentally exposed by not marking it hidden, or by manually
declaring some glibc-ABI-compat symbol that's not part of the public
API, or anything like that, you get to keep both parts when it breaks.
OTOH if a public API generates a reference to a symbol, then that
symbol is stable ABI.

Rich

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [musl] Revisiting LFS64 removal
  2022-09-26  1:03 [musl] Revisiting LFS64 removal Rich Felker
  2022-09-26 16:03 ` Markus Wichmann
@ 2022-09-26 22:04 ` Rich Felker
  2022-09-27  9:09   ` Gabriel Ravier
  1 sibling, 1 reply; 17+ messages in thread
From: Rich Felker @ 2022-09-26 22:04 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 729 bytes --]

On Sun, Sep 25, 2022 at 09:03:40PM -0400, Rich Felker wrote:
> [...]
> Of course these interfaces should not be used, and we never intended
> for them to be used just there for linking-compat. So, I've wanted to
> get rid of them for a long time now.
> 
> I believe the simplest short-term way is probably going to be just
> having the dynamic linker symbol lookup error path make one final
> check before bailing out with an error:
> 
> - If the symbol to lookup ends in "64"..
> - ..and it's in a hard-coded list of LFS64-compat symbols..
> - ..and looking up the name with the "64" removed in libc succeeds..
> 
> Then use the version without the "64" suffix and go on with relocation
> processing.

Proposed patch attached.


[-- Attachment #2: 0001-remove-LFS64-symbol-aliases-replace-with-dynamic-lin.patch --]
[-- Type: text/plain, Size: 23423 bytes --]

From 46a39430c751323defd9177df97bbb453f561a68 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Mon, 26 Sep 2022 17:14:18 -0400
Subject: [PATCH] remove LFS64 symbol aliases; replace with dynamic linker
 remapping

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.
---
 compat/time32/aio_suspend_time32.c |  2 --
 compat/time32/fstat_time32.c       |  2 --
 compat/time32/fstatat_time32.c     |  2 --
 compat/time32/lstat_time32.c       |  2 --
 compat/time32/stat_time32.c        |  2 --
 ldso/dynlink.c                     | 33 ++++++++++++++++++++++++++++++
 src/aio/aio.c                      |  7 -------
 src/aio/aio_suspend.c              |  4 ----
 src/aio/lio_listio.c               |  2 --
 src/dirent/alphasort.c             |  2 --
 src/dirent/readdir.c               |  2 --
 src/dirent/readdir_r.c             |  2 --
 src/dirent/scandir.c               |  2 --
 src/dirent/versionsort.c           |  3 ---
 src/fcntl/creat.c                  |  2 --
 src/fcntl/open.c                   |  2 --
 src/fcntl/openat.c                 |  2 --
 src/fcntl/posix_fadvise.c          |  2 --
 src/fcntl/posix_fallocate.c        |  2 --
 src/legacy/ftw.c                   |  2 --
 src/linux/fallocate.c              |  3 ---
 src/linux/getdents.c               |  2 --
 src/linux/prlimit.c                |  3 ---
 src/linux/sendfile.c               |  2 --
 src/misc/getrlimit.c               |  2 --
 src/misc/lockf.c                   |  2 --
 src/misc/nftw.c                    |  2 --
 src/misc/setrlimit.c               |  2 --
 src/mman/mmap.c                    |  2 --
 src/regex/glob.c                   |  3 ---
 src/stat/__xstat.c                 |  5 -----
 src/stat/fstat.c                   |  4 ----
 src/stat/fstatat.c                 |  4 ----
 src/stat/lstat.c                   |  4 ----
 src/stat/stat.c                    |  4 ----
 src/stat/statvfs.c                 |  5 -----
 src/stdio/fgetpos.c                |  2 --
 src/stdio/fopen.c                  |  2 --
 src/stdio/freopen.c                |  2 --
 src/stdio/fseek.c                  |  2 --
 src/stdio/fsetpos.c                |  2 --
 src/stdio/ftell.c                  |  2 --
 src/stdio/tmpfile.c                |  2 --
 src/temp/mkostemp.c                |  2 --
 src/temp/mkostemps.c               |  1 -
 src/temp/mkstemp.c                 |  2 --
 src/temp/mkstemps.c                |  2 --
 src/unistd/ftruncate.c             |  2 --
 src/unistd/lseek.c                 |  1 -
 src/unistd/mipsn32/lseek.c         |  1 -
 src/unistd/pread.c                 |  2 --
 src/unistd/preadv.c                |  2 --
 src/unistd/pwrite.c                |  2 --
 src/unistd/pwritev.c               |  2 --
 src/unistd/truncate.c              |  2 --
 src/unistd/x32/lseek.c             |  1 -
 56 files changed, 33 insertions(+), 131 deletions(-)

diff --git a/compat/time32/aio_suspend_time32.c b/compat/time32/aio_suspend_time32.c
index ed5119bd..d99cb651 100644
--- a/compat/time32/aio_suspend_time32.c
+++ b/compat/time32/aio_suspend_time32.c
@@ -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);
diff --git a/compat/time32/fstat_time32.c b/compat/time32/fstat_time32.c
index 3e084398..e5d52022 100644
--- a/compat/time32/fstat_time32.c
+++ b/compat/time32/fstat_time32.c
@@ -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);
diff --git a/compat/time32/fstatat_time32.c b/compat/time32/fstatat_time32.c
index 85dcb008..31d42e63 100644
--- a/compat/time32/fstatat_time32.c
+++ b/compat/time32/fstatat_time32.c
@@ -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);
diff --git a/compat/time32/lstat_time32.c b/compat/time32/lstat_time32.c
index c1257a14..28cb5a0b 100644
--- a/compat/time32/lstat_time32.c
+++ b/compat/time32/lstat_time32.c
@@ -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);
diff --git a/compat/time32/stat_time32.c b/compat/time32/stat_time32.c
index 8c6121da..b154b0f9 100644
--- a/compat/time32/stat_time32.c
+++ b/compat/time32/stat_time32.c
@@ -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);
diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index 03f5fd59..890dc438 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -337,6 +337,38 @@ 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++)
+		buf[l] = name[l];
+	if (l>=sizeof buf || l<2)
+		return (struct symdef){ 0 };
+	if (!strcmp(name, "readdir64_r"))
+		return find_sym(&ldso, "readdir_r", 1);
+	if (l>=sizeof buf || l<2 || name[l-2]!='6' || name[l-1]!='4')
+		return (struct symdef){ 0 };
+	buf[l-=2] = 0;
+	for (p=lfs64_list; *p; p++) {
+		if (!strcmp(buf, p)) return find_sym(&ldso, buf, 1);
+		while (*p) p++;
+	}
+	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 +422,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)) {
diff --git a/src/aio/aio.c b/src/aio/aio.c
index a1a3e791..fa24f6b6 100644
--- a/src/aio/aio.c
+++ b/src/aio/aio.c
@@ -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);
diff --git a/src/aio/aio_suspend.c b/src/aio/aio_suspend.c
index 1c1060e3..95def796 100644
--- a/src/aio/aio_suspend.c
+++ b/src/aio/aio_suspend.c
@@ -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
diff --git a/src/aio/lio_listio.c b/src/aio/lio_listio.c
index 0799c15d..a672812f 100644
--- a/src/aio/lio_listio.c
+++ b/src/aio/lio_listio.c
@@ -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);
diff --git a/src/dirent/alphasort.c b/src/dirent/alphasort.c
index bee672eb..ab2624e2 100644
--- a/src/dirent/alphasort.c
+++ b/src/dirent/alphasort.c
@@ -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);
diff --git a/src/dirent/readdir.c b/src/dirent/readdir.c
index 569fc705..5a03b363 100644
--- a/src/dirent/readdir.c
+++ b/src/dirent/readdir.c
@@ -25,5 +25,3 @@ struct dirent *readdir(DIR *dir)
 	dir->tell = de->d_off;
 	return de;
 }
-
-weak_alias(readdir, readdir64);
diff --git a/src/dirent/readdir_r.c b/src/dirent/readdir_r.c
index e2a818f3..0d5de5f5 100644
--- a/src/dirent/readdir_r.c
+++ b/src/dirent/readdir_r.c
@@ -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);
diff --git a/src/dirent/scandir.c b/src/dirent/scandir.c
index 7ee195dd..7456b9b8 100644
--- a/src/dirent/scandir.c
+++ b/src/dirent/scandir.c
@@ -43,5 +43,3 @@ int scandir(const char *path, struct dirent ***res,
 	*res = names;
 	return cnt;
 }
-
-weak_alias(scandir, scandir64);
diff --git a/src/dirent/versionsort.c b/src/dirent/versionsort.c
index d4c48923..97696105 100644
--- a/src/dirent/versionsort.c
+++ b/src/dirent/versionsort.c
@@ -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);
diff --git a/src/fcntl/creat.c b/src/fcntl/creat.c
index 8f8aab64..c9c43910 100644
--- a/src/fcntl/creat.c
+++ b/src/fcntl/creat.c
@@ -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);
diff --git a/src/fcntl/open.c b/src/fcntl/open.c
index 1d817a2d..4c3c8275 100644
--- a/src/fcntl/open.c
+++ b/src/fcntl/open.c
@@ -19,5 +19,3 @@ int open(const char *filename, int flags, ...)
 
 	return __syscall_ret(fd);
 }
-
-weak_alias(open, open64);
diff --git a/src/fcntl/openat.c b/src/fcntl/openat.c
index ad165ec3..83a9e0d0 100644
--- a/src/fcntl/openat.c
+++ b/src/fcntl/openat.c
@@ -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);
diff --git a/src/fcntl/posix_fadvise.c b/src/fcntl/posix_fadvise.c
index 75b8e1ae..07346d21 100644
--- a/src/fcntl/posix_fadvise.c
+++ b/src/fcntl/posix_fadvise.c
@@ -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);
diff --git a/src/fcntl/posix_fallocate.c b/src/fcntl/posix_fallocate.c
index c57a24ae..80a65cbf 100644
--- a/src/fcntl/posix_fallocate.c
+++ b/src/fcntl/posix_fallocate.c
@@ -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);
diff --git a/src/legacy/ftw.c b/src/legacy/ftw.c
index 506bd29c..e757fc6f 100644
--- a/src/legacy/ftw.c
+++ b/src/legacy/ftw.c
@@ -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);
diff --git a/src/linux/fallocate.c b/src/linux/fallocate.c
index 7d68bc8f..9146350e 100644
--- a/src/linux/fallocate.c
+++ b/src/linux/fallocate.c
@@ -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);
diff --git a/src/linux/getdents.c b/src/linux/getdents.c
index 796c1e5c..97f76e14 100644
--- a/src/linux/getdents.c
+++ b/src/linux/getdents.c
@@ -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);
diff --git a/src/linux/prlimit.c b/src/linux/prlimit.c
index 3df9ffba..fcf45aab 100644
--- a/src/linux/prlimit.c
+++ b/src/linux/prlimit.c
@@ -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);
diff --git a/src/linux/sendfile.c b/src/linux/sendfile.c
index 9afe6dd6..fc1577d3 100644
--- a/src/linux/sendfile.c
+++ b/src/linux/sendfile.c
@@ -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);
diff --git a/src/misc/getrlimit.c b/src/misc/getrlimit.c
index bf676307..a5558d81 100644
--- a/src/misc/getrlimit.c
+++ b/src/misc/getrlimit.c
@@ -26,5 +26,3 @@ int getrlimit(int resource, struct rlimit *rlim)
 	return ret;
 #endif
 }
-
-weak_alias(getrlimit, getrlimit64);
diff --git a/src/misc/lockf.c b/src/misc/lockf.c
index 16a80bec..0162442b 100644
--- a/src/misc/lockf.c
+++ b/src/misc/lockf.c
@@ -28,5 +28,3 @@ int lockf(int fd, int op, off_t size)
 	errno = EINVAL;
 	return -1;
 }
-
-weak_alias(lockf, lockf64);
diff --git a/src/misc/nftw.c b/src/misc/nftw.c
index 8dcff7fe..fcd25a73 100644
--- a/src/misc/nftw.c
+++ b/src/misc/nftw.c
@@ -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);
diff --git a/src/misc/setrlimit.c b/src/misc/setrlimit.c
index 5b713cf3..edb413fa 100644
--- a/src/misc/setrlimit.c
+++ b/src/misc/setrlimit.c
@@ -49,5 +49,3 @@ int setrlimit(int resource, const struct rlimit *rlim)
 	return __syscall_ret(ret);
 #endif
 }
-
-weak_alias(setrlimit, setrlimit64);
diff --git a/src/mman/mmap.c b/src/mman/mmap.c
index eff88d82..43e5e029 100644
--- a/src/mman/mmap.c
+++ b/src/mman/mmap.c
@@ -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);
diff --git a/src/regex/glob.c b/src/regex/glob.c
index 9de080ed..a4906446 100644
--- a/src/regex/glob.c
+++ b/src/regex/glob.c
@@ -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);
diff --git a/src/stat/__xstat.c b/src/stat/__xstat.c
index 630936a0..b4560df7 100644
--- a/src/stat/__xstat.c
+++ b/src/stat/__xstat.c
@@ -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)
diff --git a/src/stat/fstat.c b/src/stat/fstat.c
index 27db0ccb..fd28b8ac 100644
--- a/src/stat/fstat.c
+++ b/src/stat/fstat.c
@@ -11,7 +11,3 @@ int __fstat(int fd, struct stat *st)
 }
 
 weak_alias(__fstat, fstat);
-
-#if !_REDIR_TIME64
-weak_alias(fstat, fstat64);
-#endif
diff --git a/src/stat/fstatat.c b/src/stat/fstatat.c
index 74c51cf5..04506375 100644
--- a/src/stat/fstatat.c
+++ b/src/stat/fstatat.c
@@ -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
diff --git a/src/stat/lstat.c b/src/stat/lstat.c
index 6fe004de..6822fcae 100644
--- a/src/stat/lstat.c
+++ b/src/stat/lstat.c
@@ -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
diff --git a/src/stat/stat.c b/src/stat/stat.c
index ea70efc4..23570e7a 100644
--- a/src/stat/stat.c
+++ b/src/stat/stat.c
@@ -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
diff --git a/src/stat/statvfs.c b/src/stat/statvfs.c
index f65d1b54..bfbb5fee 100644
--- a/src/stat/statvfs.c
+++ b/src/stat/statvfs.c
@@ -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);
diff --git a/src/stdio/fgetpos.c b/src/stdio/fgetpos.c
index 50813d2c..392f7323 100644
--- a/src/stdio/fgetpos.c
+++ b/src/stdio/fgetpos.c
@@ -7,5 +7,3 @@ int fgetpos(FILE *restrict f, fpos_t *restrict pos)
 	*(long long *)pos = off;
 	return 0;
 }
-
-weak_alias(fgetpos, fgetpos64);
diff --git a/src/stdio/fopen.c b/src/stdio/fopen.c
index e1b91e12..80bc341e 100644
--- a/src/stdio/fopen.c
+++ b/src/stdio/fopen.c
@@ -29,5 +29,3 @@ FILE *fopen(const char *restrict filename, const char *restrict mode)
 	__syscall(SYS_close, fd);
 	return 0;
 }
-
-weak_alias(fopen, fopen64);
diff --git a/src/stdio/freopen.c b/src/stdio/freopen.c
index 96bfbb42..1641a4c5 100644
--- a/src/stdio/freopen.c
+++ b/src/stdio/freopen.c
@@ -51,5 +51,3 @@ fail:
 	fclose(f);
 	return NULL;
 }
-
-weak_alias(freopen, freopen64);
diff --git a/src/stdio/fseek.c b/src/stdio/fseek.c
index c07f7e95..c7425802 100644
--- a/src/stdio/fseek.c
+++ b/src/stdio/fseek.c
@@ -46,5 +46,3 @@ int fseek(FILE *f, long off, int whence)
 }
 
 weak_alias(__fseeko, fseeko);
-
-weak_alias(fseeko, fseeko64);
diff --git a/src/stdio/fsetpos.c b/src/stdio/fsetpos.c
index 77ab8d82..779cb3cc 100644
--- a/src/stdio/fsetpos.c
+++ b/src/stdio/fsetpos.c
@@ -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);
diff --git a/src/stdio/ftell.c b/src/stdio/ftell.c
index 1a2afbbc..1e1a08d8 100644
--- a/src/stdio/ftell.c
+++ b/src/stdio/ftell.c
@@ -37,5 +37,3 @@ long ftell(FILE *f)
 }
 
 weak_alias(__ftello, ftello);
-
-weak_alias(ftello, ftello64);
diff --git a/src/stdio/tmpfile.c b/src/stdio/tmpfile.c
index ae493987..2fa8803f 100644
--- a/src/stdio/tmpfile.c
+++ b/src/stdio/tmpfile.c
@@ -27,5 +27,3 @@ FILE *tmpfile(void)
 	}
 	return 0;
 }
-
-weak_alias(tmpfile, tmpfile64);
diff --git a/src/temp/mkostemp.c b/src/temp/mkostemp.c
index d8dcb805..e3dfdd91 100644
--- a/src/temp/mkostemp.c
+++ b/src/temp/mkostemp.c
@@ -5,5 +5,3 @@ int mkostemp(char *template, int flags)
 {
 	return __mkostemps(template, 0, flags);
 }
-
-weak_alias(mkostemp, mkostemp64);
diff --git a/src/temp/mkostemps.c b/src/temp/mkostemps.c
index ef24eeae..093d2380 100644
--- a/src/temp/mkostemps.c
+++ b/src/temp/mkostemps.c
@@ -26,4 +26,3 @@ int __mkostemps(char *template, int len, int flags)
 }
 
 weak_alias(__mkostemps, mkostemps);
-weak_alias(__mkostemps, mkostemps64);
diff --git a/src/temp/mkstemp.c b/src/temp/mkstemp.c
index 166b8afe..76c835bb 100644
--- a/src/temp/mkstemp.c
+++ b/src/temp/mkstemp.c
@@ -4,5 +4,3 @@ int mkstemp(char *template)
 {
 	return __mkostemps(template, 0, 0);
 }
-
-weak_alias(mkstemp, mkstemp64);
diff --git a/src/temp/mkstemps.c b/src/temp/mkstemps.c
index 6b7531b5..f8eabfec 100644
--- a/src/temp/mkstemps.c
+++ b/src/temp/mkstemps.c
@@ -5,5 +5,3 @@ int mkstemps(char *template, int len)
 {
 	return __mkostemps(template, len, 0);
 }
-
-weak_alias(mkstemps, mkstemps64);
diff --git a/src/unistd/ftruncate.c b/src/unistd/ftruncate.c
index b41be0fa..54ff34bc 100644
--- a/src/unistd/ftruncate.c
+++ b/src/unistd/ftruncate.c
@@ -5,5 +5,3 @@ int ftruncate(int fd, off_t length)
 {
 	return syscall(SYS_ftruncate, fd, __SYSCALL_LL_O(length));
 }
-
-weak_alias(ftruncate, ftruncate64);
diff --git a/src/unistd/lseek.c b/src/unistd/lseek.c
index b4984f3e..f5b66682 100644
--- a/src/unistd/lseek.c
+++ b/src/unistd/lseek.c
@@ -12,4 +12,3 @@ off_t __lseek(int fd, off_t offset, int whence)
 }
 
 weak_alias(__lseek, lseek);
-weak_alias(__lseek, lseek64);
diff --git a/src/unistd/mipsn32/lseek.c b/src/unistd/mipsn32/lseek.c
index 60e74a51..0f6cbcaa 100644
--- a/src/unistd/mipsn32/lseek.c
+++ b/src/unistd/mipsn32/lseek.c
@@ -17,4 +17,3 @@ off_t __lseek(int fd, off_t offset, int whence)
 }
 
 weak_alias(__lseek, lseek);
-weak_alias(__lseek, lseek64);
diff --git a/src/unistd/pread.c b/src/unistd/pread.c
index 5681b045..b03fb0ad 100644
--- a/src/unistd/pread.c
+++ b/src/unistd/pread.c
@@ -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);
diff --git a/src/unistd/preadv.c b/src/unistd/preadv.c
index 8376d60f..890ab403 100644
--- a/src/unistd/preadv.c
+++ b/src/unistd/preadv.c
@@ -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);
diff --git a/src/unistd/pwrite.c b/src/unistd/pwrite.c
index ca376576..869b69f0 100644
--- a/src/unistd/pwrite.c
+++ b/src/unistd/pwrite.c
@@ -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);
diff --git a/src/unistd/pwritev.c b/src/unistd/pwritev.c
index f5a612c4..becf9deb 100644
--- a/src/unistd/pwritev.c
+++ b/src/unistd/pwritev.c
@@ -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);
diff --git a/src/unistd/truncate.c b/src/unistd/truncate.c
index 97296800..077351e1 100644
--- a/src/unistd/truncate.c
+++ b/src/unistd/truncate.c
@@ -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);
diff --git a/src/unistd/x32/lseek.c b/src/unistd/x32/lseek.c
index 32636429..5f93292f 100644
--- a/src/unistd/x32/lseek.c
+++ b/src/unistd/x32/lseek.c
@@ -12,4 +12,3 @@ off_t __lseek(int fd, off_t offset, int whence)
 }
 
 weak_alias(__lseek, lseek);
-weak_alias(__lseek, lseek64);
-- 
2.21.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [musl] Revisiting LFS64 removal
  2022-09-26 22:04 ` Rich Felker
@ 2022-09-27  9:09   ` Gabriel Ravier
  2022-09-27 12:20     ` Rich Felker
  0 siblings, 1 reply; 17+ messages in thread
From: Gabriel Ravier @ 2022-09-27  9:09 UTC (permalink / raw)
  To: musl, Rich Felker

On 9/27/22 00:04, Rich Felker wrote:
> On Sun, Sep 25, 2022 at 09:03:40PM -0400, Rich Felker wrote:
>> [...]
>> Of course these interfaces should not be used, and we never intended
>> for them to be used just there for linking-compat. So, I've wanted to
>> get rid of them for a long time now.
>>
>> I believe the simplest short-term way is probably going to be just
>> having the dynamic linker symbol lookup error path make one final
>> check before bailing out with an error:
>>
>> - If the symbol to lookup ends in "64"..
>> - ..and it's in a hard-coded list of LFS64-compat symbols..
>> - ..and looking up the name with the "64" removed in libc succeeds..
>>
>> Then use the version without the "64" suffix and go on with relocation
>> processing.
> Proposed patch attached.
>
Looks at though the patch contains a buffer overflow to me, as the 
length of `name` appears to be unbounded, but it's then copied into 
`buf` which has its size limited to 16, all without checking for `l >= 
sizeof buf` until after the copying is done (which might just even get 
optimized out by GCC since it knows `l` can't be larger than buf without 
UB occuring)

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [musl] Revisiting LFS64 removal
  2022-09-27  9:09   ` Gabriel Ravier
@ 2022-09-27 12:20     ` Rich Felker
  2022-09-27 19:03       ` Rich Felker
  0 siblings, 1 reply; 17+ messages in thread
From: Rich Felker @ 2022-09-27 12:20 UTC (permalink / raw)
  To: Gabriel Ravier; +Cc: musl

On Tue, Sep 27, 2022 at 11:09:48AM +0200, Gabriel Ravier wrote:
> On 9/27/22 00:04, Rich Felker wrote:
> >On Sun, Sep 25, 2022 at 09:03:40PM -0400, Rich Felker wrote:
> >>[...]
> >>Of course these interfaces should not be used, and we never intended
> >>for them to be used just there for linking-compat. So, I've wanted to
> >>get rid of them for a long time now.
> >>
> >>I believe the simplest short-term way is probably going to be just
> >>having the dynamic linker symbol lookup error path make one final
> >>check before bailing out with an error:
> >>
> >>- If the symbol to lookup ends in "64"..
> >>- ..and it's in a hard-coded list of LFS64-compat symbols..
> >>- ..and looking up the name with the "64" removed in libc succeeds..
> >>
> >>Then use the version without the "64" suffix and go on with relocation
> >>processing.
> >Proposed patch attached.
> >
> Looks at though the patch contains a buffer overflow to me, as the
> length of `name` appears to be unbounded, but it's then copied into
> `buf` which has its size limited to 16, all without checking for `l
> >= sizeof buf` until after the copying is done (which might just
> even get optimized out by GCC since it knows `l` can't be larger
> than buf without UB occuring)

Thanks for the catch! It was a late change I made to avoid
re-iterating but indeed it's wrong. (Note that strlen, etc. can't be
used here because external function calls or even references are not
valid in the context this can be called in; strcmp is a macro that
expands to a static function call.)

Rich

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [musl] Revisiting LFS64 removal
  2022-09-27 12:20     ` Rich Felker
@ 2022-09-27 19:03       ` Rich Felker
  2022-09-27 19:08         ` Rich Felker
  0 siblings, 1 reply; 17+ messages in thread
From: Rich Felker @ 2022-09-27 19:03 UTC (permalink / raw)
  To: Gabriel Ravier; +Cc: musl

[-- Attachment #1: Type: text/plain, Size: 1689 bytes --]

On Tue, Sep 27, 2022 at 08:20:05AM -0400, Rich Felker wrote:
> On Tue, Sep 27, 2022 at 11:09:48AM +0200, Gabriel Ravier wrote:
> > On 9/27/22 00:04, Rich Felker wrote:
> > >On Sun, Sep 25, 2022 at 09:03:40PM -0400, Rich Felker wrote:
> > >>[...]
> > >>Of course these interfaces should not be used, and we never intended
> > >>for them to be used just there for linking-compat. So, I've wanted to
> > >>get rid of them for a long time now.
> > >>
> > >>I believe the simplest short-term way is probably going to be just
> > >>having the dynamic linker symbol lookup error path make one final
> > >>check before bailing out with an error:
> > >>
> > >>- If the symbol to lookup ends in "64"..
> > >>- ..and it's in a hard-coded list of LFS64-compat symbols..
> > >>- ..and looking up the name with the "64" removed in libc succeeds..
> > >>
> > >>Then use the version without the "64" suffix and go on with relocation
> > >>processing.
> > >Proposed patch attached.
> > >
> > Looks at though the patch contains a buffer overflow to me, as the
> > length of `name` appears to be unbounded, but it's then copied into
> > `buf` which has its size limited to 16, all without checking for `l
> > >= sizeof buf` until after the copying is done (which might just
> > even get optimized out by GCC since it knows `l` can't be larger
> > than buf without UB occuring)
> 
> Thanks for the catch! It was a late change I made to avoid
> re-iterating but indeed it's wrong. (Note that strlen, etc. can't be
> used here because external function calls or even references are not
> valid in the context this can be called in; strcmp is a macro that
> expands to a static function call.)

Updated version.

[-- Attachment #2: 0001-remove-LFS64-symbol-aliases-replace-with-dynamic-lin.patch --]
[-- Type: text/plain, Size: 24323 bytes --]

From efcf3118b144a3cf7703b1c934582005c0e850c3 Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Mon, 26 Sep 2022 17:14:18 -0400
Subject: [PATCH] remove LFS64 symbol aliases; replace with dynamic linker
 remapping

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.
---
 compat/time32/__xstat.c            |  8 +++----
 compat/time32/aio_suspend_time32.c |  2 --
 compat/time32/fstat_time32.c       |  2 --
 compat/time32/fstatat_time32.c     |  2 --
 compat/time32/lstat_time32.c       |  2 --
 compat/time32/stat_time32.c        |  2 --
 ldso/dynlink.c                     | 34 ++++++++++++++++++++++++++++++
 src/aio/aio.c                      |  7 ------
 src/aio/aio_suspend.c              |  4 ----
 src/aio/lio_listio.c               |  2 --
 src/dirent/alphasort.c             |  2 --
 src/dirent/readdir.c               |  2 --
 src/dirent/readdir_r.c             |  2 --
 src/dirent/scandir.c               |  2 --
 src/dirent/versionsort.c           |  3 ---
 src/fcntl/creat.c                  |  2 --
 src/fcntl/open.c                   |  2 --
 src/fcntl/openat.c                 |  2 --
 src/fcntl/posix_fadvise.c          |  2 --
 src/fcntl/posix_fallocate.c        |  2 --
 src/legacy/ftw.c                   |  2 --
 src/linux/fallocate.c              |  3 ---
 src/linux/getdents.c               |  2 --
 src/linux/prlimit.c                |  3 ---
 src/linux/sendfile.c               |  2 --
 src/misc/getrlimit.c               |  2 --
 src/misc/lockf.c                   |  2 --
 src/misc/nftw.c                    |  2 --
 src/misc/setrlimit.c               |  2 --
 src/mman/mmap.c                    |  2 --
 src/regex/glob.c                   |  3 ---
 src/stat/__xstat.c                 |  5 -----
 src/stat/fstat.c                   |  4 ----
 src/stat/fstatat.c                 |  4 ----
 src/stat/lstat.c                   |  4 ----
 src/stat/stat.c                    |  4 ----
 src/stat/statvfs.c                 |  5 -----
 src/stdio/fgetpos.c                |  2 --
 src/stdio/fopen.c                  |  2 --
 src/stdio/freopen.c                |  2 --
 src/stdio/fseek.c                  |  2 --
 src/stdio/fsetpos.c                |  2 --
 src/stdio/ftell.c                  |  2 --
 src/stdio/tmpfile.c                |  2 --
 src/temp/mkostemp.c                |  2 --
 src/temp/mkostemps.c               |  1 -
 src/temp/mkstemp.c                 |  2 --
 src/temp/mkstemps.c                |  2 --
 src/unistd/ftruncate.c             |  2 --
 src/unistd/lseek.c                 |  1 -
 src/unistd/mipsn32/lseek.c         |  1 -
 src/unistd/pread.c                 |  2 --
 src/unistd/preadv.c                |  2 --
 src/unistd/pwrite.c                |  2 --
 src/unistd/pwritev.c               |  2 --
 src/unistd/truncate.c              |  2 --
 src/unistd/x32/lseek.c             |  1 -
 57 files changed, 38 insertions(+), 135 deletions(-)

diff --git a/compat/time32/__xstat.c b/compat/time32/__xstat.c
index acfbd3cc..e52b5deb 100644
--- a/compat/time32/__xstat.c
+++ b/compat/time32/__xstat.c
@@ -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);
 }
diff --git a/compat/time32/aio_suspend_time32.c b/compat/time32/aio_suspend_time32.c
index ed5119bd..d99cb651 100644
--- a/compat/time32/aio_suspend_time32.c
+++ b/compat/time32/aio_suspend_time32.c
@@ -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);
diff --git a/compat/time32/fstat_time32.c b/compat/time32/fstat_time32.c
index 3e084398..e5d52022 100644
--- a/compat/time32/fstat_time32.c
+++ b/compat/time32/fstat_time32.c
@@ -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);
diff --git a/compat/time32/fstatat_time32.c b/compat/time32/fstatat_time32.c
index 85dcb008..31d42e63 100644
--- a/compat/time32/fstatat_time32.c
+++ b/compat/time32/fstatat_time32.c
@@ -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);
diff --git a/compat/time32/lstat_time32.c b/compat/time32/lstat_time32.c
index c1257a14..28cb5a0b 100644
--- a/compat/time32/lstat_time32.c
+++ b/compat/time32/lstat_time32.c
@@ -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);
diff --git a/compat/time32/stat_time32.c b/compat/time32/stat_time32.c
index 8c6121da..b154b0f9 100644
--- a/compat/time32/stat_time32.c
+++ b/compat/time32/stat_time32.c
@@ -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);
diff --git a/ldso/dynlink.c b/ldso/dynlink.c
index 03f5fd59..7b47b163 100644
--- a/ldso/dynlink.c
+++ b/ldso/dynlink.c
@@ -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)) {
diff --git a/src/aio/aio.c b/src/aio/aio.c
index a1a3e791..fa24f6b6 100644
--- a/src/aio/aio.c
+++ b/src/aio/aio.c
@@ -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);
diff --git a/src/aio/aio_suspend.c b/src/aio/aio_suspend.c
index 1c1060e3..95def796 100644
--- a/src/aio/aio_suspend.c
+++ b/src/aio/aio_suspend.c
@@ -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
diff --git a/src/aio/lio_listio.c b/src/aio/lio_listio.c
index 0799c15d..a672812f 100644
--- a/src/aio/lio_listio.c
+++ b/src/aio/lio_listio.c
@@ -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);
diff --git a/src/dirent/alphasort.c b/src/dirent/alphasort.c
index bee672eb..ab2624e2 100644
--- a/src/dirent/alphasort.c
+++ b/src/dirent/alphasort.c
@@ -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);
diff --git a/src/dirent/readdir.c b/src/dirent/readdir.c
index 569fc705..5a03b363 100644
--- a/src/dirent/readdir.c
+++ b/src/dirent/readdir.c
@@ -25,5 +25,3 @@ struct dirent *readdir(DIR *dir)
 	dir->tell = de->d_off;
 	return de;
 }
-
-weak_alias(readdir, readdir64);
diff --git a/src/dirent/readdir_r.c b/src/dirent/readdir_r.c
index e2a818f3..0d5de5f5 100644
--- a/src/dirent/readdir_r.c
+++ b/src/dirent/readdir_r.c
@@ -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);
diff --git a/src/dirent/scandir.c b/src/dirent/scandir.c
index 7ee195dd..7456b9b8 100644
--- a/src/dirent/scandir.c
+++ b/src/dirent/scandir.c
@@ -43,5 +43,3 @@ int scandir(const char *path, struct dirent ***res,
 	*res = names;
 	return cnt;
 }
-
-weak_alias(scandir, scandir64);
diff --git a/src/dirent/versionsort.c b/src/dirent/versionsort.c
index d4c48923..97696105 100644
--- a/src/dirent/versionsort.c
+++ b/src/dirent/versionsort.c
@@ -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);
diff --git a/src/fcntl/creat.c b/src/fcntl/creat.c
index 8f8aab64..c9c43910 100644
--- a/src/fcntl/creat.c
+++ b/src/fcntl/creat.c
@@ -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);
diff --git a/src/fcntl/open.c b/src/fcntl/open.c
index 1d817a2d..4c3c8275 100644
--- a/src/fcntl/open.c
+++ b/src/fcntl/open.c
@@ -19,5 +19,3 @@ int open(const char *filename, int flags, ...)
 
 	return __syscall_ret(fd);
 }
-
-weak_alias(open, open64);
diff --git a/src/fcntl/openat.c b/src/fcntl/openat.c
index ad165ec3..83a9e0d0 100644
--- a/src/fcntl/openat.c
+++ b/src/fcntl/openat.c
@@ -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);
diff --git a/src/fcntl/posix_fadvise.c b/src/fcntl/posix_fadvise.c
index 75b8e1ae..07346d21 100644
--- a/src/fcntl/posix_fadvise.c
+++ b/src/fcntl/posix_fadvise.c
@@ -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);
diff --git a/src/fcntl/posix_fallocate.c b/src/fcntl/posix_fallocate.c
index c57a24ae..80a65cbf 100644
--- a/src/fcntl/posix_fallocate.c
+++ b/src/fcntl/posix_fallocate.c
@@ -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);
diff --git a/src/legacy/ftw.c b/src/legacy/ftw.c
index 506bd29c..e757fc6f 100644
--- a/src/legacy/ftw.c
+++ b/src/legacy/ftw.c
@@ -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);
diff --git a/src/linux/fallocate.c b/src/linux/fallocate.c
index 7d68bc8f..9146350e 100644
--- a/src/linux/fallocate.c
+++ b/src/linux/fallocate.c
@@ -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);
diff --git a/src/linux/getdents.c b/src/linux/getdents.c
index 796c1e5c..97f76e14 100644
--- a/src/linux/getdents.c
+++ b/src/linux/getdents.c
@@ -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);
diff --git a/src/linux/prlimit.c b/src/linux/prlimit.c
index 3df9ffba..fcf45aab 100644
--- a/src/linux/prlimit.c
+++ b/src/linux/prlimit.c
@@ -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);
diff --git a/src/linux/sendfile.c b/src/linux/sendfile.c
index 9afe6dd6..fc1577d3 100644
--- a/src/linux/sendfile.c
+++ b/src/linux/sendfile.c
@@ -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);
diff --git a/src/misc/getrlimit.c b/src/misc/getrlimit.c
index bf676307..a5558d81 100644
--- a/src/misc/getrlimit.c
+++ b/src/misc/getrlimit.c
@@ -26,5 +26,3 @@ int getrlimit(int resource, struct rlimit *rlim)
 	return ret;
 #endif
 }
-
-weak_alias(getrlimit, getrlimit64);
diff --git a/src/misc/lockf.c b/src/misc/lockf.c
index 16a80bec..0162442b 100644
--- a/src/misc/lockf.c
+++ b/src/misc/lockf.c
@@ -28,5 +28,3 @@ int lockf(int fd, int op, off_t size)
 	errno = EINVAL;
 	return -1;
 }
-
-weak_alias(lockf, lockf64);
diff --git a/src/misc/nftw.c b/src/misc/nftw.c
index 8dcff7fe..fcd25a73 100644
--- a/src/misc/nftw.c
+++ b/src/misc/nftw.c
@@ -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);
diff --git a/src/misc/setrlimit.c b/src/misc/setrlimit.c
index 5b713cf3..edb413fa 100644
--- a/src/misc/setrlimit.c
+++ b/src/misc/setrlimit.c
@@ -49,5 +49,3 @@ int setrlimit(int resource, const struct rlimit *rlim)
 	return __syscall_ret(ret);
 #endif
 }
-
-weak_alias(setrlimit, setrlimit64);
diff --git a/src/mman/mmap.c b/src/mman/mmap.c
index eff88d82..43e5e029 100644
--- a/src/mman/mmap.c
+++ b/src/mman/mmap.c
@@ -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);
diff --git a/src/regex/glob.c b/src/regex/glob.c
index 9de080ed..a4906446 100644
--- a/src/regex/glob.c
+++ b/src/regex/glob.c
@@ -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);
diff --git a/src/stat/__xstat.c b/src/stat/__xstat.c
index 630936a0..b4560df7 100644
--- a/src/stat/__xstat.c
+++ b/src/stat/__xstat.c
@@ -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)
diff --git a/src/stat/fstat.c b/src/stat/fstat.c
index 27db0ccb..fd28b8ac 100644
--- a/src/stat/fstat.c
+++ b/src/stat/fstat.c
@@ -11,7 +11,3 @@ int __fstat(int fd, struct stat *st)
 }
 
 weak_alias(__fstat, fstat);
-
-#if !_REDIR_TIME64
-weak_alias(fstat, fstat64);
-#endif
diff --git a/src/stat/fstatat.c b/src/stat/fstatat.c
index 74c51cf5..04506375 100644
--- a/src/stat/fstatat.c
+++ b/src/stat/fstatat.c
@@ -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
diff --git a/src/stat/lstat.c b/src/stat/lstat.c
index 6fe004de..6822fcae 100644
--- a/src/stat/lstat.c
+++ b/src/stat/lstat.c
@@ -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
diff --git a/src/stat/stat.c b/src/stat/stat.c
index ea70efc4..23570e7a 100644
--- a/src/stat/stat.c
+++ b/src/stat/stat.c
@@ -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
diff --git a/src/stat/statvfs.c b/src/stat/statvfs.c
index f65d1b54..bfbb5fee 100644
--- a/src/stat/statvfs.c
+++ b/src/stat/statvfs.c
@@ -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);
diff --git a/src/stdio/fgetpos.c b/src/stdio/fgetpos.c
index 50813d2c..392f7323 100644
--- a/src/stdio/fgetpos.c
+++ b/src/stdio/fgetpos.c
@@ -7,5 +7,3 @@ int fgetpos(FILE *restrict f, fpos_t *restrict pos)
 	*(long long *)pos = off;
 	return 0;
 }
-
-weak_alias(fgetpos, fgetpos64);
diff --git a/src/stdio/fopen.c b/src/stdio/fopen.c
index e1b91e12..80bc341e 100644
--- a/src/stdio/fopen.c
+++ b/src/stdio/fopen.c
@@ -29,5 +29,3 @@ FILE *fopen(const char *restrict filename, const char *restrict mode)
 	__syscall(SYS_close, fd);
 	return 0;
 }
-
-weak_alias(fopen, fopen64);
diff --git a/src/stdio/freopen.c b/src/stdio/freopen.c
index 96bfbb42..1641a4c5 100644
--- a/src/stdio/freopen.c
+++ b/src/stdio/freopen.c
@@ -51,5 +51,3 @@ fail:
 	fclose(f);
 	return NULL;
 }
-
-weak_alias(freopen, freopen64);
diff --git a/src/stdio/fseek.c b/src/stdio/fseek.c
index c07f7e95..c7425802 100644
--- a/src/stdio/fseek.c
+++ b/src/stdio/fseek.c
@@ -46,5 +46,3 @@ int fseek(FILE *f, long off, int whence)
 }
 
 weak_alias(__fseeko, fseeko);
-
-weak_alias(fseeko, fseeko64);
diff --git a/src/stdio/fsetpos.c b/src/stdio/fsetpos.c
index 77ab8d82..779cb3cc 100644
--- a/src/stdio/fsetpos.c
+++ b/src/stdio/fsetpos.c
@@ -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);
diff --git a/src/stdio/ftell.c b/src/stdio/ftell.c
index 1a2afbbc..1e1a08d8 100644
--- a/src/stdio/ftell.c
+++ b/src/stdio/ftell.c
@@ -37,5 +37,3 @@ long ftell(FILE *f)
 }
 
 weak_alias(__ftello, ftello);
-
-weak_alias(ftello, ftello64);
diff --git a/src/stdio/tmpfile.c b/src/stdio/tmpfile.c
index ae493987..2fa8803f 100644
--- a/src/stdio/tmpfile.c
+++ b/src/stdio/tmpfile.c
@@ -27,5 +27,3 @@ FILE *tmpfile(void)
 	}
 	return 0;
 }
-
-weak_alias(tmpfile, tmpfile64);
diff --git a/src/temp/mkostemp.c b/src/temp/mkostemp.c
index d8dcb805..e3dfdd91 100644
--- a/src/temp/mkostemp.c
+++ b/src/temp/mkostemp.c
@@ -5,5 +5,3 @@ int mkostemp(char *template, int flags)
 {
 	return __mkostemps(template, 0, flags);
 }
-
-weak_alias(mkostemp, mkostemp64);
diff --git a/src/temp/mkostemps.c b/src/temp/mkostemps.c
index ef24eeae..093d2380 100644
--- a/src/temp/mkostemps.c
+++ b/src/temp/mkostemps.c
@@ -26,4 +26,3 @@ int __mkostemps(char *template, int len, int flags)
 }
 
 weak_alias(__mkostemps, mkostemps);
-weak_alias(__mkostemps, mkostemps64);
diff --git a/src/temp/mkstemp.c b/src/temp/mkstemp.c
index 166b8afe..76c835bb 100644
--- a/src/temp/mkstemp.c
+++ b/src/temp/mkstemp.c
@@ -4,5 +4,3 @@ int mkstemp(char *template)
 {
 	return __mkostemps(template, 0, 0);
 }
-
-weak_alias(mkstemp, mkstemp64);
diff --git a/src/temp/mkstemps.c b/src/temp/mkstemps.c
index 6b7531b5..f8eabfec 100644
--- a/src/temp/mkstemps.c
+++ b/src/temp/mkstemps.c
@@ -5,5 +5,3 @@ int mkstemps(char *template, int len)
 {
 	return __mkostemps(template, len, 0);
 }
-
-weak_alias(mkstemps, mkstemps64);
diff --git a/src/unistd/ftruncate.c b/src/unistd/ftruncate.c
index b41be0fa..54ff34bc 100644
--- a/src/unistd/ftruncate.c
+++ b/src/unistd/ftruncate.c
@@ -5,5 +5,3 @@ int ftruncate(int fd, off_t length)
 {
 	return syscall(SYS_ftruncate, fd, __SYSCALL_LL_O(length));
 }
-
-weak_alias(ftruncate, ftruncate64);
diff --git a/src/unistd/lseek.c b/src/unistd/lseek.c
index b4984f3e..f5b66682 100644
--- a/src/unistd/lseek.c
+++ b/src/unistd/lseek.c
@@ -12,4 +12,3 @@ off_t __lseek(int fd, off_t offset, int whence)
 }
 
 weak_alias(__lseek, lseek);
-weak_alias(__lseek, lseek64);
diff --git a/src/unistd/mipsn32/lseek.c b/src/unistd/mipsn32/lseek.c
index 60e74a51..0f6cbcaa 100644
--- a/src/unistd/mipsn32/lseek.c
+++ b/src/unistd/mipsn32/lseek.c
@@ -17,4 +17,3 @@ off_t __lseek(int fd, off_t offset, int whence)
 }
 
 weak_alias(__lseek, lseek);
-weak_alias(__lseek, lseek64);
diff --git a/src/unistd/pread.c b/src/unistd/pread.c
index 5681b045..b03fb0ad 100644
--- a/src/unistd/pread.c
+++ b/src/unistd/pread.c
@@ -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);
diff --git a/src/unistd/preadv.c b/src/unistd/preadv.c
index 8376d60f..890ab403 100644
--- a/src/unistd/preadv.c
+++ b/src/unistd/preadv.c
@@ -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);
diff --git a/src/unistd/pwrite.c b/src/unistd/pwrite.c
index ca376576..869b69f0 100644
--- a/src/unistd/pwrite.c
+++ b/src/unistd/pwrite.c
@@ -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);
diff --git a/src/unistd/pwritev.c b/src/unistd/pwritev.c
index f5a612c4..becf9deb 100644
--- a/src/unistd/pwritev.c
+++ b/src/unistd/pwritev.c
@@ -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);
diff --git a/src/unistd/truncate.c b/src/unistd/truncate.c
index 97296800..077351e1 100644
--- a/src/unistd/truncate.c
+++ b/src/unistd/truncate.c
@@ -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);
diff --git a/src/unistd/x32/lseek.c b/src/unistd/x32/lseek.c
index 32636429..5f93292f 100644
--- a/src/unistd/x32/lseek.c
+++ b/src/unistd/x32/lseek.c
@@ -12,4 +12,3 @@ off_t __lseek(int fd, off_t offset, int whence)
 }
 
 weak_alias(__lseek, lseek);
-weak_alias(__lseek, lseek64);
-- 
2.21.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [musl] Revisiting LFS64 removal
  2022-09-27 19:03       ` Rich Felker
@ 2022-09-27 19:08         ` Rich Felker
  2022-09-29 23:07           ` Rich Felker
  0 siblings, 1 reply; 17+ messages in thread
From: Rich Felker @ 2022-09-27 19:08 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 2132 bytes --]

On Tue, Sep 27, 2022 at 03:03:57PM -0400, Rich Felker wrote:
> On Tue, Sep 27, 2022 at 08:20:05AM -0400, Rich Felker wrote:
> > On Tue, Sep 27, 2022 at 11:09:48AM +0200, Gabriel Ravier wrote:
> > > On 9/27/22 00:04, Rich Felker wrote:
> > > >On Sun, Sep 25, 2022 at 09:03:40PM -0400, Rich Felker wrote:
> > > >>[...]
> > > >>Of course these interfaces should not be used, and we never intended
> > > >>for them to be used just there for linking-compat. So, I've wanted to
> > > >>get rid of them for a long time now.
> > > >>
> > > >>I believe the simplest short-term way is probably going to be just
> > > >>having the dynamic linker symbol lookup error path make one final
> > > >>check before bailing out with an error:
> > > >>
> > > >>- If the symbol to lookup ends in "64"..
> > > >>- ..and it's in a hard-coded list of LFS64-compat symbols..
> > > >>- ..and looking up the name with the "64" removed in libc succeeds..
> > > >>
> > > >>Then use the version without the "64" suffix and go on with relocation
> > > >>processing.
> > > >Proposed patch attached.
> > > >
> > > Looks at though the patch contains a buffer overflow to me, as the
> > > length of `name` appears to be unbounded, but it's then copied into
> > > `buf` which has its size limited to 16, all without checking for `l
> > > >= sizeof buf` until after the copying is done (which might just
> > > even get optimized out by GCC since it knows `l` can't be larger
> > > than buf without UB occuring)
> > 
> > Thanks for the catch! It was a late change I made to avoid
> > re-iterating but indeed it's wrong. (Note that strlen, etc. can't be
> > used here because external function calls or even references are not
> > valid in the context this can be called in; strcmp is a macro that
> > expands to a static function call.)
> 
> Updated version.

And the follow-up patch which removes the macro interfaces. Note that
there's not necessarily any reason these need to be done together.
Removing the macros is not safe without removing the symbols, due to
autoconf badness, but once the symbols are gone we're free to choose
if/when to remove the macros.

Rich

[-- Attachment #2: 0002-remove-LFS64-programming-interfaces-macro-only-from-.patch --]
[-- Type: text/plain, Size: 9863 bytes --]

From aac73f06584ea256eec7724d95622f09f30385bd Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Tue, 27 Sep 2022 15:04:05 -0400
Subject: [PATCH] remove LFS64 programming interfaces (macro-only) from public
 headers

these badly pollute the namespace with macros whenever _GNU_SOURCE is
defined, which is always the case with g++, and especially tends to
interfere with C++ constructs.

as our implementation of these was macro-only, their removal cannot
affect any existing binaries. at the source level, portable software
should be prepared for them not to exist.
---
 include/aio.h          | 13 -------------
 include/dirent.h       | 12 ------------
 include/fcntl.h        | 14 --------------
 include/ftw.h          |  5 -----
 include/glob.h         |  6 ------
 include/stdio.h        | 12 ------------
 include/stdlib.h       |  9 ---------
 include/sys/mman.h     |  5 -----
 include/sys/resource.h | 10 ----------
 include/sys/sendfile.h |  5 -----
 include/sys/stat.h     | 12 ------------
 include/sys/statfs.h   |  7 -------
 include/sys/statvfs.h  |  7 -------
 include/sys/types.h    |  8 --------
 include/sys/uio.h      |  5 -----
 include/unistd.h       | 10 ----------
 16 files changed, 140 deletions(-)

diff --git a/include/aio.h b/include/aio.h
index 453c41b7..c5198938 100644
--- a/include/aio.h
+++ b/include/aio.h
@@ -49,19 +49,6 @@ int aio_fsync(int, struct aiocb *);
 
 int lio_listio(int, struct aiocb *__restrict const *__restrict, int, struct sigevent *__restrict);
 
-#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
-#define aiocb64 aiocb
-#define aio_read64 aio_read
-#define aio_write64 aio_write
-#define aio_error64 aio_error
-#define aio_return64 aio_return
-#define aio_cancel64 aio_cancel
-#define aio_suspend64 aio_suspend
-#define aio_fsync64 aio_fsync
-#define lio_listio64 lio_listio
-#define off64_t off_t
-#endif
-
 #if _REDIR_TIME64
 __REDIR(aio_suspend, __aio_suspend_time64);
 #endif
diff --git a/include/dirent.h b/include/dirent.h
index 650ecf64..7ec7cf69 100644
--- a/include/dirent.h
+++ b/include/dirent.h
@@ -56,18 +56,6 @@ int getdents(int, struct dirent *, size_t);
 int versionsort(const struct dirent **, const struct dirent **);
 #endif
 
-#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
-#define dirent64 dirent
-#define readdir64 readdir
-#define readdir64_r readdir_r
-#define scandir64 scandir
-#define alphasort64 alphasort
-#define versionsort64 versionsort
-#define off64_t off_t
-#define ino64_t ino_t
-#define getdents64 getdents
-#endif
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/fcntl.h b/include/fcntl.h
index b664cdc4..3494fde4 100644
--- a/include/fcntl.h
+++ b/include/fcntl.h
@@ -195,20 +195,6 @@ ssize_t tee(int, int, size_t, unsigned);
 #define loff_t off_t
 #endif
 
-#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
-#define F_GETLK64 F_GETLK
-#define F_SETLK64 F_SETLK
-#define F_SETLKW64 F_SETLKW
-#define flock64 flock
-#define open64 open
-#define openat64 openat
-#define creat64 creat
-#define lockf64 lockf
-#define posix_fadvise64 posix_fadvise
-#define posix_fallocate64 posix_fallocate
-#define off64_t off_t
-#endif
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/ftw.h b/include/ftw.h
index b15c062a..dfb7db93 100644
--- a/include/ftw.h
+++ b/include/ftw.h
@@ -29,11 +29,6 @@ struct FTW {
 int ftw(const char *, int (*)(const char *, const struct stat *, int), int);
 int nftw(const char *, int (*)(const char *, const struct stat *, int, struct FTW *), int, int);
 
-#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
-#define ftw64 ftw
-#define nftw64 nftw
-#endif
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/glob.h b/include/glob.h
index 4a562a20..718bef44 100644
--- a/include/glob.h
+++ b/include/glob.h
@@ -39,12 +39,6 @@ void globfree(glob_t *);
 #define GLOB_NOMATCH 3
 #define GLOB_NOSYS   4
 
-#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
-#define glob64 glob
-#define globfree64 globfree
-#define glob64_t glob_t
-#endif
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/stdio.h b/include/stdio.h
index d1ed01f0..67acad1e 100644
--- a/include/stdio.h
+++ b/include/stdio.h
@@ -205,18 +205,6 @@ typedef struct _IO_cookie_io_functions_t {
 FILE *fopencookie(void *, const char *, cookie_io_functions_t);
 #endif
 
-#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
-#define tmpfile64 tmpfile
-#define fopen64 fopen
-#define freopen64 freopen
-#define fseeko64 fseeko
-#define ftello64 ftello
-#define fgetpos64 fgetpos
-#define fsetpos64 fsetpos
-#define fpos64_t fpos_t
-#define off64_t off_t
-#endif
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/stdlib.h b/include/stdlib.h
index b507ca33..6f6b708c 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -163,15 +163,6 @@ double strtod_l(const char *__restrict, char **__restrict, struct __locale_struc
 long double strtold_l(const char *__restrict, char **__restrict, struct __locale_struct *);
 #endif
 
-#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
-#define mkstemp64 mkstemp
-#define mkostemp64 mkostemp
-#if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
-#define mkstemps64 mkstemps
-#define mkostemps64 mkostemps
-#endif
-#endif
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/sys/mman.h b/include/sys/mman.h
index 80a3baae..facab648 100644
--- a/include/sys/mman.h
+++ b/include/sys/mman.h
@@ -141,11 +141,6 @@ int mincore (void *, size_t, unsigned char *);
 int shm_open (const char *, int, mode_t);
 int shm_unlink (const char *);
 
-#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
-#define mmap64 mmap
-#define off64_t off_t
-#endif
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/sys/resource.h b/include/sys/resource.h
index 3068328d..d4c2f688 100644
--- a/include/sys/resource.h
+++ b/include/sys/resource.h
@@ -95,16 +95,6 @@ int prlimit(pid_t, int, const struct rlimit *, struct rlimit *);
 
 #define RLIM_NLIMITS RLIMIT_NLIMITS
 
-#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
-#define getrlimit64 getrlimit
-#define setrlimit64 setrlimit
-#define rlimit64 rlimit
-#define rlim64_t rlim_t
-#endif
-
 #if _REDIR_TIME64
 __REDIR(getrusage, __getrusage_time64);
 #endif
diff --git a/include/sys/sendfile.h b/include/sys/sendfile.h
index e7570d8e..7273aed1 100644
--- a/include/sys/sendfile.h
+++ b/include/sys/sendfile.h
@@ -10,11 +10,6 @@ extern "C" {
 
 ssize_t sendfile(int, int, off_t *, size_t);
 
-#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
-#define sendfile64 sendfile
-#define off64_t off_t
-#endif
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/sys/stat.h b/include/sys/stat.h
index 10d446c4..cdd2a455 100644
--- a/include/sys/stat.h
+++ b/include/sys/stat.h
@@ -98,18 +98,6 @@ int lchmod(const char *, mode_t);
 #define S_IEXEC S_IXUSR
 #endif
 
-#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
-#define stat64 stat
-#define fstat64 fstat
-#define lstat64 lstat
-#define fstatat64 fstatat
-#define blkcnt64_t blkcnt_t
-#define fsblkcnt64_t fsblkcnt_t
-#define fsfilcnt64_t fsfilcnt_t
-#define ino64_t ino_t
-#define off64_t off_t
-#endif
-
 #if _REDIR_TIME64
 __REDIR(stat, __stat_time64);
 __REDIR(fstat, __fstat_time64);
diff --git a/include/sys/statfs.h b/include/sys/statfs.h
index 6f4c6230..bcdb0d17 100644
--- a/include/sys/statfs.h
+++ b/include/sys/statfs.h
@@ -18,13 +18,6 @@ typedef struct __fsid_t {
 int statfs (const char *, struct statfs *);
 int fstatfs (int, struct statfs *);
 
-#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
-#define statfs64 statfs
-#define fstatfs64 fstatfs
-#define fsblkcnt64_t fsblkcnt_t
-#define fsfilcnt64_t fsfilcnt_t
-#endif
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/sys/statvfs.h b/include/sys/statvfs.h
index 793490b6..12f5f695 100644
--- a/include/sys/statvfs.h
+++ b/include/sys/statvfs.h
@@ -42,13 +42,6 @@ int fstatvfs (int, struct statvfs *);
 #define ST_NODIRATIME  2048
 #define ST_RELATIME    4096
 
-#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
-#define statvfs64 statvfs
-#define fstatvfs64 fstatvfs
-#define fsblkcnt64_t fsblkcnt_t
-#define fsfilcnt64_t fsfilcnt_t
-#endif
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/sys/types.h b/include/sys/types.h
index 0c35541d..71a27bb3 100644
--- a/include/sys/types.h
+++ b/include/sys/types.h
@@ -71,14 +71,6 @@ typedef unsigned long long u_quad_t;
 #include <sys/select.h>
 #endif
 
-#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
-#define blkcnt64_t blkcnt_t
-#define fsblkcnt64_t fsblkcnt_t
-#define fsfilcnt64_t fsfilcnt_t
-#define ino64_t ino_t
-#define off64_t off_t
-#endif
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/include/sys/uio.h b/include/sys/uio.h
index 00f73a2f..fb228c6b 100644
--- a/include/sys/uio.h
+++ b/include/sys/uio.h
@@ -29,11 +29,6 @@ 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) || defined(_GNU_SOURCE)
-#define preadv64 preadv
-#define pwritev64 pwritev
-#define off64_t off_t
-#endif
 #endif
 
 #ifdef _GNU_SOURCE
diff --git a/include/unistd.h b/include/unistd.h
index 0e8149e4..20f5eb35 100644
--- a/include/unistd.h
+++ b/include/unistd.h
@@ -198,16 +198,6 @@ ssize_t copy_file_range(int, off_t *, int, off_t *, size_t, unsigned);
 pid_t gettid(void);
 #endif
 
-#if defined(_LARGEFILE64_SOURCE) || defined(_GNU_SOURCE)
-#define lseek64 lseek
-#define pread64 pread
-#define pwrite64 pwrite
-#define truncate64 truncate
-#define ftruncate64 ftruncate
-#define lockf64 lockf
-#define off64_t off_t
-#endif
-
 #define POSIX_CLOSE_RESTART     0
 
 #define _XOPEN_VERSION          700
-- 
2.21.0


^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [musl] Revisiting LFS64 removal
  2022-09-27 19:08         ` Rich Felker
@ 2022-09-29 23:07           ` Rich Felker
  2022-09-30  2:44             ` Markus Wichmann
  0 siblings, 1 reply; 17+ messages in thread
From: Rich Felker @ 2022-09-29 23:07 UTC (permalink / raw)
  To: musl

On Tue, Sep 27, 2022 at 03:08:54PM -0400, Rich Felker wrote:
> On Tue, Sep 27, 2022 at 03:03:57PM -0400, Rich Felker wrote:
> > On Tue, Sep 27, 2022 at 08:20:05AM -0400, Rich Felker wrote:
> > > On Tue, Sep 27, 2022 at 11:09:48AM +0200, Gabriel Ravier wrote:
> > > > On 9/27/22 00:04, Rich Felker wrote:
> > > > >On Sun, Sep 25, 2022 at 09:03:40PM -0400, Rich Felker wrote:
> > > > >>[...]
> > > > >>Of course these interfaces should not be used, and we never intended
> > > > >>for them to be used just there for linking-compat. So, I've wanted to
> > > > >>get rid of them for a long time now.
> > > > >>
> > > > >>I believe the simplest short-term way is probably going to be just
> > > > >>having the dynamic linker symbol lookup error path make one final
> > > > >>check before bailing out with an error:
> > > > >>
> > > > >>- If the symbol to lookup ends in "64"..
> > > > >>- ..and it's in a hard-coded list of LFS64-compat symbols..
> > > > >>- ..and looking up the name with the "64" removed in libc succeeds..
> > > > >>
> > > > >>Then use the version without the "64" suffix and go on with relocation
> > > > >>processing.
> > > > >Proposed patch attached.
> > > > >
> > > > Looks at though the patch contains a buffer overflow to me, as the
> > > > length of `name` appears to be unbounded, but it's then copied into
> > > > `buf` which has its size limited to 16, all without checking for `l
> > > > >= sizeof buf` until after the copying is done (which might just
> > > > even get optimized out by GCC since it knows `l` can't be larger
> > > > than buf without UB occuring)
> > > 
> > > Thanks for the catch! It was a late change I made to avoid
> > > re-iterating but indeed it's wrong. (Note that strlen, etc. can't be
> > > used here because external function calls or even references are not
> > > valid in the context this can be called in; strcmp is a macro that
> > > expands to a static function call.)
> > 
> > Updated version.
> 
> And the follow-up patch which removes the macro interfaces. Note that
> there's not necessarily any reason these need to be done together.
> Removing the macros is not safe without removing the symbols, due to
> autoconf badness, but once the symbols are gone we're free to choose
> if/when to remove the macros.

As an alternative, maybe we should consider leaving these but only
under explict _LARGEFILE64_SOURCE rather than implicitly via
_GNU_SOURCE for at least one release cycle. This would allow makeshift
fixing of any builds that break by just adding -D_LARGEFILE64_SOURCE
until a proper fix can be applied.

Any preference here?

Rich

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [musl] Revisiting LFS64 removal
  2022-09-29 23:07           ` Rich Felker
@ 2022-09-30  2:44             ` Markus Wichmann
  2022-09-30 12:57               ` Rich Felker
  0 siblings, 1 reply; 17+ messages in thread
From: Markus Wichmann @ 2022-09-30  2:44 UTC (permalink / raw)
  To: musl

On Thu, Sep 29, 2022 at 07:07:08PM -0400, Rich Felker wrote:
> As an alternative, maybe we should consider leaving these but only
> under explict _LARGEFILE64_SOURCE rather than implicitly via
> _GNU_SOURCE for at least one release cycle. This would allow makeshift
> fixing of any builds that break by just adding -D_LARGEFILE64_SOURCE
> until a proper fix can be applied.
>
> Any preference here?
>
> Rich

Given that nothing lasts as long as a temporary measure, I'd say it is
better to rip the band-aid off in one go rather than two. Besides, any
breakage ought to be able to be dealt with by a simple replacement,
right?

Ciao,
Markus

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [musl] Revisiting LFS64 removal
  2022-09-30  2:44             ` Markus Wichmann
@ 2022-09-30 12:57               ` Rich Felker
  2022-09-30 17:35                 ` Colin Cross
  0 siblings, 1 reply; 17+ messages in thread
From: Rich Felker @ 2022-09-30 12:57 UTC (permalink / raw)
  To: Markus Wichmann; +Cc: musl

On Fri, Sep 30, 2022 at 04:44:47AM +0200, Markus Wichmann wrote:
> On Thu, Sep 29, 2022 at 07:07:08PM -0400, Rich Felker wrote:
> > As an alternative, maybe we should consider leaving these but only
> > under explict _LARGEFILE64_SOURCE rather than implicitly via
> > _GNU_SOURCE for at least one release cycle. This would allow makeshift
> > fixing of any builds that break by just adding -D_LARGEFILE64_SOURCE
> > until a proper fix can be applied.
> >
> > Any preference here?
> >
> > Rich
> 
> Given that nothing lasts as long as a temporary measure, I'd say it is

That's not a given for musl, quite the opposite. I would expect it to
last at most a release cycle, possibly even to disappear before then
if distros backport the changes to their development branches early
and find and fix everything.

> better to rip the band-aid off in one go rather than two. Besides, any
> breakage ought to be able to be dealt with by a simple replacement,
> right?

It's a simple fix, but the question is how many such simple fixes a
distro might need to make in their packages, and that I don't know.

If they have a trivial mechanical fix of "add something to CFLAGS"
they can do at first, that lets them build a list of affected packages
while quickly getting them all building again, then work out the right
fixes one at a time according to usual triage rather than being
swamped with these taking priority over issues with more depth.

Rich

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [musl] Revisiting LFS64 removal
  2022-09-30 12:57               ` Rich Felker
@ 2022-09-30 17:35                 ` Colin Cross
  2022-09-30 18:13                   ` enh
  2022-09-30 19:29                   ` Rich Felker
  0 siblings, 2 replies; 17+ messages in thread
From: Colin Cross @ 2022-09-30 17:35 UTC (permalink / raw)
  To: musl; +Cc: Markus Wichmann

On Fri, Sep 30, 2022 at 5:58 AM Rich Felker <dalias@libc.org> wrote:
>
> On Fri, Sep 30, 2022 at 04:44:47AM +0200, Markus Wichmann wrote:
> > On Thu, Sep 29, 2022 at 07:07:08PM -0400, Rich Felker wrote:
> > > As an alternative, maybe we should consider leaving these but only
> > > under explict _LARGEFILE64_SOURCE rather than implicitly via
> > > _GNU_SOURCE for at least one release cycle. This would allow makeshift
> > > fixing of any builds that break by just adding -D_LARGEFILE64_SOURCE
> > > until a proper fix can be applied.
> > >
> > > Any preference here?
> > >
> > > Rich
> >
> > Given that nothing lasts as long as a temporary measure, I'd say it is
>
> That's not a given for musl, quite the opposite. I would expect it to
> last at most a release cycle, possibly even to disappear before then
> if distros backport the changes to their development branches early
> and find and fix everything.
>
> > better to rip the band-aid off in one go rather than two. Besides, any
> > breakage ought to be able to be dealt with by a simple replacement,
> > right?
>
> It's a simple fix, but the question is how many such simple fixes a
> distro might need to make in their packages, and that I don't know.
>
> If they have a trivial mechanical fix of "add something to CFLAGS"
> they can do at first, that lets them build a list of affected packages
> while quickly getting them all building again, then work out the right
> fixes one at a time according to usual triage rather than being
> swamped with these taking priority over issues with more depth.
>
> Rich

I experimented with building all the host code in the Android tree
with these two patches just to measure the damage.  The first patch is
mostly fine, but causes link failures in rust modules.  I think that's
due to the upstream rust libc assuming the presence of fstat64, etc.:
https://cs.android.com/android/platform/superproject/+/master:external/rust/crates/libc/src/unix/linux_like/mod.rs;l=1665;drc=b38fde0ab980c7d79f0a55aec1b7121022a38257

The second patch causes 680 unique errors.  Many of those are in
Android-specific code that uses the *64 functions directly, which I
think is especially common due to early bionic's poor LFS64 support.
There are a few usages in third party code, but I think most of them
just need a tweak in the configs Android uses.

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [musl] Revisiting LFS64 removal
  2022-09-30 17:35                 ` Colin Cross
@ 2022-09-30 18:13                   ` enh
  2022-09-30 19:26                     ` Rich Felker
  2022-09-30 19:29                   ` Rich Felker
  1 sibling, 1 reply; 17+ messages in thread
From: enh @ 2022-09-30 18:13 UTC (permalink / raw)
  To: musl; +Cc: Markus Wichmann

[-- Attachment #1: Type: text/plain, Size: 2997 bytes --]

On Fri, Sep 30, 2022 at 10:36 AM Colin Cross <ccross@google.com> wrote:

> On Fri, Sep 30, 2022 at 5:58 AM Rich Felker <dalias@libc.org> wrote:
> >
> > On Fri, Sep 30, 2022 at 04:44:47AM +0200, Markus Wichmann wrote:
> > > On Thu, Sep 29, 2022 at 07:07:08PM -0400, Rich Felker wrote:
> > > > As an alternative, maybe we should consider leaving these but only
> > > > under explict _LARGEFILE64_SOURCE rather than implicitly via
> > > > _GNU_SOURCE for at least one release cycle. This would allow
> makeshift
> > > > fixing of any builds that break by just adding -D_LARGEFILE64_SOURCE
> > > > until a proper fix can be applied.
> > > >
> > > > Any preference here?
> > > >
> > > > Rich
> > >
> > > Given that nothing lasts as long as a temporary measure, I'd say it is
> >
> > That's not a given for musl, quite the opposite. I would expect it to
> > last at most a release cycle, possibly even to disappear before then
> > if distros backport the changes to their development branches early
> > and find and fix everything.
> >
> > > better to rip the band-aid off in one go rather than two. Besides, any
> > > breakage ought to be able to be dealt with by a simple replacement,
> > > right?
> >
> > It's a simple fix, but the question is how many such simple fixes a
> > distro might need to make in their packages, and that I don't know.
> >
> > If they have a trivial mechanical fix of "add something to CFLAGS"
> > they can do at first, that lets them build a list of affected packages
> > while quickly getting them all building again, then work out the right
> > fixes one at a time according to usual triage rather than being
> > swamped with these taking priority over issues with more depth.
> >
> > Rich
>
> I experimented with building all the host code in the Android tree
> with these two patches just to measure the damage.  The first patch is
> mostly fine, but causes link failures in rust modules.  I think that's
> due to the upstream rust libc assuming the presence of fstat64, etc.:
>
> https://cs.android.com/android/platform/superproject/+/master:external/rust/crates/libc/src/unix/linux_like/mod.rs;l=1665;drc=b38fde0ab980c7d79f0a55aec1b7121022a38257
>
> The second patch causes 680 unique errors.  Many of those are in
> Android-specific code that uses the *64 functions directly, which I
> think is especially common due to early bionic's poor LFS64 support.
>

...and the fact that we can't flip the switch globally for the OS build
without risking subtle ABI changes. but maybe these days we could recognize
such things (via the .lsdump stuff)? maybe it's time to try?

(we have similar issues with code that's also built for macOS, which never
had the *64 functions or off64_t, so there might be some low-hanging fruit
by extending those `#if __APPLE__` hacks -- that are basically just
`#define off64_t off_t` etc -- to apply to musl too...)


> There are a few usages in third party code, but I think most of them
> just need a tweak in the configs Android uses.
>

[-- Attachment #2: Type: text/html, Size: 4151 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [musl] Revisiting LFS64 removal
  2022-09-30 18:13                   ` enh
@ 2022-09-30 19:26                     ` Rich Felker
  2022-09-30 23:03                       ` enh
  0 siblings, 1 reply; 17+ messages in thread
From: Rich Felker @ 2022-09-30 19:26 UTC (permalink / raw)
  To: enh; +Cc: musl, Markus Wichmann

On Fri, Sep 30, 2022 at 11:13:28AM -0700, enh wrote:
> On Fri, Sep 30, 2022 at 10:36 AM Colin Cross <ccross@google.com> wrote:
> 
> > On Fri, Sep 30, 2022 at 5:58 AM Rich Felker <dalias@libc.org> wrote:
> > >
> > > On Fri, Sep 30, 2022 at 04:44:47AM +0200, Markus Wichmann wrote:
> > > > On Thu, Sep 29, 2022 at 07:07:08PM -0400, Rich Felker wrote:
> > > > > As an alternative, maybe we should consider leaving these but only
> > > > > under explict _LARGEFILE64_SOURCE rather than implicitly via
> > > > > _GNU_SOURCE for at least one release cycle. This would allow
> > makeshift
> > > > > fixing of any builds that break by just adding -D_LARGEFILE64_SOURCE
> > > > > until a proper fix can be applied.
> > > > >
> > > > > Any preference here?
> > > > >
> > > > > Rich
> > > >
> > > > Given that nothing lasts as long as a temporary measure, I'd say it is
> > >
> > > That's not a given for musl, quite the opposite. I would expect it to
> > > last at most a release cycle, possibly even to disappear before then
> > > if distros backport the changes to their development branches early
> > > and find and fix everything.
> > >
> > > > better to rip the band-aid off in one go rather than two. Besides, any
> > > > breakage ought to be able to be dealt with by a simple replacement,
> > > > right?
> > >
> > > It's a simple fix, but the question is how many such simple fixes a
> > > distro might need to make in their packages, and that I don't know.
> > >
> > > If they have a trivial mechanical fix of "add something to CFLAGS"
> > > they can do at first, that lets them build a list of affected packages
> > > while quickly getting them all building again, then work out the right
> > > fixes one at a time according to usual triage rather than being
> > > swamped with these taking priority over issues with more depth.
> > >
> > > Rich
> >
> > I experimented with building all the host code in the Android tree
> > with these two patches just to measure the damage.  The first patch is
> > mostly fine, but causes link failures in rust modules.  I think that's
> > due to the upstream rust libc assuming the presence of fstat64, etc.:
> >
> > https://cs.android.com/android/platform/superproject/+/master:external/rust/crates/libc/src/unix/linux_like/mod.rs;l=1665;drc=b38fde0ab980c7d79f0a55aec1b7121022a38257
> >
> > The second patch causes 680 unique errors.  Many of those are in
> > Android-specific code that uses the *64 functions directly, which I
> > think is especially common due to early bionic's poor LFS64 support.
> >
> 
> ....and the fact that we can't flip the switch globally for the OS build
> without risking subtle ABI changes. but maybe these days we could recognize
> such things (via the .lsdump stuff)? maybe it's time to try?
> 
> (we have similar issues with code that's also built for macOS, which never
> had the *64 functions or off64_t, so there might be some low-hanging fruit
> by extending those `#if __APPLE__` hacks -- that are basically just
> `#define off64_t off_t` etc -- to apply to musl too...)

The intended usage as I understand it is that you would probe for
sizeof(off_t)>=8 and only try to use these hacks if that's not
satisfied, not hard-code combinatoric platform knowledge. Something
like:

checking if sizeof(off_t)>=8...
[if no] checking if -D_FILE_OFFSET_BITS=64 makes sizeof(off_t)>=8...
[if no] checking if -D_LARGEFILE64_SOURCE exposes off64_t interfaces...
...

Rich

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [musl] Revisiting LFS64 removal
  2022-09-30 17:35                 ` Colin Cross
  2022-09-30 18:13                   ` enh
@ 2022-09-30 19:29                   ` Rich Felker
  2022-09-30 19:41                     ` Rich Felker
  1 sibling, 1 reply; 17+ messages in thread
From: Rich Felker @ 2022-09-30 19:29 UTC (permalink / raw)
  To: Colin Cross; +Cc: musl, Markus Wichmann

On Fri, Sep 30, 2022 at 10:35:32AM -0700, Colin Cross wrote:
> On Fri, Sep 30, 2022 at 5:58 AM Rich Felker <dalias@libc.org> wrote:
> >
> > On Fri, Sep 30, 2022 at 04:44:47AM +0200, Markus Wichmann wrote:
> > > On Thu, Sep 29, 2022 at 07:07:08PM -0400, Rich Felker wrote:
> > > > As an alternative, maybe we should consider leaving these but only
> > > > under explict _LARGEFILE64_SOURCE rather than implicitly via
> > > > _GNU_SOURCE for at least one release cycle. This would allow makeshift
> > > > fixing of any builds that break by just adding -D_LARGEFILE64_SOURCE
> > > > until a proper fix can be applied.
> > > >
> > > > Any preference here?
> > > >
> > > > Rich
> > >
> > > Given that nothing lasts as long as a temporary measure, I'd say it is
> >
> > That's not a given for musl, quite the opposite. I would expect it to
> > last at most a release cycle, possibly even to disappear before then
> > if distros backport the changes to their development branches early
> > and find and fix everything.
> >
> > > better to rip the band-aid off in one go rather than two. Besides, any
> > > breakage ought to be able to be dealt with by a simple replacement,
> > > right?
> >
> > It's a simple fix, but the question is how many such simple fixes a
> > distro might need to make in their packages, and that I don't know.
> >
> > If they have a trivial mechanical fix of "add something to CFLAGS"
> > they can do at first, that lets them build a list of affected packages
> > while quickly getting them all building again, then work out the right
> > fixes one at a time according to usual triage rather than being
> > swamped with these taking priority over issues with more depth.
> 
> I experimented with building all the host code in the Android tree
> with these two patches just to measure the damage.  The first patch is
> mostly fine, but causes link failures in rust modules.  I think that's
> due to the upstream rust libc assuming the presence of fstat64, etc.:
> https://cs.android.com/android/platform/superproject/+/master:external/rust/crates/libc/src/unix/linux_like/mod.rs;l=1665;drc=b38fde0ab980c7d79f0a55aec1b7121022a38257

Thanks for running these checks! Do you know where we go about
reporting this to the rust folks? I'd like to get the process started
on getting this fixed asap so hopefully the impact on users is low by
the time it gets to them.

Rich

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [musl] Revisiting LFS64 removal
  2022-09-30 19:29                   ` Rich Felker
@ 2022-09-30 19:41                     ` Rich Felker
  0 siblings, 0 replies; 17+ messages in thread
From: Rich Felker @ 2022-09-30 19:41 UTC (permalink / raw)
  To: Colin Cross; +Cc: musl, Markus Wichmann

On Fri, Sep 30, 2022 at 03:29:30PM -0400, Rich Felker wrote:
> On Fri, Sep 30, 2022 at 10:35:32AM -0700, Colin Cross wrote:
> > On Fri, Sep 30, 2022 at 5:58 AM Rich Felker <dalias@libc.org> wrote:
> > >
> > > On Fri, Sep 30, 2022 at 04:44:47AM +0200, Markus Wichmann wrote:
> > > > On Thu, Sep 29, 2022 at 07:07:08PM -0400, Rich Felker wrote:
> > > > > As an alternative, maybe we should consider leaving these but only
> > > > > under explict _LARGEFILE64_SOURCE rather than implicitly via
> > > > > _GNU_SOURCE for at least one release cycle. This would allow makeshift
> > > > > fixing of any builds that break by just adding -D_LARGEFILE64_SOURCE
> > > > > until a proper fix can be applied.
> > > > >
> > > > > Any preference here?
> > > > >
> > > > > Rich
> > > >
> > > > Given that nothing lasts as long as a temporary measure, I'd say it is
> > >
> > > That's not a given for musl, quite the opposite. I would expect it to
> > > last at most a release cycle, possibly even to disappear before then
> > > if distros backport the changes to their development branches early
> > > and find and fix everything.
> > >
> > > > better to rip the band-aid off in one go rather than two. Besides, any
> > > > breakage ought to be able to be dealt with by a simple replacement,
> > > > right?
> > >
> > > It's a simple fix, but the question is how many such simple fixes a
> > > distro might need to make in their packages, and that I don't know.
> > >
> > > If they have a trivial mechanical fix of "add something to CFLAGS"
> > > they can do at first, that lets them build a list of affected packages
> > > while quickly getting them all building again, then work out the right
> > > fixes one at a time according to usual triage rather than being
> > > swamped with these taking priority over issues with more depth.
> > 
> > I experimented with building all the host code in the Android tree
> > with these two patches just to measure the damage.  The first patch is
> > mostly fine, but causes link failures in rust modules.  I think that's
> > due to the upstream rust libc assuming the presence of fstat64, etc.:
> > https://cs.android.com/android/platform/superproject/+/master:external/rust/crates/libc/src/unix/linux_like/mod.rs;l=1665;drc=b38fde0ab980c7d79f0a55aec1b7121022a38257
> 
> Thanks for running these checks! Do you know where we go about
> reporting this to the rust folks? I'd like to get the process started
> on getting this fixed asap so hopefully the impact on users is low by
> the time it gets to them.

OK, discussion on IRC turned up the right place to file, and I've
filed it here:

https://github.com/rust-lang/libc/issues/2934

Rich

^ permalink raw reply	[flat|nested] 17+ messages in thread

* Re: [musl] Revisiting LFS64 removal
  2022-09-30 19:26                     ` Rich Felker
@ 2022-09-30 23:03                       ` enh
  0 siblings, 0 replies; 17+ messages in thread
From: enh @ 2022-09-30 23:03 UTC (permalink / raw)
  To: Rich Felker; +Cc: musl, Markus Wichmann

[-- Attachment #1: Type: text/plain, Size: 4878 bytes --]

On Fri, Sep 30, 2022 at 12:26 PM Rich Felker <dalias@libc.org> wrote:

> On Fri, Sep 30, 2022 at 11:13:28AM -0700, enh wrote:
> > On Fri, Sep 30, 2022 at 10:36 AM Colin Cross <ccross@google.com> wrote:
> >
> > > On Fri, Sep 30, 2022 at 5:58 AM Rich Felker <dalias@libc.org> wrote:
> > > >
> > > > On Fri, Sep 30, 2022 at 04:44:47AM +0200, Markus Wichmann wrote:
> > > > > On Thu, Sep 29, 2022 at 07:07:08PM -0400, Rich Felker wrote:
> > > > > > As an alternative, maybe we should consider leaving these but
> only
> > > > > > under explict _LARGEFILE64_SOURCE rather than implicitly via
> > > > > > _GNU_SOURCE for at least one release cycle. This would allow
> > > makeshift
> > > > > > fixing of any builds that break by just adding
> -D_LARGEFILE64_SOURCE
> > > > > > until a proper fix can be applied.
> > > > > >
> > > > > > Any preference here?
> > > > > >
> > > > > > Rich
> > > > >
> > > > > Given that nothing lasts as long as a temporary measure, I'd say
> it is
> > > >
> > > > That's not a given for musl, quite the opposite. I would expect it to
> > > > last at most a release cycle, possibly even to disappear before then
> > > > if distros backport the changes to their development branches early
> > > > and find and fix everything.
> > > >
> > > > > better to rip the band-aid off in one go rather than two. Besides,
> any
> > > > > breakage ought to be able to be dealt with by a simple replacement,
> > > > > right?
> > > >
> > > > It's a simple fix, but the question is how many such simple fixes a
> > > > distro might need to make in their packages, and that I don't know.
> > > >
> > > > If they have a trivial mechanical fix of "add something to CFLAGS"
> > > > they can do at first, that lets them build a list of affected
> packages
> > > > while quickly getting them all building again, then work out the
> right
> > > > fixes one at a time according to usual triage rather than being
> > > > swamped with these taking priority over issues with more depth.
> > > >
> > > > Rich
> > >
> > > I experimented with building all the host code in the Android tree
> > > with these two patches just to measure the damage.  The first patch is
> > > mostly fine, but causes link failures in rust modules.  I think that's
> > > due to the upstream rust libc assuming the presence of fstat64, etc.:
> > >
> > >
> https://cs.android.com/android/platform/superproject/+/master:external/rust/crates/libc/src/unix/linux_like/mod.rs;l=1665;drc=b38fde0ab980c7d79f0a55aec1b7121022a38257
> > >
> > > The second patch causes 680 unique errors.  Many of those are in
> > > Android-specific code that uses the *64 functions directly, which I
> > > think is especially common due to early bionic's poor LFS64 support.
> > >
> >
> > ....and the fact that we can't flip the switch globally for the OS build
> > without risking subtle ABI changes. but maybe these days we could
> recognize
> > such things (via the .lsdump stuff)? maybe it's time to try?
> >
> > (we have similar issues with code that's also built for macOS, which
> never
> > had the *64 functions or off64_t, so there might be some low-hanging
> fruit
> > by extending those `#if __APPLE__` hacks -- that are basically just
> > `#define off64_t off_t` etc -- to apply to musl too...)
>
> The intended usage as I understand it is that you would probe for
> sizeof(off_t)>=8 and only try to use these hacks if that's not
> satisfied, not hard-code combinatoric platform knowledge.


yeah, the problem was that we had (ten years ago) the following three
situations, and code that needed to build with all three:

1. bionic at the time had a 32-bit off_t and didn't have _FILE_OFFSET_BITS,
but did have off64_t and [some of] the *64 functions.
2. glibc had _FILE_OFFSET_BITS, but we weren't using it (or were using it
set to 32?).
3. apple's libc didn't have _FILE_OFFSET_BITS, didn't have off64_t or the
*64 functions, but everything was 64-bit anyway.

so what's happened is that we've got some source (stuff that needs to build
for device and host) where we have heavy use of the *64 functions, and then
#define hacks in the case where it also needs to build for the mac.

luckily, in the meantime we took over bionic and fixed that, though we
_didn't_ change the default for `_FILE_OFFSET_BITS` for the ABI reasons i
mentioned previously. what we _did_ do though was make the *host* build use
`-D_FILE_OFFSET_BITS=64`. so given that musl is only for the host,
replacing glibc, and it seems unlikely that much if any of this code
actually needs to compile for ancient versions of bionic, i think we can
just "remove the 64s".

ccross: happy to shard that work if you want to go that route!


> Something
> like:
>
> checking if sizeof(off_t)>=8...
> [if no] checking if -D_FILE_OFFSET_BITS=64 makes sizeof(off_t)>=8...
> [if no] checking if -D_LARGEFILE64_SOURCE exposes off64_t interfaces...
> ...
>
> Rich
>

[-- Attachment #2: Type: text/html, Size: 6595 bytes --]

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2022-09-30 23:04 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-26  1:03 [musl] Revisiting LFS64 removal Rich Felker
2022-09-26 16:03 ` Markus Wichmann
2022-09-26 16:47   ` Rich Felker
2022-09-26 22:04 ` Rich Felker
2022-09-27  9:09   ` Gabriel Ravier
2022-09-27 12:20     ` Rich Felker
2022-09-27 19:03       ` Rich Felker
2022-09-27 19:08         ` Rich Felker
2022-09-29 23:07           ` Rich Felker
2022-09-30  2:44             ` Markus Wichmann
2022-09-30 12:57               ` Rich Felker
2022-09-30 17:35                 ` Colin Cross
2022-09-30 18:13                   ` enh
2022-09-30 19:26                     ` Rich Felker
2022-09-30 23:03                       ` enh
2022-09-30 19:29                   ` Rich Felker
2022-09-30 19:41                     ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).