1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-11-21 07:15:49 +00:00

stdlib: Support compiling with tinyc by omitting compat qsort code

TinyC doesn't support the .symver assembler directive. Add a generic way
to signal this and use that not to define __sym_() macros that use
it. Only use the __sym_* macros in headers when they are defined (which
currently is only for the qsort_r compat code. Not supporting this for
tcc is fine: It's an edge case for legacy binaries / code anyway which
isn't relevant to tinyc.

Sponsored by:		Netflix
Reviewed by:		kib
Differential Revision:	https://reviews.freebsd.org/D45651
This commit is contained in:
Warner Losh 2024-06-21 09:48:41 -06:00
parent 3fdf11fe8f
commit 4a86b26b84
2 changed files with 23 additions and 7 deletions

View File

@ -330,23 +330,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,

View File

@ -90,9 +90,18 @@
#define __compiler_membar() __asm __volatile(" " : : : "memory")
#define __CC_SUPPORTS___INLINE 1
#define __CC_SUPPORTS_SYMVER 1
#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
/*
* The __CONCAT macro is used to concatenate parts of symbol names, e.g.
* with "#define OLD(foo) __CONCAT(old,foo)", OLD(foo) produces oldfoo.
@ -369,10 +378,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
#else
#define __weak_reference(sym,alias) \
__asm__(".weak alias"); \
@ -381,10 +392,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
#endif /* __STDC__ */
#define __GLOBL(sym) __asm__(".globl " __XSTRING(sym))