Skip to contentSkip to conversation

Switch get/put unaligned to use memcpy

PATCH Superseded Ian Rogers 4 participants 9 messages Jun 17, 2025 – Jun 25, 2025 Generic VDSO library

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Ian Rogers

author
#0 lore raw

v2 cover Switch get/put unaligned to use memcpy

The existing type punning approach with packed structs requires
-fno-strict-aliasing to be passed to the compiler for
correctness. This is true in the kernel tree but not in the tools directory resulting in this suggested patch from Eric Biggers
<[email protected]>:
https://lore.kernel.org/lkml/[email protected]/

Requiring -fno-strict-aliasing seems unfortunate and so this patch makes the unaligned code work via memcpy for type punning rather than the packed attribute.

v2: switch memcpy to __builtin_memcpy to avoid potential/disallowed
memcpy calls in vdso caused by -fno-builtin. Reported by Christophe Leroy <[email protected]>:
https://lore.kernel.org/lkml/[email protected]/

Ian Rogers (3):
vdso: Switch get/put unaligned from packed struct to memcpy tools headers: Update the linux/unaligned.h copy with the kernel
sources
tools headers: Remove unneeded ignoring of warnings in unaligned.h

 include/vdso/unaligned.h        | 48 ++++++++++++++++++++++++++++-----
 tools/include/linux/unaligned.h |  4 ---
 tools/include/vdso/unaligned.h  | 48 ++++++++++++++++++++++++++++-----
 3 files changed, 84 insertions(+), 16 deletions(-)
Signature · 1 line
2.50.0.rc2.701.gf1e915cc24-goog
author
#1 lore raw

PATCH v2 1/3 vdso: Switch get/put unaligned from packed struct to memcpy

Type punning is necessary for get/put unaligned but the use of a packed struct violates strict aliasing rules, requiring -fno-strict-aliasing to be passed to the C compiler. Switch to using memcpy so that -fno-strict-aliasing isn't necessary.

---
 include/vdso/unaligned.h | 48 +++++++++++++++++++++++++++++++++++-----
 1 file changed, 42 insertions(+), 6 deletions(-)
include/vdso/unaligned.h +42 -6
index ff0c06b6513e..f33c1eefbf68 100644
@@ -2,14 +2,50 @@
 #ifndef __VDSO_UNALIGNED_H
 #define __VDSO_UNALIGNED_H
 
-#define __get_unaligned_t(type, ptr) ({							\
-	const struct { type x; } __packed * __get_pptr = (typeof(__get_pptr))(ptr);	\
-	__get_pptr->x;									\
+#define ____get_unaligned_type(type) type: (type)0
+/**
+ * __get_unaligned_t - read an unaligned value from memory.
+ * @ptr:	the pointer to load from.
+ * @type:	the type to load from the pointer.
+ *
+ * Use memcpy to affect an unaligned type sized load avoiding undefined behavior
+ * from approaches like type punning that require -fno-strict-aliasing in order
+ * to be correct. As type may be const, use _Generic to map to a non-const type
+ * - you can't memcpy into a const type. The void* cast silences ubsan warnings.
+ */
+#define __get_unaligned_t(type, ptr) ({					\
+	type __get_unaligned_map_ctrl = 0;				\
+	typeof(_Generic(__get_unaligned_map_ctrl,			\
+		____get_unaligned_type(short int),			\
+		____get_unaligned_type(unsigned short int),		\
+		____get_unaligned_type(int),				\
+		____get_unaligned_type(unsigned int),			\
+		____get_unaligned_type(long),				\
+		____get_unaligned_type(unsigned long),			\
+		____get_unaligned_type(long long),			\
+		____get_unaligned_type(unsigned long long),		\
+		default: (type)0					\
+		)) __get_unaligned_val;					\
+	(void)__get_unaligned_map_ctrl;					\
+	__builtin_memcpy(&__get_unaligned_val, (void *)(ptr),		\
+			 sizeof(__get_unaligned_val));			\
+	__get_unaligned_val;						\
 })
 
