Question about deduplication of COMDAT sections with different alignment

Jens Remus jremus@linux.ibm.com
Tue May 20 13:49:36 GMT 2025


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.

Thanks and regards,
Jens
-- 
Jens Remus
Linux on Z Development (D3303)
+49-7031-16-1128 Office
jremus@de.ibm.com

IBM

IBM Deutschland Research & Development GmbH; Vorsitzender des Aufsichtsrats: Wolfgang Wendt; Geschäftsführung: David Faller; Sitz der Gesellschaft: Böblingen; Registergericht: Amtsgericht Stuttgart, HRB 243294
IBM Data Privacy Statement: https://www.ibm.com/privacy/



More information about the Binutils mailing list