stddef.h: don't include sys/cdefs.h

Switch to sys/_visible.h for visibility macros.

Prefer __builtin_offsetof over __offset.  sys/cdefs.h always defines
__offsetof to __builtin_offsetof so just use the latter to remove a
dependency on sys/cdefs.h.  Realistically, we're never going to care
about a compiler that doesn't supply this builtin.

Add a somewhat questionable guard around the offsetof() definition
because the compiler no longer thinks it the same as a number of other
redundent definitions scattered around (e.g., in the openzfs codebase).
It is actually the same and those defintions likely shouldn't exist at
all, but it's easy to add a guard for now.

Reviewed by:	imp
Exp-run by:	antoine (PR 286274)
Pull Request:	https://github.com/freebsd/freebsd-src/pull/1595
This commit is contained in:
Brooks Davis 2025-06-11 17:39:02 +01:00
parent 5a2f6016de
commit 2e783ea70a

View file

@ -32,9 +32,9 @@
#ifndef _STDDEF_H_
#define _STDDEF_H_
#include <sys/cdefs.h>
#include <sys/_null.h>
#include <sys/_types.h>
#include <sys/_visible.h>
#ifndef _PTRDIFF_T_DECLARED
typedef __ptrdiff_t ptrdiff_t;
@ -61,7 +61,9 @@ typedef __max_align_t max_align_t;
#endif
#endif
#define offsetof(type, field) __offsetof(type, field)
#ifndef offsetof
#define offsetof(type, field) __builtin_offsetof(type, field)
#endif
#if __EXT1_VISIBLE
/* ISO/IEC 9899:2011 K.3.3.2 */