[1/5] perf tools: Add get_unaligned_leNN()

Message ID 20231005190451.175568-2-adrian.hunter@intel.com
State New
Headers
Series perf intel-pt: Use of get_unaligned_le16() etc |

Commit Message

Adrian Hunter Oct. 5, 2023, 7:04 p.m. UTC
  Add get_unaligned_le16(), get_unaligned_le32 and get_unaligned_le64, same
as include/asm-generic/unaligned.h.

Use diagnostic pragmas to ignore -Wpacked used by perf build.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
---
 tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
  

Comments

Arnaldo Carvalho de Melo Oct. 5, 2023, 7:38 p.m. UTC | #1
Em Thu, Oct 05, 2023 at 10:04:47PM +0300, Adrian Hunter escreveu:
> Add get_unaligned_le16(), get_unaligned_le32 and get_unaligned_le64, same
> as include/asm-generic/unaligned.h.
> 
> Use diagnostic pragmas to ignore -Wpacked used by perf build.

Can we get the tools copy of include/asm-generic/unaligned.h closer and
have it in check-headers.sh?

- Arnaldo
 
> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> ---
>  tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 
> diff --git a/tools/include/asm-generic/unaligned.h b/tools/include/asm-generic/unaligned.h
> index 47387c607035..9140bb4e16c6 100644
> --- a/tools/include/asm-generic/unaligned.h
> +++ b/tools/include/asm-generic/unaligned.h
> @@ -6,6 +6,9 @@
>  #ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
>  #define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
>  
> +#pragma GCC diagnostic push
> +#pragma GCC diagnostic ignored "-Wpacked"
> +
>  #define __get_unaligned_t(type, ptr) ({						\
>  	const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);	\
>  	__pptr->x;								\
> @@ -19,5 +22,22 @@
>  #define get_unaligned(ptr)	__get_unaligned_t(typeof(*(ptr)), (ptr))
>  #define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr))
>  
> +static inline u16 get_unaligned_le16(const void *p)
> +{
> +	return le16_to_cpu(__get_unaligned_t(__le16, p));
> +}
> +
> +static inline u32 get_unaligned_le32(const void *p)
> +{
> +	return le32_to_cpu(__get_unaligned_t(__le32, p));
> +}
> +
> +static inline u64 get_unaligned_le64(const void *p)
> +{
> +	return le64_to_cpu(__get_unaligned_t(__le64, p));
> +}
> +
> +#pragma GCC diagnostic pop
> +
>  #endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */
>  
> -- 
> 2.34.1
>
  
Adrian Hunter Oct. 10, 2023, 2:29 p.m. UTC | #2
On 5/10/23 22:38, Arnaldo Carvalho de Melo wrote:
> Em Thu, Oct 05, 2023 at 10:04:47PM +0300, Adrian Hunter escreveu:
>> Add get_unaligned_le16(), get_unaligned_le32 and get_unaligned_le64, same
>> as include/asm-generic/unaligned.h.
>>
>> Use diagnostic pragmas to ignore -Wpacked used by perf build.
> 
> Can we get the tools copy of include/asm-generic/unaligned.h closer and
> have it in check-headers.sh?

I sent another patch for that
  
Arnaldo Carvalho de Melo Oct. 26, 2023, 1:44 p.m. UTC | #3
Em Thu, Oct 05, 2023 at 04:38:05PM -0300, Arnaldo Carvalho de Melo escreveu:
> Em Thu, Oct 05, 2023 at 10:04:47PM +0300, Adrian Hunter escreveu:
> > Add get_unaligned_le16(), get_unaligned_le32 and get_unaligned_le64, same
> > as include/asm-generic/unaligned.h.
> > 
> > Use diagnostic pragmas to ignore -Wpacked used by perf build.
> 
> Can we get the tools copy of include/asm-generic/unaligned.h closer and
> have it in check-headers.sh?

And this is not building when cross building to mips, mips64 and mipsel
on debian:experimental:

