[Bug ld/12131] New: Using R_ARM_MOV[WT]_PREL to load address of _GLOBAL_OFFSET_TABLE_

2010-10-18 Thread stephen.clarke at st dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=12131

   Summary: Using R_ARM_MOV[WT]_PREL to load address of
_GLOBAL_OFFSET_TABLE_
   Product: binutils
   Version: 2.20
Status: NEW
  Severity: normal
  Priority: P2
 Component: ld
AssignedTo: unassig...@sources.redhat.com
ReportedBy: stephen.cla...@st.com


I'm seeing a problem with ARM GOT relocations, specifically
when the .got.plt section is not placed at the start of its output
section.  I have reproduced the problem with the binutils.weekly.bz2
tarball snapshot dated Oct 12 2010.

Here's my test example (also in the attachment):

$ cat gottest.s
.text
_start:
.global _start
movw r0, :lower16:_GLOBAL_OFFSET_TABLE_-(here+8)
movt r0, :upper16:_GLOBAL_OFFSET_TABLE_-(here+8)
ldr  r1, littab
here:
littab:
.word _GLOBAL_OFFSET_TABLE_-(here+8)

.section .jcr, "aw"
.space 1000

$ cat gottest.ld
OUTPUT_FORMAT("elf32-littlearm", "elf32-bigarm",
  "elf32-littlearm")
OUTPUT_ARCH(arm)
ENTRY(_start)
SECTIONS
{
 .text   :
 {
*(.text)
*(.glue_7t) *(.glue_7) *(.vfp11_veneer)
 }  =0
  .data   : ALIGN (8)
  {
KEEP (*(.jcr))
*(.got.plt) *(.got)
*(.data)
  }
}

I build like this:
$ arm-none-eabi-as -o gottest.o gottest.s
$ arm-none-eabi-ld --script gottest.ld gottest.o

My expectation is that the code will load the same value
into r0 and r1, but here is the disassembly:
$ arm-none-eabi-objdump -d a.out

a.out: file format elf32-littlearm


Disassembly of section .text:

 <_start>:
   0:   e30003e4movwr0, #996; 0x3e4
   4:   e340movtr0, #0
   8:   e51f1004ldr r1, [pc, #-4]   ; c 

000c :
   c:   fffc.word   0xfffc


It seems that r0 is being loaded with 996, and r1 is loaded
with -4.  The difference (1000) is exactly the size of the .jcr
section I placed at the start of .data.
Looking at the resolved symbol values:
$ arm-none-eabi-nm a.out 
03f8 d _GLOBAL_OFFSET_TABLE_
 T _start
000c t here
000c t littab

it seems the correct value should be 0x3f8-(0xc+0x8) = 0x3e4 = 996, i.e. the
movw/movt sequence is consistent with the symbol values.
However, the movw/movt sequence does not work when I use it in my
compiler in combination with R_ARM_GOT32 to get the address of a GOT entry,
whereas the ldr instruction does work.

Everything is fine and consistent iff the .got sections are
placed right at the start of the .data output section (e.g. if the
.jcr section has size zero).  But as soon as there is something before
them, I get problems.

Steve.

-- 
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
http://lists.gnu.org/mailman/listinfo/bug-binutils


[Bug ld/12131] Using R_ARM_MOV[WT]_PREL to load address of _GLOBAL_OFFSET_TABLE_

2010-10-18 Thread stephen.clarke at st dot com
http://sourceware.org/bugzilla/show_bug.cgi?id=12131

--- Comment #1 from Stephen Clarke  2010-10-18 
14:32:31 UTC ---
Created attachment 5066
  --> http://sourceware.org/bugzilla/attachment.cgi?id=5066
Test example

-- 
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
http://lists.gnu.org/mailman/listinfo/bug-binutils