From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 26730 invoked by alias); 18 Jun 2009 14:25:55 -0000 Received: (qmail 26716 invoked by uid 22791); 18 Jun 2009 14:25:53 -0000 X-SWARE-Spam-Status: No, hits=-1.9 required=5.0 tests=AWL,BAYES_00,J_CHICKENPOX_61 X-Spam-Check-By: sourceware.org Received: from eu1sys200aog109.obsmtp.com (HELO eu1sys200aog109.obsmtp.com) (207.126.144.127) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 18 Jun 2009 14:25:45 +0000 Received: from source ([164.129.1.35]) (using TLSv1) by eu1sys200aob109.postini.com ([207.126.147.11]) with SMTP ID DSNKSjpOZMbBRpw614DySidxcSvNu71eBHRD@postini.com; Thu, 18 Jun 2009 14:25:44 UTC Received: from zeta.dmz-eu.st.com (ns2.st.com [164.129.230.9]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 56FB014F; Thu, 18 Jun 2009 14:25:39 +0000 (GMT) Received: from mail2.gnb.st.com (mail2.gnb.st.com [164.129.119.59]) by zeta.dmz-eu.st.com (STMicroelectronics) with ESMTP id EFA4C4C4A7; Thu, 18 Jun 2009 14:25:38 +0000 (GMT) Received: from [164.129.122.46] (gnx2504.gnb.st.com [164.129.122.46]) by mail2.gnb.st.com (MOS 3.8.7a) with ESMTP id DDW77537 (AUTH lyon); Thu, 18 Jun 2009 16:26:06 +0200 (CEST) Message-ID: <4A3A4E62.8030603@st.com> Date: Thu, 18 Jun 2009 14:36:00 -0000 From: Christophe LYON User-Agent: Thunderbird 2.0.0.21 (X11/20090302) MIME-Version: 1.0 To: binutils@sourceware.org, Nick Clifton , Phil Blundell Subject: Re: linker crash in arm stub generation References: <1244740179.21585.119.camel@mill.internal.reciva.com> <4A324BAC.7090702@redhat.com> <4A3255D9.9030906@st.com> <20090612140642.GA31950@caradoc.them.org> <4A32626C.8090407@st.com> <4A3658C4.3000800@st.com> <20090615175935.GA22200@caradoc.them.org> <4A390CF5.3000505@st.com> <20090617162337.GA9315@caradoc.them.org> <4A3A4DEF.5070704@st.com> In-Reply-To: <4A3A4DEF.5070704@st.com> Content-Type: multipart/mixed; boundary="------------010100090506090105040600" X-IsSubscribed: yes Mailing-List: contact binutils-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sourceware.org X-SW-Source: 2009-06/txt/msg00310.txt.bz2 This is a multi-part message in MIME format. --------------010100090506090105040600 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-length: 393 Oops! I forgot to attach the patch, sorry. On 18.06.2009 16:23, Christophe LYON wrote: > Hi, > > After a bit more work, I am able to propose a new patch for this issue. > I have enriched the tests to be sure to check calls inside shared libs > to defined/undefined and ARM/Thumb symbols. > > Checked with arm-none-eabi and arm-linux-gnueabi with no regression. > > Christophe. > > > --------------010100090506090105040600 Content-Type: text/plain; name="pltshared.changelog" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="pltshared.changelog" Content-length: 623 2009-06-18 Christophe Lyon bfd/ * elf32-arm.c (elf32_arm_size_stubs): Use PLT address as destination for defined dynamic symbols when deciding whether to insert a stub or not. (allocate_dynrelocs): Make sure functions are not marked as Thumb when actually accessed through a PLT, even when generating a shared lib. ld/testsuite: * ld-arm/farcall-mixed-app.s: Add new references to check more modes switching. * ld-arm/farcall-mixed-lib1.s: Likewise. * ld-arm/farcall-mixed-app-v5.d: Update expected result. * farcall-mixed-app.d: Likewise. * ld-arm/farcall-mixed-lib.d: Likewise. --------------010100090506090105040600 Content-Type: text/plain; name="pltshared.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="pltshared.patch" Content-length: 10779 Index: bfd/elf32-arm.c =================================================================== RCS file: /cvs/src/src/bfd/elf32-arm.c,v retrieving revision 1.200 diff -u -p -r1.200 elf32-arm.c --- bfd/elf32-arm.c 17 Jun 2009 18:08:34 -0000 1.200 +++ bfd/elf32-arm.c 18 Jun 2009 14:12:33 -0000 @@ -4361,7 +4361,25 @@ elf32_arm_size_stubs (bfd *output_bfd, { sym_sec = hash->root.root.u.def.section; sym_value = hash->root.root.u.def.value; - if (sym_sec->output_section != NULL) + + struct elf32_arm_link_hash_table *globals = + elf32_arm_hash_table (info); + + /* For a destination in a shared library, + use the PLT stub as target address to + decide whether a branch stub is + needed. */ + if (globals->splt != NULL && hash != NULL + && hash->root.plt.offset != (bfd_vma) -1) + { + sym_sec = globals->splt; + sym_value = hash->root.plt.offset; + if (sym_sec->output_section != NULL) + destination = (sym_value + + sym_sec->output_offset + + sym_sec->output_section->vma); + } + else if (sym_sec->output_section != NULL) destination = (sym_value + irela->r_addend + sym_sec->output_offset + sym_sec->output_section->vma); @@ -11273,14 +11291,14 @@ allocate_dynrelocs (struct elf_link_hash { h->root.u.def.section = s; h->root.u.def.value = h->plt.offset; - - /* Make sure the function is not marked as Thumb, in case - it is the target of an ABS32 relocation, which will - point to the PLT entry. */ - if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC) - h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC); } + /* Make sure the function is not marked as Thumb, in case + it is the target of an ABS32 relocation, which will + point to the PLT entry. */ + if (ELF_ST_TYPE (h->type) == STT_ARM_TFUNC) + h->type = ELF_ST_INFO (ELF_ST_BIND (h->type), STT_FUNC); + /* Make room for this entry. */ s->size += htab->plt_entry_size; Index: ld/testsuite/ld-arm/farcall-mixed-app-v5.d =================================================================== RCS file: /cvs/src/src/ld/testsuite/ld-arm/farcall-mixed-app-v5.d,v retrieving revision 1.1 diff -u -p -r1.1 farcall-mixed-app-v5.d --- ld/testsuite/ld-arm/farcall-mixed-app-v5.d 5 Mar 2009 17:28:21 -0000 1.1 +++ ld/testsuite/ld-arm/farcall-mixed-app-v5.d 18 Jun 2009 14:12:36 -0000 @@ -25,11 +25,11 @@ Disassembly of section .text: .*: e1a0c00d mov ip, sp .*: e92dd800 push {fp, ip, lr, pc} .*: eb000008 bl .* <__app_func_veneer> + .*: ebfffff8 bl .* <_start-0xc> + .*: ebfffff4 bl .* <_start-0x18> .*: e89d6800 ldm sp, {fp, sp, lr} .*: e12fff1e bx lr .*: e1a00000 nop \(mov r0,r0\) - .*: e1a00000 nop \(mov r0,r0\) - .*: e1a00000 nop \(mov r0,r0\) .* : .*: b500 push {lr} @@ -49,12 +49,12 @@ Disassembly of section .far_arm: .* : .*: e1a0c00d mov ip, sp .*: e92dd800 push {fp, ip, lr, pc} - .*: eb000008 bl .* <__lib_func1_veneer> + .*: eb00000a bl .* <__lib_func1_veneer> + .*: eb000007 bl .* <__lib_func2_veneer> .*: e89d6800 ldm sp, {fp, sp, lr} .*: e12fff1e bx lr .*: e1a00000 nop \(mov r0,r0\) .*: e1a00000 nop \(mov r0,r0\) - .*: e1a00000 nop \(mov r0,r0\) .* : .*: e12fff1e bx lr @@ -62,8 +62,11 @@ Disassembly of section .far_arm: .*: e1a00000 nop \(mov r0,r0\) .*: e1a00000 nop \(mov r0,r0\) +.* <__lib_func2_veneer>: + .*: e51ff004 ldr pc, \[pc, #-4\] ; 2100034 <__lib_func2_veneer\+0x4> + .*: 00008218 .word 0x00008218 .* <__lib_func1_veneer>: - .*: e51ff004 ldr pc, \[pc, #-4\] ; 2100034 <__lib_func1_veneer\+0x4> + .*: e51ff004 ldr pc, \[pc, #-4\] ; 210003c <__lib_func1_veneer\+0x4> .*: 00008224 .word 0x00008224 Disassembly of section .far_thumb: Index: ld/testsuite/ld-arm/farcall-mixed-app.d =================================================================== RCS file: /cvs/src/src/ld/testsuite/ld-arm/farcall-mixed-app.d,v retrieving revision 1.1 diff -u -p -r1.1 farcall-mixed-app.d --- ld/testsuite/ld-arm/farcall-mixed-app.d 5 Mar 2009 17:28:21 -0000 1.1 +++ ld/testsuite/ld-arm/farcall-mixed-app.d 18 Jun 2009 14:12:36 -0000 @@ -27,11 +27,11 @@ Disassembly of section .text: .*: e1a0c00d mov ip, sp .*: e92dd800 push {fp, ip, lr, pc} .*: eb000008 bl .* <__app_func_veneer> + .*: ebfffff5 bl .* <_start-0x18> + .*: ebfffff1 bl .* <_start-0x24> .*: e89d6800 ldm sp, {fp, sp, lr} .*: e12fff1e bx lr .*: e1a00000 nop \(mov r0,r0\) - .*: e1a00000 nop \(mov r0,r0\) - .*: e1a00000 nop \(mov r0,r0\) .* : .*: b500 push {lr} @@ -51,12 +51,12 @@ Disassembly of section .far_arm: .* : .*: e1a0c00d mov ip, sp .*: e92dd800 push {fp, ip, lr, pc} - .*: eb000008 bl .* <__lib_func1_veneer> + .*: eb00000a bl .* <__lib_func1_veneer> + .*: eb000007 bl .* <__lib_func2_veneer> .*: e89d6800 ldm sp, {fp, sp, lr} .*: e12fff1e bx lr .*: e1a00000 nop \(mov r0,r0\) .*: e1a00000 nop \(mov r0,r0\) - .*: e1a00000 nop \(mov r0,r0\) .* : .*: e12fff1e bx lr @@ -64,8 +64,11 @@ Disassembly of section .far_arm: .*: e1a00000 nop \(mov r0,r0\) .*: e1a00000 nop \(mov r0,r0\) +.* <__lib_func2_veneer>: + .*: e51ff004 ldr pc, \[pc, #-4\] ; 2100034 <__lib_func2_veneer\+0x4> + .*: 0000821c .word 0x0000821c .* <__lib_func1_veneer>: - .*: e51ff004 ldr pc, \[pc, #-4\] ; 2100034 <__lib_func1_veneer\+0x4> + .*: e51ff004 ldr pc, \[pc, #-4\] ; 210003c <__lib_func1_veneer\+0x4> .*: 00008228 .word 0x00008228 Disassembly of section .far_thumb: Index: ld/testsuite/ld-arm/farcall-mixed-app.s =================================================================== RCS file: /cvs/src/src/ld/testsuite/ld-arm/farcall-mixed-app.s,v retrieving revision 1.1 diff -u -p -r1.1 farcall-mixed-app.s --- ld/testsuite/ld-arm/farcall-mixed-app.s 5 Mar 2009 17:28:21 -0000 1.1 +++ ld/testsuite/ld-arm/farcall-mixed-app.s 18 Jun 2009 14:12:36 -0000 @@ -5,6 +5,8 @@ _start: mov ip, sp stmdb sp!, {r11, ip, lr, pc} bl app_func + bl lib_func1 + bl lib_func2 ldmia sp, {r11, sp, lr} bx lr @@ -30,6 +32,7 @@ app_func: mov ip, sp stmdb sp!, {r11, ip, lr, pc} bl lib_func1 + bl lib_func2 ldmia sp, {r11, sp, lr} bx lr Index: ld/testsuite/ld-arm/farcall-mixed-lib.d =================================================================== RCS file: /cvs/src/src/ld/testsuite/ld-arm/farcall-mixed-lib.d,v retrieving revision 1.3 diff -u -p -r1.3 farcall-mixed-lib.d --- ld/testsuite/ld-arm/farcall-mixed-lib.d 21 Apr 2009 22:05:04 -0000 1.3 +++ ld/testsuite/ld-arm/farcall-mixed-lib.d 18 Jun 2009 14:12:36 -0000 @@ -17,6 +17,13 @@ Disassembly of section .plt: .*: e28fc6.* add ip, pc, #.* ; 0x.* .*: e28cca.* add ip, ip, #.* ; 0x.* .*: e5bcf.* ldr pc, \[ip, #.*\]! + .*: e28fc6.* add ip, pc, #.* ; 0x.* + .*: e28cca.* add ip, ip, #.* ; 0x.* + .*: e5bcf.* ldr pc, \[ip, #.*\]! + .*: e28fc6.* add ip, pc, #.* ; 0x.* + .*: e28cca.* add ip, ip, #.* ; 0x.* + .*: e5bcf.* ldr pc, \[ip, #.*\]! + Disassembly of section .text: .* : @@ -24,46 +31,62 @@ Disassembly of section .text: .*: e92dd800 push {fp, ip, lr, pc} .*: ebfffff. bl .* .*: ebfffff. bl .* + .*: ebfffff. bl .* + .*: ebfffff. bl .* .*: e89d6800 ldm sp, {fp, sp, lr} .*: e12fff1e bx lr ... - .*: e1a00000 .word 0xe1a00000 - .*: e1a00000 .word 0xe1a00000 .* : - .*: f000 e806 blx 1000300 <__app_func_from_thumb> - .*: f000 e80a blx 100030c <__app_func_weak_from_thumb> + .*: f000 e80e blx 1000350 <__app_func_from_thumb> + .*: f000 e818 blx 1000368 <__app_func_weak_from_thumb> + .*: f000 e810 blx 100035c <__lib_func3_from_thumb> + .*: f000 e81a blx 1000374 <__lib_func4_from_thumb> .*: 4770 bx lr .*: 46c0 nop \(mov r8, r8\) .*: 46c0 nop \(mov r8, r8\) .*: 46c0 nop \(mov r8, r8\) + .*: 46c0 nop \(mov r8, r8\) + .*: 46c0 nop \(mov r8, r8\) + .*: 46c0 nop \(mov r8, r8\) + .*: 46c0 nop \(mov r8, r8\) .* <__app_func_from_thumb>: - .*: e59fc000 ldr ip, \[pc, #0\] ; 1000308 <__app_func_from_thumb\+0x8> + .*: e59fc000 ldr ip, \[pc, #0\] ; 1000358 <__app_func_from_thumb\+0x8> + .*: e08ff00c add pc, pc, ip + .*: feffff84 .word 0xfeffff84 + +.* <__lib_func3_from_thumb>: + .*: e59fc000 ldr ip, \[pc, #0\] ; 1000364 <__lib_func3_from_thumb\+0x8> .*: e08ff00c add pc, pc, ip - .*: feffffa8 .word 0xfeffffa8 + .*: feffff90 .word 0xfeffff90 .* <__app_func_weak_from_thumb>: - .*: e59fc000 ldr ip, \[pc, #0\] ; 1000314 <__app_func_weak_from_thumb\+0x8> + .*: e59fc000 ldr ip, \[pc, #0\] ; 1000370 <__app_func_weak_from_thumb\+0x8> + .*: e08ff00c add pc, pc, ip + .*: feffff78 .word 0xfeffff78 + +.* <__lib_func4_from_thumb>: + .*: e59fc000 ldr ip, \[pc, #0\] ; 100037c <__lib_func4_from_thumb\+0x8> .*: e08ff00c add pc, pc, ip - .*: feffffa8 .word 0xfeffffa8 + .*: feffff84 .word 0xfeffff84 ... .* : - .*: f000 e80c blx 200033c <__app_func_from_thumb> - .*: f000 e804 blx 2000330 <__app_func_weak_from_thumb> + .*: f000 e80c blx 20003ac <__app_func_from_thumb> + .*: f000 e804 blx 20003a0 <__app_func_weak_from_thumb> .*: 4770 bx lr .*: 46c0 nop \(mov r8, r8\) .*: 46c0 nop \(mov r8, r8\) .*: 46c0 nop \(mov r8, r8\) .* <__app_func_weak_from_thumb>: - .*: e59fc000 ldr ip, \[pc, #0\] ; 2000338 <__app_func_weak_from_thumb\+0x8> + .*: e59fc000 ldr ip, \[pc, #0\] ; 20003a8 <__app_func_weak_from_thumb\+0x8> .*: e08ff00c add pc, pc, ip - .*: fdffff84 .word 0xfdffff84 + .*: fdffff40 .word 0xfdffff40 .* <__app_func_from_thumb>: - .*: e59fc000 ldr ip, \[pc, #0\] ; 2000344 <__app_func_from_thumb\+0x8> + .*: e59fc000 ldr ip, \[pc, #0\] ; 20003b4 <__app_func_from_thumb\+0x8> .*: e08ff00c add pc, pc, ip - .*: fdffff6c .word 0xfdffff6c + .*: fdffff28 .word 0xfdffff28 ... Index: ld/testsuite/ld-arm/farcall-mixed-lib1.s =================================================================== RCS file: /cvs/src/src/ld/testsuite/ld-arm/farcall-mixed-lib1.s,v retrieving revision 1.1 diff -u -p -r1.1 farcall-mixed-lib1.s --- ld/testsuite/ld-arm/farcall-mixed-lib1.s 17 Apr 2009 13:04:41 -0000 1.1 +++ ld/testsuite/ld-arm/farcall-mixed-lib1.s 18 Jun 2009 14:12:36 -0000 @@ -14,6 +14,8 @@ lib_func1: bl app_func .weak app_func_weak bl app_func_weak + bl lib_func3 + bl lib_func4 ldmia sp, {r11, sp, lr} bx lr .size lib_func1, . - lib_func1 @@ -27,5 +29,7 @@ lib_func1: lib_func2: bl app_func bl app_func_weak + bl lib_func3 + bl lib_func4 bx lr .size lib_func2, . - lib_func2 --------------010100090506090105040600--