In file included from util/intel-pt-decoder/intel-pt-pkt-decoder.c:10:
/git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le16':
/git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:29: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
   13 |         const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);      \
      |                             ^
/git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:27:28: note: in expansion of macro '__get_unaligned_t'
   27 |         return le16_to_cpu(__get_unaligned_t(__le16, p));
      |                            ^~~~~~~~~~~~~~~~~
/git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le32':
/git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:29: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
   13 |         const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);      \
      |                             ^
/git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:32:28: note: in expansion of macro '__get_unaligned_t'
   32 |         return le32_to_cpu(__get_unaligned_t(__le32, p));
      |                            ^~~~~~~~~~~~~~~~~


Ditto for some other distros when cross building on ubuntu:18.04

  MKDIR   /tmp/build/perf/util/perf-regs-arch/
In file included from /usr/sparc64-linux-gnu/include/bits/byteswap.h:34:0,
                 from /usr/sparc64-linux-gnu/include/endian.h:60,
                 from util/intel-pt-decoder/intel-pt-pkt-decoder.c:9:
/git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le16':
/git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:22: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
  const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
                      ^
/git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:27:21: note: in expansion of macro '__get_unaligned_t'
  return le16_to_cpu(__get_unaligned_t(__le16, p));
                     ^~~~~~~~~~~~~~~~~

  37    14.17 ubuntu:18.04-x-arm            : FAIL gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
  38    13.56 ubuntu:18.04-x-arm64          : FAIL gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
  42    12.70 ubuntu:18.04-x-riscv64        : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
  44    13.95 ubuntu:18.04-x-sh4            : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
  45    13.08 ubuntu:18.04-x-sparc64        : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
 
> - Arnaldo
>  
> > Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> > ---
> >  tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++
> >  1 file changed, 20 insertions(+)
> > 
> > diff --git a/tools/include/asm-generic/unaligned.h b/tools/include/asm-generic/unaligned.h
> > index 47387c607035..9140bb4e16c6 100644
> > --- a/tools/include/asm-generic/unaligned.h
> > +++ b/tools/include/asm-generic/unaligned.h
> > @@ -6,6 +6,9 @@
> >  #ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
> >  #define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
> >  
> > +#pragma GCC diagnostic push
> > +#pragma GCC diagnostic ignored "-Wpacked"
> > +
> >  #define __get_unaligned_t(type, ptr) ({						\
> >  	const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);	\
> >  	__pptr->x;								\
> > @@ -19,5 +22,22 @@
> >  #define get_unaligned(ptr)	__get_unaligned_t(typeof(*(ptr)), (ptr))
> >  #define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr))
> >  
> > +static inline u16 get_unaligned_le16(const void *p)
> > +{
> > +	return le16_to_cpu(__get_unaligned_t(__le16, p));
> > +}
> > +
> > +static inline u32 get_unaligned_le32(const void *p)
> > +{
> > +	return le32_to_cpu(__get_unaligned_t(__le32, p));
> > +}
> > +
> > +static inline u64 get_unaligned_le64(const void *p)
> > +{
> > +	return le64_to_cpu(__get_unaligned_t(__le64, p));
> > +}
> > +
> > +#pragma GCC diagnostic pop
> > +
> >  #endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */
> >  
> > -- 
> > 2.34.1
> > 
> 
> -- 
> 
> - Arnaldo
  
Adrian Hunter Oct. 26, 2023, 4:09 p.m. UTC | #4
On 26/10/23 16:44, Arnaldo Carvalho de Melo wrote:
> Em Thu, Oct 05, 2023 at 04:38:05PM -0300, Arnaldo Carvalho de Melo escreveu:
>> Em Thu, Oct 05, 2023 at 10:04:47PM +0300, Adrian Hunter escreveu:
>>> Add get_unaligned_le16(), get_unaligned_le32 and get_unaligned_le64, same
>>> as include/asm-generic/unaligned.h.
>>>
>>> Use diagnostic pragmas to ignore -Wpacked used by perf build.
>>
>> Can we get the tools copy of include/asm-generic/unaligned.h closer and
>> have it in check-headers.sh?
> 
> And this is not building when cross building to mips, mips64 and mipsel
> on debian:experimental:
> 
> In file included from util/intel-pt-decoder/intel-pt-pkt-decoder.c:10:
> /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le16':
> /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:29: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]

