lkml.org 
[lkml]   [2022]   [Aug]   [1]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRE: [for-next][PATCH 21/21] tracing: Use a struct alignof to determine trace event field alignment
Date
From: Steven Rostedt
> Sent: 31 July 2022 20:04
>
> alignof() gives an alignment of types as they would be as standalone
> variables. But alignment in structures might be different, and when
> building the fields of events, the alignment must be the actual
> alignment otherwise the field offsets may not match what they actually
> are.
>
> This caused trace-cmd to crash, as libtraceevent did not check if the
> field offset was bigger than the event. The write_msr and read_msr
> events on 32 bit had their fields incorrect, because it had a u64 field
> between two ints. alignof(u64) would give 8, but the u64 field was at a
> 4 byte alignment.
>
> Define a macro as:
>
> ALIGN_STRUCTFIELD(type) ((int)(offsetof(struct {char a; type b;}, b)))
>
> which gives the actual alignment of types in a structure.

The simpler:
__alignof__(struct {type b;})
also works.

David

-
Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK
Registration No: 1397386 (Wales)
\
 
 \ /
  Last update: 2022-08-01 09:46    [W:0.224 / U:0.136 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site