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

Jan Beulich jbeulich@suse.com
Mon Mar 31 07:49:16 GMT 2025


On 31.03.2025 09:34, LIU Hao wrote:
> 在 2025-3-31 15:13, Jan Beulich 写道:
>> On 30.03.2025 13:43, LIU Hao wrote:
>>>    #define COFF_SECTION_ALIGNMENT_ENTRIES \
>>>    { COFF_SECTION_NAME_EXACT_MATCH (".bss"), \
>>> -  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
>>> +  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
>>>    { COFF_SECTION_NAME_PARTIAL_MATCH (".data"), \
>>> -  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
>>> +  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
>>>    { COFF_SECTION_NAME_PARTIAL_MATCH (".rdata"), \
>>> -  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
>>> +  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
>>>    { COFF_SECTION_NAME_PARTIAL_MATCH (".text"), \
>>> -  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 4 }, \
>>> +  COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
>>>    { COFF_SECTION_NAME_PARTIAL_MATCH (".idata"), \
>>>      COFF_ALIGNMENT_FIELD_EMPTY, COFF_ALIGNMENT_FIELD_EMPTY, 2 }, \
>>>    { COFF_SECTION_NAME_EXACT_MATCH (".pdata"), \
>>
>> I remain unconvinced that we can do it like this.
> 
> LLVM has already been doing that, no?

Right, and people using that will have adopted their code. People using gas
may be caught by surprise if we change default alignment like this. The
changes you needed to make elsewhere (testsuite, gcc) demonstrate that very
aspect.

>>> --- a/ld/testsuite/ld-pe/pr26659-weak-undef-sym.d
>>> +++ b/ld/testsuite/ld-pe/pr26659-weak-undef-sym.d
>>> @@ -13,7 +13,7 @@
>>>     *[0-9a-f]+:	48 85 c0             	test   %rax,%rax
>>>     *[0-9a-f]+:	74 05                	je     [0-9a-f]+ <foo\+0x1c>
>>>     *[0-9a-f]+:	e8 e4 ef [fb]f [fb]f       	call   100000000 <__size_of_stack_reserve__\+0xffe00000>
>>> - *[0-9a-f]+:	48 8b 05 ed 0f 00 00 	mov    0xfed\(%rip\),%rax        # [0-9a-f]+ <.refptr.bar2>
>>> + *[0-9a-f]+:	48 8b 05 e5 0f 00 00 	mov    0xfe5\(%rip\),%rax        # [0-9a-f]+ <.refptr.bar2>
>>
>> Instead of the 0xfe5 imo we also better would use 0x[0-9a-f]+ there. It's
>> the <.refptr.bar2> on the far right which is important to match.
> 
> This makes sense. `.refptr` can't be referenced outside %rip ± 2GB, otherwise it would be a serious 
> trouble; the displacement just doesn't matter.
> 
> 
> I request a confirmation about whether we have agreed that this patch with all the changes above is 
> acceptable. I wouldn't send a new patch before that, as it just sounds like noise.

No agreement thus far, I'm afraid. I did outline a less risky approach before.
An approach leaving out all risk would be to make the new behavior dependent
upon a command line option. (The default of such a command line option could
further be controlled by a configure-time option, but in any event the "first
level" default imo needs to be to retain present behavior. Or else there will
be risk of breaking people's code.)

Jan


More information about the Binutils mailing list