This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Thanks Florian,

2017年11月6日星期一,Florian Weimer <fweimer@redhat.com> 写道:

> 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" ?

Yubin


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]