So I guess another diagnostic pragma is needed, perhaps the following works?

#pragma GCC diagnostic ignored "-Wattributes"


>    13 |         const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);      \
>       |                             ^
> /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:27:28: note: in expansion of macro '__get_unaligned_t'
>    27 |         return le16_to_cpu(__get_unaligned_t(__le16, p));
>       |                            ^~~~~~~~~~~~~~~~~
> /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le32':
> /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:29: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
>    13 |         const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);      \
>       |                             ^
> /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:32:28: note: in expansion of macro '__get_unaligned_t'
>    32 |         return le32_to_cpu(__get_unaligned_t(__le32, p));
>       |                            ^~~~~~~~~~~~~~~~~
> 
> 
> Ditto for some other distros when cross building on ubuntu:18.04
> 
>   MKDIR   /tmp/build/perf/util/perf-regs-arch/
> In file included from /usr/sparc64-linux-gnu/include/bits/byteswap.h:34:0,
>                  from /usr/sparc64-linux-gnu/include/endian.h:60,
>                  from util/intel-pt-decoder/intel-pt-pkt-decoder.c:9:
> /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le16':
> /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:22: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
>   const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
>                       ^
> /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:27:21: note: in expansion of macro '__get_unaligned_t'
>   return le16_to_cpu(__get_unaligned_t(__le16, p));
>                      ^~~~~~~~~~~~~~~~~
> 
>   37    14.17 ubuntu:18.04-x-arm            : FAIL gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
>   38    13.56 ubuntu:18.04-x-arm64          : FAIL gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
>   42    12.70 ubuntu:18.04-x-riscv64        : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
>   44    13.95 ubuntu:18.04-x-sh4            : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
>   45    13.08 ubuntu:18.04-x-sparc64        : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
>  
>> - Arnaldo
>>  
>>> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
>>> ---
>>>  tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++
>>>  1 file changed, 20 insertions(+)
>>>
>>> diff --git a/tools/include/asm-generic/unaligned.h b/tools/include/asm-generic/unaligned.h
>>> index 47387c607035..9140bb4e16c6 100644
>>> --- a/tools/include/asm-generic/unaligned.h
>>> +++ b/tools/include/asm-generic/unaligned.h
>>> @@ -6,6 +6,9 @@
>>>  #ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
>>>  #define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
>>>  
>>> +#pragma GCC diagnostic push
>>> +#pragma GCC diagnostic ignored "-Wpacked"
>>> +
>>>  #define __get_unaligned_t(type, ptr) ({						\
>>>  	const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);	\
>>>  	__pptr->x;								\
>>> @@ -19,5 +22,22 @@
>>>  #define get_unaligned(ptr)	__get_unaligned_t(typeof(*(ptr)), (ptr))
>>>  #define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr))
>>>  
>>> +static inline u16 get_unaligned_le16(const void *p)
>>> +{
>>> +	return le16_to_cpu(__get_unaligned_t(__le16, p));
>>> +}
>>> +
>>> +static inline u32 get_unaligned_le32(const void *p)
>>> +{
>>> +	return le32_to_cpu(__get_unaligned_t(__le32, p));
>>> +}
>>> +
>>> +static inline u64 get_unaligned_le64(const void *p)
>>> +{
>>> +	return le64_to_cpu(__get_unaligned_t(__le64, p));
>>> +}
>>> +
>>> +#pragma GCC diagnostic pop
>>> +
>>>  #endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */
>>>  
>>> -- 
>>> 2.34.1
>>>
>>
>> -- 
>>
>> - Arnaldo
>
  
