[Bug ld/15302] Branching to linker script symbol is resolved to improperly BLX instruction for cortex-m3

2013-09-12 Thread terry.guo at arm dot com
https://sourceware.org/bugzilla/show_bug.cgi?id=15302

Terry Guo terry.guo at arm dot com changed:

   What|Removed |Added

 Status|REOPENED|RESOLVED
 Resolution|--- |FIXED

--- Comment #9 from Terry Guo terry.guo at arm dot com ---
Fixed by a updated patch at
https://sourceware.org/ml/binutils/2013-07/msg00094.html.

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

___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/15302] Branching to linker script symbol is resolved to improperly BLX instruction for cortex-m3

2013-08-08 Thread info at fagus dot ch
http://sourceware.org/bugzilla/show_bug.cgi?id=15302

peter info at fagus dot ch changed:

   What|Removed |Added

 CC||info at fagus dot ch

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

___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/15302] Branching to linker script symbol is resolved to improperly BLX instruction for cortex-m3

2013-06-28 Thread cvs-commit at gcc dot gnu.org
http://sourceware.org/bugzilla/show_bug.cgi?id=15302

--- Comment #8 from cvs-commit at gcc dot gnu.org cvs-commit at gcc dot 
gnu.org ---
CVSROOT:/cvs/src
Module name:src
Changes by:ni...@sourceware.org2013-06-28 12:22:42

Modified files:
bfd: ChangeLog elf32-arm.c 

Log message:
PR ld/15302
* elf32-arm.c (allocate_dynrelocs_for_symbol): Revert previous patch.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=srcr1=1.6088r2=1.6089
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf32-arm.c.diff?cvsroot=srcr1=1.318r2=1.319

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

___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/15302] Branching to linker script symbol is resolved to improperly BLX instruction for cortex-m3

2013-06-20 Thread terry.guo at arm dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=15302

Terry Guo terry.guo at arm dot com changed:

   What|Removed |Added

 Status|RESOLVED|REOPENED
   Last reconfirmed||2013-06-21
 Resolution|FIXED   |---
 Ever confirmed|0   |1

--- Comment #7 from Terry Guo terry.guo at arm dot com ---
I am sorry that I have to reopen it. The proposed patch will cause below issue. 

In the below concrete case, the __init_array_start is allocated at address
0x11a40 actually. But any relocations using address of __init_array_start will
be resolved to use address 0x11a41 by linker, thus the subsequential deference
on __init_array_start is a deference on wrong address (0x11a41). 

This is because the proposed patch set ST_BRANCH_TO_THUMB to the symbol
__init_array_start, then the last bit of its address is set by the linker
function elf32_arm_swap_symbol_out.

To reproduce this issue, an ARM baremetal toolchain using Newlib as C library
is needed. Then use below command to build a project with empty main function:
arm-none-eabi-gcc -mthumb -mcpu=cortex-m3 -O2 -lc -lrdimon -specs=rdimon.specs
test.c -o test.out -Wl,-verbose -Wl,-Map=test.map

Then run test.out on QEMU, a Segmentation falut will be reported.
qemu-system-arm -cpu cortex-m3 -nographic -monitor null -serial null
-semihosting -kernel ./test.out

This QEMU segmentation fault is caused by deference of __init_array_start in
function __libc_init_array.

Here are some investigations:
Disassemble the test.out with command arm-none-eabi-objdump -D test.out and
we will see:

Disassembly of section .init_array:

00011a40 __init_array_start:
   11a40:   802dandeq   r8, r0, sp, lsr #32


The __init_array_start is allocated at address 0x11a40 actually.

Meanwhile the command arm-none-eabi-readelf -s test.out, we will get symbol
table:

   222: 00011a41 0 FUNCLOCAL  DEFAULT7 __init_array_start

Thus any instructions using __init_array_start will be resolved to 0x11a41
instead of 0x11a40.

