Bug 102292 - R_ARM_THM_JUMP24 incorrect link result if symbol duplicated
Summary: R_ARM_THM_JUMP24 incorrect link result if symbol duplicated
Status: UNCONFIRMED
Alias: None
Product: gcc
Classification: Unclassified
Component: lto (show other bugs)
Version: 10.2.1
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-09-11 16:21 UTC by Eason Lai
Modified: 2021-09-13 01:33 UTC (History)
1 user (show)

See Also:
Host:
Target: arm
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
simple code to reproduce this issue (1.14 KB, application/x-gzip)
2021-09-11 16:21 UTC, Eason Lai
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eason Lai 2021-09-11 16:21:24 UTC
Created attachment 51439 [details]
simple code to reproduce this issue

If a program is linked with duplicated symbol, one in symbol file and another one in object file, the R_ARM_THM_JUMP24(b.w) result will be incorrect.

Please find the simple code from the attachment.
Following are the results of simple code.

(Correct) The veneer stay in THUMB mode if LTO is disabled.

Disassembly of section .text:

00001000 <dummy>:
    1000:       f04f 0004       mov.w   r0, #4
    1004:       f04f 0105       mov.w   r1, #5
    1008:       f000 b806       b.w     1018 <__foo_veneer>
    100c:       4770            bx      lr

0000100e <main>:
    100e:       b508            push    {r3, lr}
    1010:       f7ff fff6       bl      1000 <dummy>
    1014:       2000            movs    r0, #0
    1016:       bd08            pop     {r3, pc}

00001018 <__foo_veneer>:
    1018:       b401            push    {r0}
    101a:       4802            ldr     r0, [pc, #8]    ; (1024 <__foo_veneer+0xc>)
    101c:       4684            mov     ip, r0
    101e:       bc01            pop     {r0}
    1020:       4760            bx      ip
    1022:       bf00            nop
    1024:       10009ed1        .word   0x10009ed1


(Incorrect) The veneer switch to ARM mode if LTO is enabled.

Disassembly of section .text:

00001000 <dummy>:
    1000:       f04f 0004       mov.w   r0, #4
    1004:       f04f 0105       mov.w   r1, #5
    1008:       f000 b806       b.w     1018 <__foo_veneer>
    100c:       4770            bx      lr

0000100e <main>:
    100e:       b510            push    {r4, lr}
    1010:       2000            movs    r0, #0
    1012:       f7ff fff5       bl      1000 <dummy>
    1016:       bd10            pop     {r4, pc}

00001018 <__foo_veneer>:
    1018:       4778            bx      pc
    101a:       e7fd            b.n     1018 <__foo_veneer>
    101c:       e51ff004        ldr     pc, [pc, #-4]   ; 1020 <__foo_veneer+0x8>
    1020:       10009ed0        .word   0x10009ed0
    1024:       00000000        .word   0x00000000


(Correct) After removing foo.o from C_OBJS in Makefile, the veneer stay in THUMB mode as expected when LTO is enabled.

Disassembly of section .text:

00001000 <dummy>:
    1000:       f04f 0004       mov.w   r0, #4
    1004:       f04f 0105       mov.w   r1, #5
    1008:       f000 b806       b.w     1018 <__foo_veneer>
    100c:       4770            bx      lr

0000100e <main>:
    100e:       b510            push    {r4, lr}
    1010:       2000            movs    r0, #0
    1012:       f7ff fff5       bl      1000 <dummy>
    1016:       bd10            pop     {r4, pc}

00001018 <__foo_veneer>:
    1018:       b401            push    {r0}
    101a:       4802            ldr     r0, [pc, #8]    ; (1024 <__foo_veneer+0xc>)
    101c:       4684            mov     ip, r0
    101e:       bc01            pop     {r0}
    1020:       4760            bx      ip
    1022:       bf00            nop
    1024:       10009ed1        .word   0x10009ed1
Comment 1 Andrew Pinski 2021-09-11 18:28:59 UTC
Are you sure this is not a linker issue?
Comment 2 Eason Lai 2021-09-13 01:28:35 UTC
sorry, I'm not sure whether this is a linker issue or not. Only thing I know is enabling or disabling LTO makes the result different. 
I can do more experiments to provide information if any suggestions. Thank you very much.