Question about deduplication of COMDAT sections with different alignment

Jan Beulich jbeulich@suse.com
Tue May 20 14:01:39 GMT 2025


On 20.05.2025 15:49, Jens Remus wrote:
> On 16.05.2025 15:24, Jens Remus wrote:
>> Shouldn't the linker retain the maximum section alignment when
>> deduplicating COMDAT sections with the same group signature, but
>> different section alignment?
> 
> Following is a minimal example showing the issue:
> 
> $ cat sample.sh
> #!/bin/bash
> set -e -u -x
> 
> AS="${AS:-as}"
> LD="${LD:-ld}"
> READELF="${READELF:-readelf}"
> 
> cat <<EOF > sample.s
>         .text
>         .globl _start
> _start:
>         nop
> 
>         .data
> pfoo:   .quad foo
> EOF
> 
> cat <<EOF > foo-1.s
>         .section .rodata.foo,"aG",@progbits,foo_group,comdat
>         .align 1
>         .globl foo
>         .type foo,@object
> foo:
>         .byte 1
>         .size foo, .-foo
> EOF
> 
> cat <<EOF > foo-2.s
>         .section .rodata.foo,"aG",@progbits,foo_group,comdat
>         .align 2
>         .globl foo
>         .type foo,@object
> foo:
>         .byte 2
>         .size foo, .-foo
> EOF
> 
> $AS -o sample.o sample.s
> $AS -o foo-1.o foo-1.s
> $AS -o foo-2.o foo-2.s
> $LD -o sample-12 sample.o foo-1.o foo-2.o
> $LD -o sample-21 sample.o foo-2.o foo-1.o
> $READELF -WS foo-1.o foo-2.o sample-12 sample-21 | grep -E "File:|\[Nr\]|\.rodata"
> 
> $ ./sample.sh
> [output truncated and reformatted]
> File      Name        Off    Size   ES Flg Lk Inf Al
> foo-1.o   .rodata.foo 000048 000001 00  AG  0   0  1
> foo-2.o   .rodata.foo 000048 000002 00  AG  0   0  2
> sample-12 .rodata     0000b4 000001 00   A  0   0  1 <-- !
> sample-21 .rodata     0000b4 000002 00   A  0   0  2
> 
> Shouldn't section .rodata in both sample-12 and sample-21 better have a
> 2-byte alignment, regardless of which instance of COMDAT section group
> foo_group got deduplicated?  After all code in foo-2.o (not part of this
> example) may rely on foo being 2-byte aligned.

Well. I may need to look into this in more detail, but one aspect right away:
Generally the expectation is that any of the instances can be picked, on the
basis that they're all functionally equivalent. While it's conceivable that
code (insn sequences) may differ across instances, I find it more difficult
to see how data (i.e. value, size, and alignment) could sensibly be different.

Jan


More information about the Binutils mailing list