movwr5, #:lower16:__init_array_start
movtr5, #:upper16:__init_array_start
ldr r3, [r5, #4]!
blx r3

in the above case, the r5 will get wrong value 0x11a41, then r3 will get wrong
value, finally the blx will cause the fault.

Here are some background on Newlib:

In Newlib init.c we have code:

extern void (*__init_array_start []) (void) __attribute__((weak));
extern void (*__init_array_end []) (void) __attribute__((weak));

void
__libc_init_array (void)
{
  size_t count;
  size_t i;



  count = __init_array_end - __init_array_start;
  for (i = 0; i  count; i++)
__init_array_start[i] ();
}

Both __init_array_start and __init_array_end are defined in linker script as:

  .init_array :
  {
PROVIDE_HIDDEN (__init_array_start = .);
KEEP (*(SORT(.init_array.*)))
KEEP (*(.init_array ))
PROVIDE_HIDDEN (__init_array_end = .);
  }

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

___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/15302] Branching to linker script symbol is resolved to improperly BLX instruction for cortex-m3

2013-06-13 Thread cvs-commit at gcc dot gnu.org
http://sourceware.org/bugzilla/show_bug.cgi?id=15302

--- Comment #5 from cvs-commit at gcc dot gnu.org cvs-commit at gcc dot 
gnu.org ---
CVSROOT:/cvs/src
Module name:src
Changes by:ni...@sourceware.org2013-06-13 12:36:02

Modified files:
bfd: ChangeLog elf32-arm.c 
ld/testsuite   : ChangeLog 
ld/testsuite/ld-arm: arm-elf.exp 
Added files:
ld/testsuite/ld-arm: branch-lks-sym.ld thumb-b-lks-sym.d 
 thumb-b-lks-sym.s thumb-bl-lks-sym.d 
 thumb-bl-lks-sym.s 

Log message:
PR ld/15302
* elf32-arm.c (allocate_dynrelocs_for_symbol): Transform
ST_BRANCH_TO_ARM into ST_BRANCH_TO_THUMB if the target only
supports thumb instructions.

PR ld/15302
* ld-arm/branch-lks-sym.ld: New script.
* ld-arm/thumb-b-lks-sym.s: New test.
* ld-arm/thumb-b-lks-sym.d: Expected disassembly.
* ld-arm/thumb-bl-lks-sym.s: New test.
* ld-arm/thumb-bl-lks-sym.d: Expected disassembly.
* ld-arm/arm-elf.exp: Run the new tests.

Patches:
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/ChangeLog.diff?cvsroot=srcr1=1.6073r2=1.6074
http://sourceware.org/cgi-bin/cvsweb.cgi/src/bfd/elf32-arm.c.diff?cvsroot=srcr1=1.317r2=1.318
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=srcr1=1.1726r2=1.1727
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-arm/branch-lks-sym.ld.diff?cvsroot=srcr1=NONEr2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-arm/thumb-b-lks-sym.d.diff?cvsroot=srcr1=NONEr2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-arm/thumb-b-lks-sym.s.diff?cvsroot=srcr1=NONEr2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-arm/thumb-bl-lks-sym.d.diff?cvsroot=srcr1=NONEr2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-arm/thumb-bl-lks-sym.s.diff?cvsroot=srcr1=NONEr2=1.1
http://sourceware.org/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-arm/arm-elf.exp.diff?cvsroot=srcr1=1.103r2=1.104

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

___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/15302] Branching to linker script symbol is resolved to improperly BLX instruction for cortex-m3

2013-06-13 Thread nickc at redhat dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=15302

Nick Clifton nickc at redhat dot com changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution|--- |FIXED

--- Comment #6 from Nick Clifton nickc at redhat dot com ---
Hi Terry,

  Thanks for the patch - I liked it, so I have applied it!  I made one small
change - there was no need for the globals local variable as htab already
contained the same pointer.

Cheers
  Nick

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

___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/15302] Branching to linker script symbol is resolved to improperly BLX instruction for cortex-m3

2013-06-12 Thread terry.guo at arm dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=15302