Arnaldo Carvalho de Melo Oct. 26, 2023, 8:08 p.m. UTC | #5
Em Thu, Oct 26, 2023 at 07:09:26PM +0300, Adrian Hunter escreveu:
> On 26/10/23 16:44, Arnaldo Carvalho de Melo wrote:
> > Em Thu, Oct 05, 2023 at 04:38:05PM -0300, Arnaldo Carvalho de Melo escreveu:
> >> Em Thu, Oct 05, 2023 at 10:04:47PM +0300, Adrian Hunter escreveu:
> >>> Add get_unaligned_le16(), get_unaligned_le32 and get_unaligned_le64, same
> >>> as include/asm-generic/unaligned.h.
> >>>
> >>> Use diagnostic pragmas to ignore -Wpacked used by perf build.
> >>
> >> Can we get the tools copy of include/asm-generic/unaligned.h closer and
> >> have it in check-headers.sh?
> > 
> > And this is not building when cross building to mips, mips64 and mipsel
> > on debian:experimental:
> > 
> > In file included from util/intel-pt-decoder/intel-pt-pkt-decoder.c:10:
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le16':
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:29: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
> 
> So I guess another diagnostic pragma is needed, perhaps the following works?
> 
> #pragma GCC diagnostic ignored "-Wattributes"

I'll try it.

- Arnaldo
 
> 
> >    13 |         const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);      \
> >       |                             ^
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:27:28: note: in expansion of macro '__get_unaligned_t'
> >    27 |         return le16_to_cpu(__get_unaligned_t(__le16, p));
> >       |                            ^~~~~~~~~~~~~~~~~
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le32':
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:29: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
> >    13 |         const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);      \
> >       |                             ^
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:32:28: note: in expansion of macro '__get_unaligned_t'
> >    32 |         return le32_to_cpu(__get_unaligned_t(__le32, p));
> >       |                            ^~~~~~~~~~~~~~~~~
> > 
> > 
> > Ditto for some other distros when cross building on ubuntu:18.04
> > 
> >   MKDIR   /tmp/build/perf/util/perf-regs-arch/
> > In file included from /usr/sparc64-linux-gnu/include/bits/byteswap.h:34:0,
> >                  from /usr/sparc64-linux-gnu/include/endian.h:60,
> >                  from util/intel-pt-decoder/intel-pt-pkt-decoder.c:9:
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le16':
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:22: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
> >   const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
> >                       ^
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:27:21: note: in expansion of macro '__get_unaligned_t'
> >   return le16_to_cpu(__get_unaligned_t(__le16, p));
> >                      ^~~~~~~~~~~~~~~~~
> > 
> >   37    14.17 ubuntu:18.04-x-arm            : FAIL gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
> >   38    13.56 ubuntu:18.04-x-arm64          : FAIL gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
> >   42    12.70 ubuntu:18.04-x-riscv64        : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
> >   44    13.95 ubuntu:18.04-x-sh4            : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
> >   45    13.08 ubuntu:18.04-x-sparc64        : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
> >  
> >> - Arnaldo
> >>  
> >>> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> >>> ---
> >>>  tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++
> >>>  1 file changed, 20 insertions(+)
> >>>
> >>> diff --git a/tools/include/asm-generic/unaligned.h b/tools/include/asm-generic/unaligned.h
> >>> index 47387c607035..9140bb4e16c6 100644
> >>> --- a/tools/include/asm-generic/unaligned.h
> >>> +++ b/tools/include/asm-generic/unaligned.h
> >>> @@ -6,6 +6,9 @@
> >>>  #ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
> >>>  #define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
> >>>  
> >>> +#pragma GCC diagnostic push
> >>> +#pragma GCC diagnostic ignored "-Wpacked"
> >>> +
> >>>  #define __get_unaligned_t(type, ptr) ({						\
> >>>  	const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);	\
> >>>  	__pptr->x;								\
> >>> @@ -19,5 +22,22 @@
> >>>  #define get_unaligned(ptr)	__get_unaligned_t(typeof(*(ptr)), (ptr))
> >>>  #define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr))
> >>>  
> >>> +static inline u16 get_unaligned_le16(const void *p)
> >>> +{
> >>> +	return le16_to_cpu(__get_unaligned_t(__le16, p));
> >>> +}
> >>> +
> >>> +static inline u32 get_unaligned_le32(const void *p)
> >>> +{
> >>> +	return le32_to_cpu(__get_unaligned_t(__le32, p));
> >>> +}
> >>> +
> >>> +static inline u64 get_unaligned_le64(const void *p)
> >>> +{
> >>> +	return le64_to_cpu(__get_unaligned_t(__le64, p));
> >>> +}
> >>> +
> >>> +#pragma GCC diagnostic pop
> >>> +
> >>>  #endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */
> >>>  
> >>> -- 
> >>> 2.34.1
> >>>
> >>
> >> -- 
> >>
> >> - Arnaldo
> > 
>
  
