zfs: rename several printf attribute declarations to __printf__

For kernel builds, we redefine `__printf__` to `__freebsd_kprintf__`, to
support FreeBSD kernel printf(9) extensions with clang.

In OpenZFS various printf related functions are declared with
__attribute__((format(printf, X, Y))), so these won't work with the
above redefinition. With clang 21 and higher, this leads to errors
similar to:

    sys/contrib/openzfs/module/zfs/spa_misc.c:414:38: error: passing 'printf' format string where 'freebsd_kprintf' format string is expected [-Werror,-Wformat]
      414 |         (void) vsnprintf(buf, sizeof (buf), fmt, adx);
          |                                             ^

Since attribute names can always be spelled with leading and trailing
double underscores, rename these instances.

Note that in FreeBSD proper we usually use `__printflike` from
<sys/cdefs.h>, but that does not apply to OpenZFS.

Reviewed by:	emaste
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D54388
This commit is contained in:
Dimitry Andric 2025-12-30 13:50:24 +01:00
parent 667259b392
commit bcd9ea853b
5 changed files with 14 additions and 14 deletions

View file

@ -52,28 +52,28 @@ extern "C" {
#ifndef _ASM
extern void cmn_err(int, const char *, ...)
__attribute__((format(printf, 2, 3)));
__attribute__((format(__printf__, 2, 3)));
extern void vzcmn_err(zoneid_t, int, const char *, __va_list)
__attribute__((format(printf, 3, 0)));
__attribute__((format(__printf__, 3, 0)));
extern void vcmn_err(int, const char *, __va_list)
__attribute__((format(printf, 2, 0)));
__attribute__((format(__printf__, 2, 0)));
extern void zcmn_err(zoneid_t, int, const char *, ...)
__attribute__((format(printf, 3, 4)));
__attribute__((format(__printf__, 3, 4)));
extern void vzprintf(zoneid_t, const char *, __va_list)
__attribute__((format(printf, 2, 0)));
__attribute__((format(__printf__, 2, 0)));
extern void zprintf(zoneid_t, const char *, ...)
__attribute__((format(printf, 2, 3)));
__attribute__((format(__printf__, 2, 3)));
extern void vuprintf(const char *, __va_list)
__attribute__((format(printf, 1, 0)));
__attribute__((format(__printf__, 1, 0)));
extern void panic(const char *, ...)
__attribute__((format(printf, 1, 2), __noreturn__));
__attribute__((format(__printf__, 1, 2), __noreturn__));
#define cmn_err_once(ce, ...) \
do { \

View file

@ -55,9 +55,9 @@ MALLOC_DECLARE(M_SOLARIS);
typedef struct vmem vmem_t;
extern char *kmem_asprintf(const char *, ...)
__attribute__((format(printf, 1, 2)));
__attribute__((format(__printf__, 1, 2)));
extern char *kmem_vasprintf(const char *fmt, va_list ap)
__attribute__((format(printf, 1, 0)));
__attribute__((format(__printf__, 1, 0)));
extern int kmem_scnprintf(char *restrict str, size_t size,
const char *restrict fmt, ...);

View file

@ -1127,9 +1127,9 @@ extern void spa_set_allocator(spa_t *spa, const char *allocator);
/* Miscellaneous support routines */
extern void spa_load_failed(spa_t *spa, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
__attribute__((format(__printf__, 2, 3)));
extern void spa_load_note(spa_t *spa, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
__attribute__((format(__printf__, 2, 3)));
extern void spa_activate_mos_feature(spa_t *spa, const char *feature,
dmu_tx_t *tx);
extern void spa_deactivate_mos_feature(spa_t *spa, const char *feature);

View file

@ -54,7 +54,7 @@ extern int zfs_nocacheflush;
typedef boolean_t vdev_open_children_func_t(vdev_t *vd);
extern void vdev_dbgmsg(vdev_t *vd, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
__attribute__((format(__printf__, 2, 3)));
extern void vdev_dbgmsg_print_tree(vdev_t *, int);
extern int vdev_open(vdev_t *);
extern void vdev_open_children(vdev_t *);

View file

@ -68,7 +68,7 @@ extern int zfs_dbgmsg_enable;
extern void __set_error(const char *file, const char *func, int line, int err);
extern void __zfs_dbgmsg(char *buf);
extern void __dprintf(boolean_t dprint, const char *file, const char *func,
int line, const char *fmt, ...) __attribute__((format(printf, 5, 6)));
int line, const char *fmt, ...) __attribute__((format(__printf__, 5, 6)));
/*
* Some general principles for using zfs_dbgmsg():