summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorThomas Weißschuh <linux@weissschuh.net>2026-04-01 18:07:27 +0300
committerThomas Weißschuh <linux@weissschuh.net>2026-04-04 11:48:14 +0300
commitfd2e9f820005d63769a6662c276b1f52a72ed041 (patch)
treeef797258355c1b2ae85820e88c544203eba7b68e /tools
parent867fb336a65ac59260674382168d2d93896ffa8d (diff)
downloadlinux-fd2e9f820005d63769a6662c276b1f52a72ed041.tar.xz
tools/nolibc: use __builtin_offsetof()
The current custom implementation of offsetof() fails UBSAN: runtime error: member access within null pointer of type 'struct ...' This means that all its users, including container_of(), free() and realloc(), fail. Use __builtin_offsetof() instead which does not have this issue and has been available since GCC 4 and clang 3. Signed-off-by: Thomas Weißschuh <linux@weissschuh.net> Acked-by: Willy Tarreau <w@1wt.eu> Link: https://patch.msgid.link/20260401-nolibc-asprintf-v1-1-46292313439f@weissschuh.net
Diffstat (limited to 'tools')
-rw-r--r--tools/include/nolibc/stddef.h2
1 files changed, 1 insertions, 1 deletions
diff --git a/tools/include/nolibc/stddef.h b/tools/include/nolibc/stddef.h
index ecbd13eab1f5..a3976341afdd 100644
--- a/tools/include/nolibc/stddef.h
+++ b/tools/include/nolibc/stddef.h
@@ -18,7 +18,7 @@
#endif
#ifndef offsetof
-#define offsetof(TYPE, FIELD) ((size_t) &((TYPE *)0)->FIELD)
+#define offsetof(TYPE, FIELD) __builtin_offsetof(TYPE, FIELD)
#endif
#endif /* _NOLIBC_STDDEF_H */