-#define __put_unaligned_t(type, val, ptr) do {						\
-	struct { type x; } __packed * __put_pptr = (typeof(__put_pptr))(ptr);		\
-	__put_pptr->x = (val);								\
+/**
+ * __put_unaligned_t - write an unaligned value to memory.
+ * @type:	the type of the value to store.
+ * @val:	the value to store.
+ * @ptr:	the pointer to store to.
+ *
+ * Use memcpy to affect an unaligned type sized store avoiding undefined
+ * behavior from approaches like type punning that require -fno-strict-aliasing
+ * in order to be correct. The void* cast silences ubsan warnings.
+ */
+#define __put_unaligned_t(type, val, ptr) do {				\
+	type __put_unaligned_val = (val);				\
+	__builtin_memcpy((void *)(ptr), &__put_unaligned_val,		\
+			 sizeof(__put_unaligned_val));			\
 } while (0)
 
 #endif /* __VDSO_UNALIGNED_H */
Signature · 1 line
2.50.0.rc2.701.gf1e915cc24-goog
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy

Le 17/06/2025 à 22:53, Ian Rogers a écrit :

Quoted 6 lines

Type punning is necessary for get/put unaligned but the use of a packed struct violates strict aliasing rules, requiring -fno-strict-aliasing to be passed to the C compiler. Switch to using memcpy so that -fno-strict-aliasing isn't necessary.

Quoted 65 lines
---
  include/vdso/unaligned.h | 48 +++++++++++++++++++++++++++++++++++-----
  1 file changed, 42 insertions(+), 6 deletions(-)
include/vdso/unaligned.h +42 -6
index ff0c06b6513e..f33c1eefbf68 100644
@@ -2,14 +2,50 @@
  #ifndef __VDSO_UNALIGNED_H
  #define __VDSO_UNALIGNED_H
 
-#define __get_unaligned_t(type, ptr) ({							\
-	const struct { type x; } __packed * __get_pptr = (typeof(__get_pptr))(ptr);	\
-	__get_pptr->x;									\
+#define ____get_unaligned_type(type) type: (type)0
+/**
+ * __get_unaligned_t - read an unaligned value from memory.
+ * @ptr:	the pointer to load from.
+ * @type:	the type to load from the pointer.
+ *
+ * Use memcpy to affect an unaligned type sized load avoiding undefined behavior
+ * from approaches like type punning that require -fno-strict-aliasing in order
+ * to be correct. As type may be const, use _Generic to map to a non-const type
+ * - you can't memcpy into a const type. The void* cast silences ubsan warnings.
+ */
+#define __get_unaligned_t(type, ptr) ({					\
+	type __get_unaligned_map_ctrl = 0;				\
+	typeof(_Generic(__get_unaligned_map_ctrl,			\
+		____get_unaligned_type(short int),			\
+		____get_unaligned_type(unsigned short int),		\
+		____get_unaligned_type(int),				\
+		____get_unaligned_type(unsigned int),			\
+		____get_unaligned_type(long),				\
+		____get_unaligned_type(unsigned long),			\
+		____get_unaligned_type(long long),			\
+		____get_unaligned_type(unsigned long long),		\
+		default: (type)0					\
+		)) __get_unaligned_val;					\
+	(void)__get_unaligned_map_ctrl;					\
+	__builtin_memcpy(&__get_unaligned_val, (void *)(ptr),		\
+			 sizeof(__get_unaligned_val));			\
+	__get_unaligned_val;						\
  })
 
-#define __put_unaligned_t(type, val, ptr) do {						\
-	struct { type x; } __packed * __put_pptr = (typeof(__put_pptr))(ptr);		\
-	__put_pptr->x = (val);								\
+/**
+ * __put_unaligned_t - write an unaligned value to memory.
+ * @type:	the type of the value to store.
+ * @val:	the value to store.
+ * @ptr:	the pointer to store to.
+ *
+ * Use memcpy to affect an unaligned type sized store avoiding undefined
+ * behavior from approaches like type punning that require -fno-strict-aliasing
+ * in order to be correct. The void* cast silences ubsan warnings.
+ */
+#define __put_unaligned_t(type, val, ptr) do {				\
+	type __put_unaligned_val = (val);				\
+	__builtin_memcpy((void *)(ptr), &__put_unaligned_val,		\
+			 sizeof(__put_unaligned_val));			\
  } while (0)
 
  #endif /* __VDSO_UNALIGNED_H */
