is there a way to find the maximum alignment supported by the linker?

tim prince via gcc-help
Sun Jun 11 20:18:00 GMT 2017

On 6/11/2017 3:34 PM, Toby Douglass wrote:
> Hej, all.
> GCC supports an attribute "alignment".
> The docs state the extent to which alignment can be modified depends
> on the linker, and it can be very small.
> In my code, I have two options; I can either align by double word
> length (i.e. 8 or 16 bytes, depending on target) or I can align by the
> size required for "atomic isolation", which is to say on Intel
> cache-line length, which is up to and including 128 bytes, and on
> arm/aarch64 up to and including 2048 bytes, which is the maximum
> exclusive reservation granule size.
> The docs state if you ask for too much alignment, the linker will fall
> back to doing only the most it can do, which isn't very satisfactory,
> since you have no idea if it's happening or what that value is.
> Is there a way to find out the maximum alignment supported by the iinker?
You may need to look at the binutils source (if  your gcc uses gnu ld), 
where the maximum supported alignment is defined.  32-byte alignment 
needs to be supported for x86-64 platforms beginning with Intel Nehalem; 
64-byte alignment for those which support AVX512.  So it is a poor 
quality build of binutils which doesn't meet those requirements.   Not 
many years ago, the binutils default on windows was less than 16-byte 
alignment and so it was useful to build your own copy with this 
corrected, but there may be a limit to what the platform can support.  
Surely, you can run objdump on your executables and see what alignments 
you get in those spots where you set a request.  Agreed that 128-byte 
alignment on x86 might avoid some situations where the prefetcher brings 
in a useless adjacent cache line, but the cache line size is 64 bytes.

More information about the Gcc-help mailing list