On 18/02/2025 10:52 am, Alan Maguire wrote: > On 14/02/2025 16:34, Andrew Cooper wrote: >> Hello, >> >> I think this is a new feature request. >> >> I'm tracking down a UBSAN failure (only shows up on one arch, and it's >> in a list_for_each() so there's loads of container_of() going on too). >> >> Newer versions of pahole have the overall structure alignment given the >> end, but I can't seem to persuade it to give the the alignment of each >> field. >> >> More concretely, I'm looking at a structure which is nearly 4k in size, >> differs per arch and has an overall alignment of 128, but I can't find >> which sub-struct within it is causing such an alignment requirement. >> >> Would it be possible to also print the alignment information in the >> comments that exist already? i.e., instead of: >> >> /* $offset $size */ >> >> could we have >> >> /* $offset $size $align */ >> >> ? >> > hi Andrew, I might be missing something but I think "pahole -E > <struct_name>" should give what you're looking for. This should show > any nested structs which have alignment attributes associated. For > example with "pahole -E task_struct" I see the a few substructures > tagged with alignment attributes: > > $ pahole -E task_struct|grep align > } avg __attribute__((__aligned__(64))); /* 320 64 */ > } __attribute__((__aligned__(64))) stats > __attribute__((__aligned__(64))); /* 960 256 */ > /* Force alignment to the next boundary: */ > } regs __attribute__((__aligned__(64))); /* 6016 4096 */ > } fpu __attribute__((__aligned__(64))); /* 5888 4224 */ > } thread __attribute__((__aligned__(64))); /* 5696 4416 */ > /* forced alignments: 2, forced holes: 2, sum forced holes: 88 */ > > It's possible there are bugs that mean this doesn't always work > correctly of course; it would be worth trying if that helps and if you > run into any issues let us know. Thanks! Hmm, that's a little different. Still nothing internally, but: > } __attribute__((__aligned__(128))) arch > __attribute__((__aligned__(128))); /* 0x180 0x380 */ suggests I've been an idiot all along. This struct has an explicit align attribute, rather than an internal member causing this, hidden behind __cacheline_aligned which appears to be wrongly 128 instead of 64. Ok, so that explains my problem, but I still think it would be nice to get the alignment of every member. ~Andrew