Arnaldo Carvalho de Melo Nov. 9, 2023, 7:34 p.m. UTC | #6
Em Thu, Oct 26, 2023 at 07:09:26PM +0300, Adrian Hunter escreveu:
> On 26/10/23 16:44, Arnaldo Carvalho de Melo wrote:
> > Em Thu, Oct 05, 2023 at 04:38:05PM -0300, Arnaldo Carvalho de Melo escreveu:
> >> Em Thu, Oct 05, 2023 at 10:04:47PM +0300, Adrian Hunter escreveu:
> >>> Add get_unaligned_le16(), get_unaligned_le32 and get_unaligned_le64, same
> >>> as include/asm-generic/unaligned.h.
> >>>
> >>> Use diagnostic pragmas to ignore -Wpacked used by perf build.
> >>
> >> Can we get the tools copy of include/asm-generic/unaligned.h closer and
> >> have it in check-headers.sh?
> > 
> > And this is not building when cross building to mips, mips64 and mipsel
> > on debian:experimental:
> > 
> > In file included from util/intel-pt-decoder/intel-pt-pkt-decoder.c:10:
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le16':
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:29: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
> 
> So I guess another diagnostic pragma is needed, perhaps the following works?
> 
> #pragma GCC diagnostic ignored "-Wattributes"

Yeah, I tested with this and it works, I'll add a patch with your
Suggested-by, ok?

- Arnaldo
 
