[PATCH] ld: arm: Test Thumb PLT sizing after attribute merging

Torbjorn SVENSSON torbjorn.svensson@foss.st.com
Tue Nov 17 06:40:15 GMT 2026


Another gentle ping! :)

Kind regards,
Torbjörn

On 2026-10-27 10:53, Torbjorn SVENSSON wrote:
> Gentle ping! :)
> 
> Kind regards,
> Torbjörn
> 
> On 2026-10-16 20:38, Torbjörn SVENSSON wrote:
>> Hi,
>>
>> I found this issue using the GNU Toolchain Release 15.3.rel2 from Arm
>> that is based on users/ARM/binutils-2_45-branch.
>> Looking at existing release branches, 2.47.0 is fixed, but earlier
>> versions has this overflow.
>>
>> Ok for master and binutils-2_47-branch?
>>
>> Kind regards,
>> Torbjörn
>>
>> -- 
>>
>> Add regression coverage for bd8942a0e049a466f9b649364bf53445fb47dd0c.
>>
>> I stumbled upon the PLT sizing bug fixed by the above commit when
>> linking the GCC LTO test pr87906 with -shared for a Thumb-only
>> arm-none-eabi target with Thumb-2 support.
>>
>> Add a new test that reproduces the PLT corruption encountered in
>> pr87906 by linking an object without .ARM.attributes before an
>> ARMv7-M object containing calls to three external functions.
>> Before the fix, the linker used the first object's attributes to
>> reserve space for a 20-byte ARM PLT header and three 12-byte entries.
>> It then used the merged output attributes to emit a 16-byte Thumb
>> header and 16-byte Thumb entries.
>>
>> The mismatch leaves only 56 bytes allocated for a PLT that requires
>> 64 bytes.  The entries are placed 12 bytes apart but occupy 16 bytes
>> each, so they overwrite one another and the final entry extends beyond
>> the section buffer.  The output therefore contains corrupted PLT
>> instructions and an incomplete final entry.
>>
>> This requires a Thumb-only target with Thumb-2 support.  Thumb-1-only
>> targets are rejected before the PLT entries are emitted because
>> Thumb-1 PLT generation is not supported.
>>
>> ld/
>>     * testsuite/ld-arm/arm-elf.exp: Run thumb-plt-size.
>>     * testsuite/ld-arm/thumb-plt-size.s: New test source.
>>     * testsuite/ld-arm/thumb-plt-size.d: New test expectations.
>> ---
>>   ld/testsuite/ld-arm/arm-elf.exp      |  1 +
>>   ld/testsuite/ld-arm/thumb-plt-size.d | 50 ++++++++++++++++++++++++++++
>>   ld/testsuite/ld-arm/thumb-plt-size.s |  6 ++++
>>   3 files changed, 57 insertions(+)
>>   create mode 100644 ld/testsuite/ld-arm/thumb-plt-size.d
>>   create mode 100644 ld/testsuite/ld-arm/thumb-plt-size.s
>>
>> diff --git a/ld/testsuite/ld-arm/arm-elf.exp b/ld/testsuite/ld-arm/arm-elf.exp
>> index f50c0c1795c..d2208cc9c86 100644
>> --- a/ld/testsuite/ld-arm/arm-elf.exp
>> +++ b/ld/testsuite/ld-arm/arm-elf.exp
>> @@ -1299,4 +1299,5 @@ run_dump_test "non-contiguous-arm7"
>>   if { [check_shared_lib_support] } {
>>       run_dump_test "thumb-plt"
>>       run_dump_test "thumb-plt-got"
>> +    run_dump_test "thumb-plt-size"
>>   }
>> diff --git a/ld/testsuite/ld-arm/thumb-plt-size.d b/ld/testsuite/ld-arm/thumb-plt-size.d
>> new file mode 100644
>> index 00000000000..1b7e61b73ee
>> --- /dev/null
>> +++ b/ld/testsuite/ld-arm/thumb-plt-size.d
>> @@ -0,0 +1,50 @@
>> +#source: blank.s RUN_OBJCOPY
>> +#source: thumb-plt-size.s
>> +#objcopy_objects: -R .ARM.attributes
>> +#name: Thumb PLT size after attribute merging
>> +#ld: -shared --section-start=.plt=0x1000 --section-start=.text=0x2000 --section-start=.got=0x8000
>> +#objdump: -h -d -j .plt
>> +#skip: *-*-pe *-*-wince *-*-vxworks armeb-*-* *-*-gnueabihf *-*-musleabihf
>> +
>> +# The first input has no .ARM.attributes; the second specifies a
>> +# Thumb-only architecture with Thumb-2 support.  PLT sizing must use
>> +# the merged output attributes, reserving a 16-byte header and three
>> +# 16-byte entries rather than a 20-byte ARM header and three 12-byte
>> +# entries.
>> +
>> +.*: +file format .*arm.*
>> +
>> +Sections:
>> +Idx Name +Size +VMA +LMA +File off +Algn
>> + +0 .plt +00000040 +00001000 +00001000 +[0-9a-f]+ +2\*\*2
>> + +CONTENTS, ALLOC, LOAD, READONLY, CODE
>> +
>> +Disassembly of section \.plt:
>> +
>> +00001000 <\.plt>:
>> + +1000:    b500          push    {lr}
>> + +1002:    f8df e008     ldr.w    lr, \[pc, #8\]    @ 100c <\.plt\+0xc>
>> + +1006:    44fe          add    lr, pc
>> + +1008:    f85e ff08     ldr.w    pc, \[lr, #8\]!
>> + +100c:    00006ff4     \.word    0x00006ff4
>> +
>> +00001010 <baz@plt>:
>> + +1010:    f646 7cf0     movw    ip, #28656    @ 0x6ff0
>> + +1014:    f2c0 0c00     movt    ip, #0
>> + +1018:    44fc          add    ip, pc
>> + +101a:    f8dc f000     ldr.w    pc, \[ip\]
>> + +101e:    e7fc          b.n    101a <baz@plt\+0xa>
>> +
>> +00001020 <foo@plt>:
>> + +1020:    f646 7ce4     movw    ip, #28644    @ 0x6fe4
>> + +1024:    f2c0 0c00     movt    ip, #0
>> + +1028:    44fc          add    ip, pc
>> + +102a:    f8dc f000     ldr.w    pc, \[ip\]
>> + +102e:    e7fc          b.n    102a <foo@plt\+0xa>
>> +
>> +00001030 <bar@plt>:
>> + +1030:    f646 7cd8     movw    ip, #28632    @ 0x6fd8
>> + +1034:    f2c0 0c00     movt    ip, #0
>> + +1038:    44fc          add    ip, pc
>> + +103a:    f8dc f000     ldr.w    pc, \[ip\]
>> + +103e:    e7fc          b.n    103a <bar@plt\+0xa>
>> diff --git a/ld/testsuite/ld-arm/thumb-plt-size.s b/ld/testsuite/ld-arm/thumb-plt-size.s
>> new file mode 100644
>> index 00000000000..c7693f8d20a
>> --- /dev/null
>> +++ b/ld/testsuite/ld-arm/thumb-plt-size.s
>> @@ -0,0 +1,6 @@
>> +    .arch armv7-m
>> +    .thumb
>> +    .text
>> +    bl foo
>> +    bl bar
>> +    bl baz
> 



More information about the Binutils mailing list