https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102292
Bug ID: 102292 Summary: R_ARM_THM_JUMP24 incorrect link result if symbol duplicated Product: gcc Version: 10.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: lto Assignee: unassigned at gcc dot gnu.org Reporter: eason.lai at mediatek dot com CC: marxin at gcc dot gnu.org Target Milestone: --- Created attachment 51439 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51439&action=edit 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