#3 lore raw

Re: [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy

In reply to Ian Rogers
kernel test robot noticed the following build warnings:

Hi Ian,

kernel test robot noticed the following build warnings:

[auto build test WARNING on linus/master]
[also build test WARNING on v6.16-rc2 next-20250618]
[cannot apply to tip/timers/vdso acme/perf/core]
[If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Ian-Rogers/vdso-Switch-get-put-unaligned-from-packed-struct-to-memcpy/20250618-045610
base:   linus/master
patch link:    https://lore.kernel.org/r/20250617205320.1580946-2-irogers%40google.com
patch subject: [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy
config: parisc-allnoconfig (https://download.01.org/0day-ci/archive/20250618/[email protected]/config)
compiler: hppa-linux-gcc (GCC) 15.1.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20250618/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All warnings (new ones prefixed by >>):

In file included from include/linux/swab.h:5,
from include/uapi/linux/byteorder/big_endian.h:14, from include/linux/byteorder/big_endian.h:5,
from arch/parisc/include/uapi/asm/byteorder.h:5, from arch/parisc/include/asm/bitops.h:11,
from include/linux/bitops.h:67,
from include/linux/kernel.h:23,
from arch/parisc/include/asm/bug.h:5,
from include/linux/bug.h:5,
from include/linux/thread_info.h:13,
from include/linux/sched.h:14,
from include/linux/uaccess.h:9,
from arch/parisc/boot/compressed/misc.c:7:
In function 'get_unaligned_le32',
inlined from 'decompress_kernel' at arch/parisc/boot/compressed/misc.c:312:16:

>> include/vdso/unaligned.h:30:9: warning: '__builtin_memcpy' reading 4 bytes from a region of size 1 [-Wstringop-overread]
      30 |         __builtin_memcpy(&__get_unaligned_val, (void *)(ptr),           \
         |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      31 |                          sizeof(__get_unaligned_val));                  \
         |                          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
   include/uapi/linux/swab.h:120:19: note: in definition of macro '__swab32'
     120 |         __fswab32(x))
         |                   ^
   include/linux/byteorder/generic.h:89:21: note: in expansion of macro '__le32_to_cpu'
      89 | #define le32_to_cpu __le32_to_cpu
         |                     ^~~~~~~~~~~~~
   include/linux/unaligned.h:23:28: note: in expansion of macro '__get_unaligned_t'
      23 |         return le32_to_cpu(__get_unaligned_t(__le32, p));
         |                            ^~~~~~~~~~~~~~~~~
   arch/parisc/boot/compressed/misc.c: In function 'decompress_kernel':
   arch/parisc/boot/compressed/misc.c:29:13: note: source object 'output_len' of size 1
      29 | extern char output_len;
         |             ^~~~~~~~~~

vim +/__builtin_memcpy +30 include/vdso/unaligned.h

     4	
     5	#define ____get_unaligned_type(type) type: (type)0
     6	/**
     7	 * __get_unaligned_t - read an unaligned value from memory.
     8	 * @ptr:	the pointer to load from.
     9	 * @type:	the type to load from the pointer.
    10	 *
    11	 * Use memcpy to affect an unaligned type sized load avoiding undefined behavior
    12	 * from approaches like type punning that require -fno-strict-aliasing in order
    13	 * to be correct. As type may be const, use _Generic to map to a non-const type
    14	 * - you can't memcpy into a const type. The void* cast silences ubsan warnings.
    15	 */
    16	#define __get_unaligned_t(type, ptr) ({					\
    17		type __get_unaligned_map_ctrl = 0;				\
    18		typeof(_Generic(__get_unaligned_map_ctrl,			\
    19			____get_unaligned_type(short int),			\
    20			____get_unaligned_type(unsigned short int),		\
    21			____get_unaligned_type(int),				\
    22			____get_unaligned_type(unsigned int),			\
    23			____get_unaligned_type(long),				\
    24			____get_unaligned_type(unsigned long),			\
    25			____get_unaligned_type(long long),			\
    26			____get_unaligned_type(unsigned long long),		\
    27			default: (type)0					\
    28			)) __get_unaligned_val;					\
    29		(void)__get_unaligned_map_ctrl;					\
  > 30		__builtin_memcpy(&__get_unaligned_val, (void *)(ptr),		\
    31				 sizeof(__get_unaligned_val));			\
    32		__get_unaligned_val;						\
    33	})
    34	
Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#4 lore raw

Re: [PATCH v2 1/3] vdso: Switch get/put unaligned from packed struct to memcpy

In reply to Ian Rogers
Quoted 10 lines · On Tue, 17 Jun 2025 13:53:18 -0700 Ian Rogers <[email protected]> wrote:

Type punning is necessary for get/put unaligned but the use of a packed struct violates strict aliasing rules, requiring -fno-strict-aliasing to be passed to the C compiler. Switch to using memcpy so that -fno-strict-aliasing isn't necessary.
.... \

include/vdso/unaligned.h +5 -0
+/**
+ * __put_unaligned_t - write an unaligned value to memory.
+ * @type:	the type of the value to store.
+ * @val:	the value to store.
+ * @ptr:	the pointer to store to.

include/vdso/unaligned.h line 49

Quoted 10 lines
include/vdso/unaligned.h +9 -0
+ *
+ * Use memcpy to affect an unaligned type sized store avoiding undefined
+ * behavior from approaches like type punning that require -fno-strict-aliasing
+ * in order to be correct. The void* cast silences ubsan warnings.
+ */
+#define __put_unaligned_t(type, val, ptr) do {				\
+	type __put_unaligned_val = (val);				\
+	__builtin_memcpy((void *)(ptr), &__put_unaligned_val,		\
+			 sizeof(__put_unaligned_val));			\
 } while (0)

