From 2e783ea70a7a1aa0bec116451d70abd8cf05ce42 Mon Sep 17 00:00:00 2001 From: Brooks Davis Date: Wed, 11 Jun 2025 17:39:02 +0100 Subject: [PATCH] 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 --- include/stddef.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/include/stddef.h b/include/stddef.h index 2255ea47a49..3ba9a9946b0 100644 --- a/include/stddef.h +++ b/include/stddef.h @@ -32,9 +32,9 @@ #ifndef _STDDEF_H_ #define _STDDEF_H_ -#include #include #include +#include #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 */