https://sourceware.org/bugzilla/show_bug.cgi?id=32896

--- Comment #8 from Matthew Malcomson <mmalcomson at nvidia dot com> ---
(In reply to H.J. Lu from comment #6)
> (In reply to Matthew Malcomson from comment #5)
> > I think that this proposed patch could allow putting the PT_TLS segment
> > offset past the end of the file (that I think was a problem in
> > https://sourceware.org/bugzilla/show_bug.cgi?id=12921 ).
> > 
> > This because it doesn't adjust the `off` that indicates position into the
> > file.
> 
> The updated patch is at:
> 
> https://sourceware.org/pipermail/binutils/2025-April/140755.html

I had a look at this patch, and it does seem to ensure that the PT_TLS segment
has the correct alignment requirements.

I noticed that with this patch one can end up with a very large PT_TLS filesize
if you re-order the .tbss and .tdata sections.  Not sure whether this would be
problematic in some way.  I did have to use a testcase that was triggering a
linker warning so it may be invalid.


vshcmd: > cat tbss-makes-huge-segment.s
    # Put enough data into the file to get to the next `maxpagesize`
    .section .rodata,"a",@progbits
    .align 4
    .zero 0x10000

    .section    .tbss,"awT",@nobits
    .align 4
    .type   abc, @object
    .size   abc, 4
abc:
    .zero   4

    # Have .tdata and .tbss, so that the
    # `assign_file_positions_for_non_load_sections` function takes the file
    # position from the two separate sections.
    .section .tdata,"awT",@progbits
    .align 4
    .type val, @object
    .size val, 4
val:
    .word 13

    .text
    .global _start
_start:
tls-segfault [11:13:17] $ 
vshcmd: > # Only difference between default linker script and the one I'm using
vshcmd: > # here is the location of the .tbss section (now before the .tdata
vshcmd: > # section).
vshcmd: > diff segment-too-large.ld \
vshcmd: >      
<(../build-aarch64-none-linux-gnu/install/bin/aarch64-none-linux-gnu-ld
-verbose | sed -n '/=====/,/=====/p')
> 0a1,10
> ==================================================
> /* Script for -z combreloc */
> /* Copyright (C) 2014-2025 Free Software Foundation, Inc.
>    Copying and distribution of this script, with or without modification,
>    are permitted in any medium without royalty provided the copyright
>    notice and this notice are preserved.  */
> OUTPUT_FORMAT("elf64-littleaarch64", "elf64-bigaarch64", 
> "elf64-littleaarch64")
> OUTPUT_ARCH(aarch64)
> ENTRY(_start)
> SEARCH_DIR("=/aarch64-none-linux-gnu/lib64"); 
> SEARCH_DIR("=/usr/local/lib64"); SEARCH_DIR("=/lib64"); 
> SEARCH_DIR("=/usr/lib64"); SEARCH_DIR("=/aarch64-none-linux-gnu/lib"); 
> SEARCH_DIR("=/usr/local/lib"); SEARCH_DIR("=/lib"); SEARCH_DIR("=/usr/lib");
98d107
<   .tbss                 : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
103a113
>   .tbss                 : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }
245a256
> ==================================================
tls-segfault [11:13:20] $ 
vshcmd: > ../build-aarch64-none-linux-gnu/install/bin/aarch64-none-linux-gnu-as
\
vshcmd: >   tbss-makes-huge-segment.s -o tbss-makes-huge-segment.o
vshcmd: > ../build-aarch64-none-linux-gnu/install/bin/aarch64-none-linux-gnu-ld
\
vshcmd: >   -T segment-too-large.ld \
vshcmd: >   tbss-makes-huge-segment.o -o tbss-makes-huge-segment
vshcmd: >
../build-aarch64-none-linux-gnu/install/bin/aarch64-none-linux-gnu-readelf
--segments --wide tbss-makes-huge-segment
> tls-segfault [11:13:22] $ > > 
> ../build-aarch64-none-linux-gnu/install/bin/aarch64-none-linux-gnu-ld: 
> tbss-makes-huge-segment: section .tdata lma 0x42ffe0 adjusted to 0x42ffe4
tls-segfault [11:13:22] $ 
Elf file type is EXEC (Executable file)
Entry point 0x400120
There are 4 program headers, starting at offset 64

Program Headers:
    Type           Offset   VirtAddr           PhysAddr           FileSiz 
MemSiz   Flg Align
    LOAD           0x000000 0x0000000000400000 0x0000000000400000 0x010120
0x010120 R   0x10000
    LOAD           0x01ffe0 0x000000000042ffe0 0x000000000042ffe0 0x000004
0x000004 RW  0x10000
    TLS            0x000010 0x000000000042ffe0 0x000000000042ffe0 0x01ffd4
0x000008 R   0x10
    GNU_RELRO      0x000010 0x000000000042ffe0 0x000000000042ffe0 0x000004
0x000020 R   0x1

    Section to Segment mapping:
    Segment Sections...
    00     .rodata 
    01     .tdata 
    02     .tbss .tdata 
    03     
tls-segfault [11:13:22] $

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to