> 
> >    13 |         const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);      \
> >       |                             ^
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:27:28: note: in expansion of macro '__get_unaligned_t'
> >    27 |         return le16_to_cpu(__get_unaligned_t(__le16, p));
> >       |                            ^~~~~~~~~~~~~~~~~
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le32':
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:29: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
> >    13 |         const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);      \
> >       |                             ^
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:32:28: note: in expansion of macro '__get_unaligned_t'
> >    32 |         return le32_to_cpu(__get_unaligned_t(__le32, p));
> >       |                            ^~~~~~~~~~~~~~~~~
> > 
> > 
> > Ditto for some other distros when cross building on ubuntu:18.04
> > 
> >   MKDIR   /tmp/build/perf/util/perf-regs-arch/
> > In file included from /usr/sparc64-linux-gnu/include/bits/byteswap.h:34:0,
> >                  from /usr/sparc64-linux-gnu/include/endian.h:60,
> >                  from util/intel-pt-decoder/intel-pt-pkt-decoder.c:9:
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h: In function 'get_unaligned_le16':
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:13:22: error: packed attribute causes inefficient alignment for 'x' [-Werror=attributes]
> >   const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr); \
> >                       ^
> > /git/perf-6.6.0-rc1/tools/include/asm-generic/unaligned.h:27:21: note: in expansion of macro '__get_unaligned_t'
> >   return le16_to_cpu(__get_unaligned_t(__le16, p));
> >                      ^~~~~~~~~~~~~~~~~
> > 
> >   37    14.17 ubuntu:18.04-x-arm            : FAIL gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
> >   38    13.56 ubuntu:18.04-x-arm64          : FAIL gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04)
> >   42    12.70 ubuntu:18.04-x-riscv64        : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
> >   44    13.95 ubuntu:18.04-x-sh4            : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
> >   45    13.08 ubuntu:18.04-x-sparc64        : FAIL gcc version 7.5.0 (Ubuntu 7.5.0-3ubuntu1~18.04)
> >  
> >> - Arnaldo
> >>  
> >>> Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
> >>> ---
> >>>  tools/include/asm-generic/unaligned.h | 20 ++++++++++++++++++++
> >>>  1 file changed, 20 insertions(+)
> >>>
> >>> diff --git a/tools/include/asm-generic/unaligned.h b/tools/include/asm-generic/unaligned.h
> >>> index 47387c607035..9140bb4e16c6 100644
> >>> --- a/tools/include/asm-generic/unaligned.h
> >>> +++ b/tools/include/asm-generic/unaligned.h
> >>> @@ -6,6 +6,9 @@
> >>>  #ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
> >>>  #define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
> >>>  
> >>> +#pragma GCC diagnostic push
> >>> +#pragma GCC diagnostic ignored "-Wpacked"
> >>> +
> >>>  #define __get_unaligned_t(type, ptr) ({						\
> >>>  	const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);	\
> >>>  	__pptr->x;								\
> >>> @@ -19,5 +22,22 @@
> >>>  #define get_unaligned(ptr)	__get_unaligned_t(typeof(*(ptr)), (ptr))
> >>>  #define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr))
> >>>  
> >>> +static inline u16 get_unaligned_le16(const void *p)
> >>> +{
> >>> +	return le16_to_cpu(__get_unaligned_t(__le16, p));
> >>> +}
> >>> +
> >>> +static inline u32 get_unaligned_le32(const void *p)
> >>> +{
> >>> +	return le32_to_cpu(__get_unaligned_t(__le32, p));
> >>> +}
> >>> +
> >>> +static inline u64 get_unaligned_le64(const void *p)
> >>> +{
> >>> +	return le64_to_cpu(__get_unaligned_t(__le64, p));
> >>> +}
> >>> +
> >>> +#pragma GCC diagnostic pop
> >>> +
> >>>  #endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */
> >>>  
> >>> -- 
> >>> 2.34.1
> >>>
> >>
> >> -- 
> >>
> >> - Arnaldo
> > 
>
  

Patch

diff --git a/tools/include/asm-generic/unaligned.h b/tools/include/asm-generic/unaligned.h
index 47387c607035..9140bb4e16c6 100644
--- a/tools/include/asm-generic/unaligned.h
+++ b/tools/include/asm-generic/unaligned.h
@@ -6,6 +6,9 @@ 
 #ifndef __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
 #define __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H
 
+#pragma GCC diagnostic push
+#pragma GCC diagnostic ignored "-Wpacked"
+
 #define __get_unaligned_t(type, ptr) ({						\
 	const struct { type x; } __packed *__pptr = (typeof(__pptr))(ptr);	\
 	__pptr->x;								\
@@ -19,5 +22,22 @@ 
 #define get_unaligned(ptr)	__get_unaligned_t(typeof(*(ptr)), (ptr))
 #define put_unaligned(val, ptr) __put_unaligned_t(typeof(*(ptr)), (val), (ptr))
 
+static inline u16 get_unaligned_le16(const void *p)
+{
+	return le16_to_cpu(__get_unaligned_t(__le16, p));
+}
+
+static inline u32 get_unaligned_le32(const void *p)
+{
+	return le32_to_cpu(__get_unaligned_t(__le32, p));
+}
+
+static inline u64 get_unaligned_le64(const void *p)
+{
+	return le64_to_cpu(__get_unaligned_t(__le64, p));
+}
+
+#pragma GCC diagnostic pop
+
 #endif /* __TOOLS_LINUX_ASM_GENERIC_UNALIGNED_H */