Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 19 Jul 2024 12:51:26 -0600
From:      Kim Shrier <kim@westryn.net>
To:        FreeBSD Hackers <freebsd-hackers@freebsd.org>
Subject:   MFC D45651 to stable/14
Message-ID:  <EBAD3E97-BE4C-43EE-B887-854DDD134AA3@westryn.net>

index | next in thread | raw e-mail

[-- Attachment #1 --]
I’m unsure of the proper channels for this request.

I would like https://reviews.freebsd.org/D45651 to be MFC’ed to stable/14
and if possible releng/14.1.  I have attached patch files to accomplish
these updates.


[-- Attachment #2 --]
diff --git a/include/stdlib.h b/include/stdlib.h
index 67a1cb82761d..ef0e196744cd 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -339,23 +339,26 @@ __uint64_t
  * parameter, and both are different from the ones expected by the historical
  * FreeBSD qsort_r() interface.
  *
- * Apply a workaround where we explicitly link against the historical
- * interface, qsort_r@FBSD_1.0, in case when qsort_r() is called with
- * the last parameter with a function pointer that exactly matches the
- * historical FreeBSD qsort_r() comparator signature, so applications
- * written for the historical interface can continue to work without
- * modification.
+ * Apply a workaround where we explicitly link against the historical interface,
+ * qsort_r@FBSD_1.0, in case when qsort_r() is called with the last parameter
+ * with a function pointer that exactly matches the historical FreeBSD qsort_r()
+ * comparator signature, so applications written for the historical interface
+ * can continue to work without modification. Toolchains that don't support
+ * symbol versioning don't define __sym_compat, so only provide this symbol in
+ * supported environments.
  */
+#ifdef __sym_compat
 #if defined(__generic) || defined(__cplusplus)
 void __qsort_r_compat(void *, size_t, size_t, void *,
 	    int (*)(void *, const void *, const void *));
 __sym_compat(qsort_r, __qsort_r_compat, FBSD_1.0);
 #endif
+#endif
 #if defined(__generic) && !defined(__cplusplus)
 #define	qsort_r(base, nel, width, arg4, arg5)				\
     __generic(arg5, int (*)(void *, const void *, const void *),	\
         __qsort_r_compat, qsort_r)(base, nel, width, arg4, arg5)
-#elif defined(__cplusplus)
+#elif defined(__cplusplus) && defined(__sym_compat)
 __END_DECLS
 extern "C++" {
 static inline void qsort_r(void *base, size_t nmemb, size_t size,
diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h
index 19b7d8fe427d..38be15666231 100644
--- a/sys/sys/cdefs.h
+++ b/sys/sys/cdefs.h
@@ -112,6 +112,8 @@
 #define	__CC_SUPPORTS___INLINE 1
 #define	__CC_SUPPORTS___INLINE__ 1
 
+#define	__CC_SUPPORTS_SYMVER 1
+
 #define	__CC_SUPPORTS___FUNC__ 1
 #define	__CC_SUPPORTS_WARNING 1
 
@@ -121,6 +123,14 @@
 
 #endif /* __GNUC__ */
 
+/*
+ * TinyC pretends to be gcc 9.3. This is generally good enough to support
+ * everything FreeBSD... except for the .symver assembler directive.
+ */
+#ifdef __TINYC__
+#undef __CC_SUPPORTS_SYMVER
+#endif
+
 /*
  * Macro to test if we're using a specific version of gcc or later.
  */
@@ -540,10 +550,12 @@
 	__asm__(".section .gnu.warning." #sym);	\
 	__asm__(".asciz \"" msg "\"");	\
 	__asm__(".previous")
+#ifdef __CC_SUPPORTS_SYMVER
 #define	__sym_compat(sym,impl,verid)	\
 	__asm__(".symver " #impl ", " #sym "@" #verid)
 #define	__sym_default(sym,impl,verid)	\
 	__asm__(".symver " #impl ", " #sym "@@@" #verid)
+#endif	/* __CC_SUPPORTS_SYMVER */
 #else
 #define	__weak_reference(sym,alias)	\
 	__asm__(".weak alias");		\
@@ -552,10 +564,12 @@
 	__asm__(".section .gnu.warning.sym"); \
 	__asm__(".asciz \"msg\"");	\
 	__asm__(".previous")
+#ifdef __CC_SUPPORTS_SYMVER
 #define	__sym_compat(sym,impl,verid)	\
 	__asm__(".symver impl, sym@verid")
 #define	__sym_default(impl,sym,verid)	\
 	__asm__(".symver impl, sym@@@verid")
+#endif	/* __CC_SUPPORTS_SYMVER */
 #endif	/* __STDC__ */
 #endif	/* __GNUC__ */
 

[-- Attachment #3 --]



[-- Attachment #4 --]
diff --git a/include/stdlib.h b/include/stdlib.h
index 67a1cb82761d..ef0e196744cd 100644
--- a/include/stdlib.h
+++ b/include/stdlib.h
@@ -339,23 +339,26 @@ __uint64_t
  * parameter, and both are different from the ones expected by the historical
  * FreeBSD qsort_r() interface.
  *
- * Apply a workaround where we explicitly link against the historical
- * interface, qsort_r@FBSD_1.0, in case when qsort_r() is called with
- * the last parameter with a function pointer that exactly matches the
- * historical FreeBSD qsort_r() comparator signature, so applications
- * written for the historical interface can continue to work without
- * modification.
+ * Apply a workaround where we explicitly link against the historical interface,
+ * qsort_r@FBSD_1.0, in case when qsort_r() is called with the last parameter
+ * with a function pointer that exactly matches the historical FreeBSD qsort_r()
+ * comparator signature, so applications written for the historical interface
+ * can continue to work without modification. Toolchains that don't support
+ * symbol versioning don't define __sym_compat, so only provide this symbol in
+ * supported environments.
  */
+#ifdef __sym_compat
 #if defined(__generic) || defined(__cplusplus)
 void __qsort_r_compat(void *, size_t, size_t, void *,
 	    int (*)(void *, const void *, const void *));
 __sym_compat(qsort_r, __qsort_r_compat, FBSD_1.0);
 #endif
+#endif
 #if defined(__generic) && !defined(__cplusplus)
 #define	qsort_r(base, nel, width, arg4, arg5)				\
     __generic(arg5, int (*)(void *, const void *, const void *),	\
         __qsort_r_compat, qsort_r)(base, nel, width, arg4, arg5)
-#elif defined(__cplusplus)
+#elif defined(__cplusplus) && defined(__sym_compat)
 __END_DECLS
 extern "C++" {
 static inline void qsort_r(void *base, size_t nmemb, size_t size,
diff --git a/sys/sys/cdefs.h b/sys/sys/cdefs.h
index 4893ae1662b8..2872f1d5d554 100644
--- a/sys/sys/cdefs.h
+++ b/sys/sys/cdefs.h
@@ -112,6 +112,8 @@
 #define	__CC_SUPPORTS___INLINE 1
 #define	__CC_SUPPORTS___INLINE__ 1
 
+#define	__CC_SUPPORTS_SYMVER 1
+
 #define	__CC_SUPPORTS___FUNC__ 1
 #define	__CC_SUPPORTS_WARNING 1
 
@@ -121,6 +123,14 @@
 
 #endif /* __GNUC__ */
 
+/*
+ * TinyC pretends to be gcc 9.3. This is generally good enough to support
+ * everything FreeBSD... except for the .symver assembler directive.
+ */
+#ifdef __TINYC__
+#undef __CC_SUPPORTS_SYMVER
+#endif
+
 /*
  * Macro to test if we're using a specific version of gcc or later.
  */
@@ -539,10 +549,12 @@
 	__asm__(".section .gnu.warning." #sym);	\
 	__asm__(".asciz \"" msg "\"");	\
 	__asm__(".previous")
+#ifdef __CC_SUPPORTS_SYMVER
 #define	__sym_compat(sym,impl,verid)	\
 	__asm__(".symver " #impl ", " #sym "@" #verid)
 #define	__sym_default(sym,impl,verid)	\
 	__asm__(".symver " #impl ", " #sym "@@@" #verid)
+#endif	/* __CC_SUPPORTS_SYMVER */
 #else
 #define	__weak_reference(sym,alias)	\
 	__asm__(".weak alias");		\
@@ -551,10 +563,12 @@
 	__asm__(".section .gnu.warning.sym"); \
 	__asm__(".asciz \"msg\"");	\
 	__asm__(".previous")
+#ifdef __CC_SUPPORTS_SYMVER
 #define	__sym_compat(sym,impl,verid)	\
 	__asm__(".symver impl, sym@verid")
 #define	__sym_default(impl,sym,verid)	\
 	__asm__(".symver impl, sym@@@verid")
+#endif	/* __CC_SUPPORTS_SYMVER */
 #endif	/* __STDC__ */
 #endif	/* __GNUC__ */
 

[-- Attachment #5 --]


Kim
_
C++ is an off-by-one error




help

Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?EBAD3E97-BE4C-43EE-B887-854DDD134AA3>