Does that actually work?
If 'ptr' has type 'long *' gcc will (validly according to C) assume it is aligned and will generate a misaligned memory write. The (void *) cast make no difference.

Using (void *)(long)(ptr) might lose the alignment. Otherwise you may need to use OPTIMISER_HIDE_VAR() and live with the extra register-register move it tends to generate.

David

author
#5 lore raw

PATCH v2 2/3 tools headers: Update the linux/unaligned.h copy with the kernel sources

In reply to Ian Rogers

To pick up the changes in:

fe9b2b7b3583 vdso: Switch get/put unaligned from packed struct to memcpy

---
 tools/include/vdso/unaligned.h | 48 +++++++++++++++++++++++++++++-----
 1 file changed, 42 insertions(+), 6 deletions(-)
tools/include/vdso/unaligned.h +42 -6
index ff0c06b6513e..f33c1eefbf68 100644
@@ -2,14 +2,50 @@
 #ifndef __VDSO_UNALIGNED_H
 #define __VDSO_UNALIGNED_H
 
-#define __get_unaligned_t(type, ptr) ({							\
-	const struct { type x; } __packed * __get_pptr = (typeof(__get_pptr))(ptr);	\
-	__get_pptr->x;									\
+#define ____get_unaligned_type(type) type: (type)0
+/**
+ * __get_unaligned_t - read an unaligned value from memory.
+ * @ptr:	the pointer to load from.
+ * @type:	the type to load from the pointer.
+ *
+ * Use memcpy to affect an unaligned type sized load avoiding undefined behavior
+ * from approaches like type punning that require -fno-strict-aliasing in order
+ * to be correct. As type may be const, use _Generic to map to a non-const type
+ * - you can't memcpy into a const type. The void* cast silences ubsan warnings.
+ */
+#define __get_unaligned_t(type, ptr) ({					\
+	type __get_unaligned_map_ctrl = 0;				\
+	typeof(_Generic(__get_unaligned_map_ctrl,			\
+		____get_unaligned_type(short int),			\
+		____get_unaligned_type(unsigned short int),		\
+		____get_unaligned_type(int),				\
+		____get_unaligned_type(unsigned int),			\
+		____get_unaligned_type(long),				\
+		____get_unaligned_type(unsigned long),			\
+		____get_unaligned_type(long long),			\
+		____get_unaligned_type(unsigned long long),		\
+		default: (type)0					\
+		)) __get_unaligned_val;					\
+	(void)__get_unaligned_map_ctrl;					\
+	__builtin_memcpy(&__get_unaligned_val, (void *)(ptr),		\
+			 sizeof(__get_unaligned_val));			\
+	__get_unaligned_val;						\
 })
 