--- Comment #4 from Terry Guo terry.guo at arm dot com ---
Created attachment 7076
  -- http://sourceware.org/bugzilla/attachment.cgi?id=7076action=edit
A proposal to fix this bug

Hello Nick and Pavel,

I am inspired by Nick's patch and managed to come up with this one. It did
fixed this issue without causing any new failures in regress test. Can you guys
please help to check it? Is this patch good enough to be sent to Binutils
mailing list for review?

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

___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/15302] Branching to linker script symbol is resolved to improperly BLX instruction for cortex-m3

2013-06-12 Thread terry.guo at arm dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=15302

Terry Guo terry.guo at arm dot com changed:

   What|Removed |Added

 CC||nickc at redhat dot com

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

___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/15302] Branching to linker script symbol is resolved to improperly BLX instruction for cortex-m3

2013-06-04 Thread terry.guo at arm dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=15302

--- Comment #3 from Terry Guo terry.guo at arm dot com ---
(In reply to Nick Clifton from comment #1)
 Created attachment 6968 [details]
 Do not enable blx use on thumb-only architectures.
 
 Hi Terry,
 
   Please could you try out the uploaded patch and let me know if it works
 for you.
 
 Cheers
   Nick

Apologize for my slow response. With your patch I got code like:

terguo01@terry-pc01:case$ ../install-native/bin/arm-none-eabi-objdump -d a.out 

a.out: file format elf32-littlearm


Disassembly of section .text:

 main:
   0:b580  push{r7, lr}
   2:af00  addr7, sp, #0
   4:f000 f804 bl10 __extFunc_from_thumb
   8:bd80  pop{r7, pc}
   a:bf00  nop
   c:  movsr0, r0
...

0010 __extFunc_from_thumb:
  10:4778  bxpc
  12:46c0  nop; (mov r8, r8)
  14:ea0003f9 b1000 __extFunc_from_thumb+0xff0
terguo01@terry-pc01:case$ 

It's same with Pavel's issue. Can you please continue to look into it?

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

___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/15302] Branching to linker script symbol is resolved to improperly BLX instruction for cortex-m3

2013-05-20 Thread pavel.kral at omsquare dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=15302



Pavel Král pavel.kral at omsquare dot com changed:



   What|Removed |Added



 Status|NEW |UNCONFIRMED

 CC||pavel.kral at omsquare dot

   ||com

 Ever Confirmed|1   |0



--- Comment #2 from Pavel Král pavel.kral at omsquare dot com 2013-0
5-20 21:57:34 UTC ---

My use case is similar. I just did smoke test and there is another issue. T
est

code is executed from RAM (0x1000) where it try to call firmware stored
 at

flash (in this example function at 0x3779) 



BLX instruction was replaced by BL, but at immediate address is generated

thumb-ARM switch instruction BX PC which cause hard fault



1a94:f000 f898 bl1bc8 ___xxx_from_thumb # ok BLX repl
aced

by BL

...

___xxx_from_thumb():

1bc8:4778  bxpc  ; hard fault

1bca:46c0  nop; 

1bcc:e51ff004 ldrpc, [pc, #-4]; 1bd0

_farAway_from_thumb+0x8

1bd0:3779 andeqr3, r0, r9, ror r7



ld just generate these __from_thumb stubs which is not what we wont at Cort
ex

Ms.



-- 

Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email

--- You are receiving this mail because: ---

You are on the CC list for the bug.

___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/15302] Branching to linker script symbol is resolved to improperly BLX instruction for cortex-m3

2013-04-05 Thread nickc at redhat dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=15302

--- Comment #1 from Nick Clifton nickc at redhat dot com 2013-04-05 17:04:22 
UTC ---
Created attachment 6968
  -- http://sourceware.org/bugzilla/attachment.cgi?id=6968
Do not enable blx use on thumb-only architectures.

Hi Terry,

  Please could you try out the uploaded patch and let me know if it works for
you.

Cheers
  Nick

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
--- You are receiving this mail because: ---
You are on the CC list for the bug.

___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils