Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 26 Sep 2025 08:47:23 GMT
From:      Konstantin Belousov <kib@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: e194103bd35d - main - libc: properly forward the compat syscall references to libsys
Message-ID:  <202509260847.58Q8lN8e053475@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=e194103bd35d9e08a5d271d814d6184ec159eadf

commit e194103bd35d9e08a5d271d814d6184ec159eadf
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2025-09-22 23:27:05 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2025-09-26 06:51:28 +0000

    libc: properly forward the compat syscall references to libsys
    
    same as it was done for setgroups@FBSD_1.0.
    Switch from weakref to symver, since GNU as cannot handle version spec
    with weakref.
    
    Reviewed by:    olce
    Sponsored by:   The FreeBSD Foundation
    MFC after:      1 week
    Differential revision:  https://reviews.freebsd.org/D52687
---
 lib/libc/gen/gen-compat.h | 48 ++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 37 insertions(+), 11 deletions(-)

diff --git a/lib/libc/gen/gen-compat.h b/lib/libc/gen/gen-compat.h
index 74678301af6f..19b9addb4321 100644
--- a/lib/libc/gen/gen-compat.h
+++ b/lib/libc/gen/gen-compat.h
@@ -40,24 +40,50 @@ struct freebsd11_statfs;
 struct freebsd11_dirent *freebsd11_readdir(DIR *);
 int	freebsd11_readdir_r(DIR *, struct freebsd11_dirent *,
 	    struct freebsd11_dirent **);
-int	freebsd11_stat(const char *, struct freebsd11_stat *);
-int	freebsd11_lstat(const char *, struct freebsd11_stat *);
-int	freebsd11_fstat(int, struct freebsd11_stat *);
-int	freebsd11_fstatat(int, const char *, struct freebsd11_stat *, int);
 
-int	freebsd11_statfs(const char *, struct freebsd11_statfs *);
-int	freebsd11_getfsstat(struct freebsd11_statfs *, long, int);
 int	freebsd11_getmntinfo(struct freebsd11_statfs **, int);
 
 char	*freebsd11_devname(__uint32_t dev, __mode_t type);
-char	*freebsd11_devname_r(__uint32_t dev, __mode_t type, char *buf, int len);
+char	*freebsd11_devname_r(__uint32_t dev, __mode_t type, char *buf,
+	    int len);
 
-#define	F14SG	int freebsd14_setgroups(int gidsize, const __gid_t *gidset)
+/*
+ * We want freebsd11_fstat in C source to result in resolution to
+ * - fstat@FBSD_1.0 for libc.so (but we do not need the _definition_
+ *   of this fstat, it is provided by libsys.so which we want to use).
+ * - freebsd11_fstat for libc.a (since if we make it fstat@FBSD_1.0
+ *   for libc.a, then final linkage into static object ignores version
+ *   and would reference fstat, which is the current syscall, not the
+ *   compat syscall). libc.a provides the freebsd11_fstat implementation.
+ *   Note that freebsd11_fstat from libc.a is not used for anything, but
+ *   we make it correct nonetheless, just in case it would.
+ * This is arranged by COMPAT_SYSCALL, and libc can just use freebsd11_fstat.
+ */
 #ifdef PIC
-static F14SG __attribute__((__weakref__("setgroups@FBSD_1.0")));
+#define	COMPAT_SYSCALL(rtype, fun, args, sym, ver)			\
+    rtype fun args; __sym_compat(sym, fun, ver);
 #else
-F14SG;
+#define	COMPAT_SYSCALL(rtype, fun, args, sym, ver)			\
+    rtype fun args;
 #endif
-#undef F14SG
+
+COMPAT_SYSCALL(int, freebsd11_stat, (const char *, struct freebsd11_stat *),
+    stat, FBSD_1.0);
+COMPAT_SYSCALL(int, freebsd11_lstat, (const char *, struct freebsd11_stat *),
+    lstat, FBSD_1.0);
+COMPAT_SYSCALL(int, freebsd11_fstat, (int, struct freebsd11_stat *),
+    fstat, FBSD_1.0);
+COMPAT_SYSCALL(int, freebsd11_fstatat, (int, const char *,
+    struct freebsd11_stat *, int), fstatat, FBSD_1.1);
+
+COMPAT_SYSCALL(int, freebsd11_statfs, (const char *,
+    struct freebsd11_statfs *), statfs, FBSD_1.0);
+COMPAT_SYSCALL(int, freebsd11_getfsstat, (struct freebsd11_statfs *, long,
+    int), getfsstat, FBSD_1.0);
+
+COMPAT_SYSCALL(int, freebsd14_setgroups, (int gidsize, const __gid_t *gidset),
+    setgroups, FBSD_1.0);
+
+#undef COMPAT_SYSCALL
 
 #endif /* _GEN_COMPAT_H_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202509260847.58Q8lN8e053475>