-#define __put_unaligned_t(type, val, ptr) do {						\
-	struct { type x; } __packed * __put_pptr = (typeof(__put_pptr))(ptr);		\
-	__put_pptr->x = (val);								\
+/**
+ * __put_unaligned_t - write an unaligned value to memory.
+ * @type:	the type of the value to store.
+ * @val:	the value to store.
+ * @ptr:	the pointer to store to.
+ *
+ * Use memcpy to affect an unaligned type sized store avoiding undefined
+ * behavior from approaches like type punning that require -fno-strict-aliasing
+ * in order to be correct. The void* cast silences ubsan warnings.
+ */
+#define __put_unaligned_t(type, val, ptr) do {				\
+	type __put_unaligned_val = (val);				\
+	__builtin_memcpy((void *)(ptr), &__put_unaligned_val,		\
+			 sizeof(__put_unaligned_val));			\
 } while (0)
 
 #endif /* __VDSO_UNALIGNED_H */
Signature · 1 line
2.50.0.rc2.701.gf1e915cc24-goog
author
#6 lore raw

PATCH v2 3/3 tools headers: Remove unneeded ignoring of warnings in unaligned.h

In reply to Ian Rogers

Now the get/put unaligned use memcpy the -Wpacked and -Wattributes warnings don't need disabling.

---
 tools/include/linux/unaligned.h | 4 ----
 1 file changed, 4 deletions(-)
tools/include/linux/unaligned.h +0 -4
index 395a4464fe73..d51ddafed138 100644
@@ -6,9 +6,6 @@
  * This is the most generic implementation of unaligned accesses
  * and should work almost anywhere.
  */
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wpacked"
-#pragma GCC diagnostic ignored "-Wattributes"
 #include <vdso/unaligned.h>
 
 #define get_unaligned(ptr)	__get_unaligned_t(typeof(*(ptr)), (ptr))
@@ -143,6 +140,5 @@ static inline u64 get_unaligned_be48(const void *p)
 {
 	return __get_unaligned_be48(p);
 }
-#pragma GCC diagnostic pop
 
 #endif /* __LINUX_UNALIGNED_H */
Signature · 1 line
2.50.0.rc2.701.gf1e915cc24-goog
#7 lore raw
In reply to Ian Rogers

Le 17/06/2025 à 22:53, Ian Rogers a écrit :

Quoted 7 lines

The existing type punning approach with packed structs requires
-fno-strict-aliasing to be passed to the compiler for
correctness. This is true in the kernel tree but not in the tools directory resulting in this suggested patch from Eric Biggers
<[email protected]>:
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Flkml%2F20250614044133.660848-2-ebiggers%40kernel.org%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Cf05413010ecc40ad1bdf08ddade1316a%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638857904894967529%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=29QUBLnUowncZiTH4z74Ec1olUlX0OTYnUNGDvWxX1o%3D&reserved=0

Quoted 9 lines

Requiring -fno-strict-aliasing seems unfortunate and so this patch makes the unaligned code work via memcpy for type punning rather than the packed attribute.

v2: switch memcpy to __builtin_memcpy to avoid potential/disallowed
memcpy calls in vdso caused by -fno-builtin. Reported by Christophe Leroy <[email protected]>:
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Flkml%2Fc57de5bf-d55c-48c5-9dfa-e2fb844dafe9%40csgroup.eu%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Cf05413010ecc40ad1bdf08ddade1316a%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638857904894985987%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=l1LJP3XPKVuhDpiHxxkfWBiNPMYaBT9YXGBFzs6wLpY%3D&reserved=0

Does this new version also fixes the failures reported by the robots:
- arm64-randconfig with clang 21
- i386-randconfig with gcc 12

