[PATCH] bfd/{pe, pei}-x86_64: Decrease preferred section alignment from 16 to 4

Jan Beulich jbeulich@suse.com
Fri Mar 28 07:36:43 GMT 2025


On 28.03.2025 07:34, LIU Hao wrote:

First - not (also) inlining patches makes it hard to comment.

I fear you saying merely "On x86-64, sections require only 4-byte alignment.
For example, we compile this program with Clang for x86_64-w64-mingw32: ...
The alignment of `.text` is 4 when optimizing for size, and 16 when optimizing
for speed. The exact same behavior can be observed when compiling with MSVC, or
when targeting ARM64." That's an observation, yes, but there may be historical
reasons why default alignment was set higher. Arm64 can't realistically serve
as a reference. MSVC possibly can, if its behavior was consistent across many
versions, or if it's clear why its behavior was changed at some point. My
preferred reference, if any, would be MASM though. The version I have to hand
sets .text, .data, .rdata, and .bss to 16-byte alignment.

Best, however, would be if you were able to point to a written down statement
somewhere. After all there must have been a reason why this was done
differently from what pe-i386.c and pei-i386.c have (and maybe it was MASM's
behavior). In fact, if there was a change to be made here, I'd wonder why we
wouldn't bring x86-64 back in sync with i386. I see as much or as little
reason to default to 4- as to 16-byte alignment. It can, in principle, all be
left to the programmer. Lowering alignment now may break existing code,
though.

Finally, just to double check - you did run the full testsuites, and there's
no fallout there at all?

Jan


More information about the Binutils mailing list