hc
2024-01-05 071106ecf68c401173c58808b1cf5f68cc50d390
kernel/tools/lib/bpf/bpf_helpers.h
....@@ -42,16 +42,21 @@
4242 /*
4343 * Helper macro to manipulate data structures
4444 */
45
-#ifndef offsetof
46
-#define offsetof(TYPE, MEMBER) ((unsigned long)&((TYPE *)0)->MEMBER)
47
-#endif
48
-#ifndef container_of
45
+
46
+/* offsetof() definition that uses __builtin_offset() might not preserve field
47
+ * offset CO-RE relocation properly, so force-redefine offsetof() using
48
+ * old-school approach which works with CO-RE correctly
49
+ */
50
+#undef offsetof
51
+#define offsetof(type, member) ((unsigned long)&((type *)0)->member)
52
+
53
+/* redefined container_of() to ensure we use the above offsetof() macro */
54
+#undef container_of
4955 #define container_of(ptr, type, member) \
5056 ({ \
5157 void *__mptr = (void *)(ptr); \
5258 ((type *)(__mptr - offsetof(type, member))); \
5359 })
54
-#endif
5560
5661 /*
5762 * Helper macro to throw a compilation error if __bpf_unreachable() gets