Re: will __attribute__((aligned(CACHE_LINE_SIZE))) break struct alignment

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 6 November 2017 at 15:46, Yubin Ruan wrote:
> Thanks Florian,
>
> 2017年11月6日星期一,Florian Weimer <fweimer@xxxxxxxxxx> 写道:
>
>> On 11/06/2017 06:04 AM, Yubin Ruan wrote:
>>
>>> I am using something like this:
>>>
>>>    struct S1 {
>>>      int index __attribute__((aligned(CACHE_LINE_SIZE)));
>>>      struct S2 some_other;
>>>    };
>>>
>>> I am not using anything like `#pragma pack`.
>>>
>>> I am wondering whether adding that
>>> `__attribute__((aligned(CACHE_LINE_SIZE)))` will break GCC's automatic
>>> alignment for S1 and S2. Can anyone point me to any document which
>>> specify this behavior?
>>>
>>
>> It will change the alignment of struct S1, so code which allocates objects
>> of struct S1 will have to be modified, and the offset in structs of a
>> member of type struct S1 will likely change (and so will the offsets of
>> members after it).
>>
>> So in general, this is not an ABI-compatible change.
>>
>
> Hmm... if struct S1 was aligned at a power of 4 boundary, then will that
> alignment be changed after adding that
> "__attribute__((aligned(CACHE_LINE_SIZE)))"? The same for "someother" ?

Assuming that CACHE_LINE_SIZE is also a power of four (which must be
true unless it equals 1 or 2) then it will still be a power of four,
but it might be a different power of four.

If the original alignment is 16 and CACHE_LINE_SIZE == 64 then it
changes from 16 to 64.

If the original alignment is 32 and CACHE_LINE_SIZE == 32 it won't change.




[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux