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

LIU Hao lh_mouse@126.com
Fri Mar 28 11:16:50 GMT 2025


在 2025-3-28 18:15, Jan Beulich 写道:
> IOW you're (implicitly) suggesting we add a way for compilers to indicate to
> the assembler that this is compiler-generated code, and that behavior should
> be different than for hand-written assembly. There's already -f, but that
> has other effects, so is very unlikely to be usable here.

Apart from what Martin has commented, when optimizing for speed, the compiler emits `.palign 4` to 
increase the alignment to 16, which makes sense. I presume there's no directive to do decrease 
alignment..? It would be what we call a weird behavior I think.


>>> Finally, just to double check - you did run the full testsuites, and there's
>>> no fallout there at all?
>>
>> I did have a look in GNU AS testsuite, and did not find any checks against alignment of outputs. In order
>> to be certain, attached are test results of current master and current mater with the proposed patch
>> applied. There's no more error.
> 
> Good. But you understand that the other binutils subdir tests also need to
> pass without regressions. There definitely are tests which look for certain
> section alignment. See e.g. binutils' set-section-alignment.d. (With the
> defaults here that's pretty useless on x86-64 then right now; it would need
> higher than 16 as command line option to actually check that the command
> line option takes effect.)

I will take a look later tomorrow. If any tests have to be fixed, I will propose another patch.

One more word, I have not found any specification about section alignments in object files. However there 
is indeed a specification for image files, which is 512 [1]. According to that, assuming the linker will 
align the entire section properly, whether we choose 4 or 16 really doesn't matter. There was code in LD 
which placed static ctor and dtor function pointers in `.text` section, which made `.text` require an 
alignment of 8, but I fixed that (they are in `.rdata` now) so it would not block this change.


[1] 
https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#optional-header-windows-specific-fields-image-only



-- 
Best regards,
LIU Hao
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature.asc
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://sourceware.org/pipermail/binutils/attachments/20250328/461e1bca/attachment.sig>


More information about the Binutils mailing list