Christophe

Quoted 11 lines

Ian Rogers (3):
vdso: Switch get/put unaligned from packed struct to memcpy tools headers: Update the linux/unaligned.h copy with the kernel
sources
tools headers: Remove unneeded ignoring of warnings in unaligned.h

  include/vdso/unaligned.h        | 48 ++++++++++++++++++++++++++++-----
  tools/include/linux/unaligned.h |  4 ---
  tools/include/vdso/unaligned.h  | 48 ++++++++++++++++++++++++++++-----
  3 files changed, 84 insertions(+), 16 deletions(-)
author
#8 lore raw
Quoted 15 lines · Christophe Leroy
Quoted 11 lines · Ian Rogers

The existing type punning approach with packed structs requires
-fno-strict-aliasing to be passed to the compiler for
correctness. This is true in the kernel tree but not in the tools directory resulting in this suggested patch from Eric Biggers
<[email protected]>:
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Flkml%2F20250614044133.660848-2-ebiggers%40kernel.org%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Cf05413010ecc40ad1bdf08ddade1316a%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638857904894967529%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=29QUBLnUowncZiTH4z74Ec1olUlX0OTYnUNGDvWxX1o%3D&reserved=0

Requiring -fno-strict-aliasing seems unfortunate and so this patch makes the unaligned code work via memcpy for type punning rather than the packed attribute.

Quoted 5 lines
Quoted 5 lines

v2: switch memcpy to __builtin_memcpy to avoid potential/disallowed
memcpy calls in vdso caused by -fno-builtin. Reported by Christophe Leroy <[email protected]>:
https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Flkml%2Fc57de5bf-d55c-48c5-9dfa-e2fb844dafe9%40csgroup.eu%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Cf05413010ecc40ad1bdf08ddade1316a%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638857904894985987%7CUnknown%7CTWFpbGZsb3d8eyJFbXB0eU1hcGkiOnRydWUsIlYiOiIwLjAuMDAwMCIsIlAiOiJXaW4zMiIsIkFOIjoiTWFpbCIsIldUIjoyfQ%3D%3D%7C0%7C%7C%7C&sdata=l1LJP3XPKVuhDpiHxxkfWBiNPMYaBT9YXGBFzs6wLpY%3D&reserved=0

So I think I can remove the _Generic block in unaligned.h by depending on the equivalent __unqual_scalar_typeof from include/linux/compiler_types.h. I think this is preferable and so I'll post a v3.

Quoted 2 lines

Does this new version also fixes the failures reported by the robots:
- arm64-randconfig with clang 21

The issue here was:

llvm-readelf: warning: 'arch/arm64/kernel/vdso/vdso.so.dbg': invalid
PT_DYNAMIC size (0x118)
llvm-readelf: warning: 'arch/arm64/kernel/vdso/vdso.so.dbg':
PT_DYNAMIC dynamic table is invalid: SHT_DYNAMIC will be used

which the switch to __builtin_memcpy should have resolved.

Quoted 1 line

- i386-randconfig with gcc 12

The reported error is in the unaligned code from sparse:

drivers/scsi/megaraid/megaraid_sas_base.c:8438:32: sparse: sparse:
Using plain integer as NULL pointer

I believe this is because of the _Generic block with a pointer type, and so the use of __unqual_scalar_typeof in the next/v3 patch set should hopefully resolve it - or else we'll need to special case pointer types to assign NULL rather than 0, but I'd prefer not to special case every potential pointer type.

Thanks,
Ian

Quoted 14 lines

Christophe

Quoted 11 lines

Ian Rogers (3):
vdso: Switch get/put unaligned from packed struct to memcpy tools headers: Update the linux/unaligned.h copy with the kernel
sources
tools headers: Remove unneeded ignoring of warnings in unaligned.h

  include/vdso/unaligned.h        | 48 ++++++++++++++++++++++++++++-----
  tools/include/linux/unaligned.h |  4 ---
  tools/include/vdso/unaligned.h  | 48 ++++++++++++++++++++++++++++-----
  3 files changed, 84 insertions(+), 16 deletions(-)