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

Jan Beulich jbeulich@suse.com
Mon Mar 31 07:13:51 GMT 2025


On 30.03.2025 13:43, LIU Hao wrote:
> The `.refptr` fix has been committed to GCC master 
> (https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=8d42378acdf1a011420ba78685f7a6c79808c881).

But that means older gcc with a gas patched as suggested here will produce not entirely
correct code?

Looking at that patch (and some of the involved code) I also can't see why its 8-byte
alignment (and .quad) uniformly. This code is also used for 32-bit, isn't it?

> Code is reverted to the first patch; only tests are updated. Test results are identical to patch v2.
> 
> 
> * gas/testsuite/gas/i386/x86-64-secidx.d
> 
>     Fix a typo in test name. `.data` is now aligned to 4 bytes, so the 4 `.word` take
>     only 8 bytes now.
> 
> * gas/testsuite/gas/pe/peseh-x64-{5,6}.d
> 
>     Remove check for offsets of `.xdata` and `.pdata` sections, because they are subject
>     to the sizes of all preceding sections.
> 
> * ld/testsuite/ld-pe/pr26659-weak-undef-sym.{s,d}
> 
>     Align `.refptr` properly, and fix the displacement to `.refptr.bar2` accordingly.
> 
> * ld/testsuite/ld-pe/secidx.d
> 
>     Escape dots in regular expressions.
> 

This change is entirely unrelated here. Pre-approved if broken out to a
standalone change.

> --- a/bfd/pe-x86_64.c
> +++ b/bfd/pe-x86_64.c
> @@ -48,13 +48,13 @@
> 
>   #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"), \
> --- a/bfd/pei-x86_64.c
> +++ b/bfd/pei-x86_64.c
> @@ -42,13 +42,13 @@
> 
>   #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.

> --- 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.

Jan


More information about the Binutils mailing list