[PATCH] bfd/{pe, pei}-x86_64: Decrease preferred section alignment from 16 to 4
Jan Beulich
jbeulich@suse.com
Fri Mar 28 11:41:35 GMT 2025
On 28.03.2025 12:16, LIU Hao wrote:
> 在 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.
Indeed.
What we may want here is a means to effect pre-defined alignment not upon
section creation, but later. We could e.g. add a heuristic that the (then
prior) default is to be applied if the first contribution to a section
isn't preceded by an alignment directive. (I didn't think through all
aspects of this yet. E.g. sub-sections may need special consideration.)
>>>> 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].
That may be a default value. Other values are definitely possible and
observable in the wild.
> According to that, assuming the linker will
> align the entire section properly, whether we choose 4 or 16 really doesn't matter.
How would it not matter? If someone relies on 16-byte alignment without
having a respective .align directive, and if an item of interest requires
16-byte alignment, they'd be hosed in a possibly seemingly random fashion,
as things working would then depend on earlier contributions to the same
section (from other object files).
Jan
> 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
>
>
>
More information about the Binutils
mailing list