Bug 5552 - Wrong data address after linking
Summary: Wrong data address after linking
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.18
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-01-08 13:16 UTC by Markus Heigl
Modified: 2008-01-09 12:29 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: fr30-unknown-elf
Build:
Last reconfirmed:


Attachments
testcase (126 bytes, text/plain)
2008-01-08 13:17 UTC, Markus Heigl
Details
assembler output (231 bytes, application/octet-stream)
2008-01-08 13:18 UTC, Markus Heigl
Details
linker output (230 bytes, application/octet-stream)
2008-01-08 13:18 UTC, Markus Heigl
Details
Set partial_inplace to FALSE for FR30 relocs (585 bytes, patch)
2008-01-09 12:27 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Heigl 2008-01-08 13:16:04 UTC
While porting Linux to the Fujitsu RISC I observed that pointers within
a structure were not initialized with the right addresses.
After some investigation it boiled down to the linker.

Following testcase shows the problem.

foo.s:
	.globl foo
	.data
	.p2align 2
	.type	foo, @object
	.size	foo, 8
foo:
	.word	286331153
	.word	foo+4
	.word	foo+4
	.word	-1
	
	.globl bar
	.data
	.p2align 2
	.type	bar, @object
	.size	bar, 40
bar:
	.word	286331153
	.word	bar+4
	.word	bar+4
	.word	-1
	
assembled with:
bash-2.05b$ fr30-elf-as foo.s -o foo.o

and linked with:
bash-2.05b$ fr30-elf-ld -t -stats foo.o
fr30-elf-ld: mode elf32fr30
foo.o
fr30-elf-ld: warning: cannot find entry symbol _start; defaulting to 00010000


What I would expect is: a2.out
00001000: 11111111	foo
00001004: 00010004
00001008: 00010004
0000100c: ffffffff
00001010: 11111111	bar
00001014: 00010014	<
00001018: 00010014	<
0000101c: ffffffff

But what I get is: a.out
00001000: 11111111	foo
00001004: 00010004
00001008: 00010004
0000100c: ffffffff
00001010: 11111111	bar
00001014: 00010024	<
00001018: 00010024	<
0000101c: ffffffff
Comment 1 Markus Heigl 2008-01-08 13:17:24 UTC
Created attachment 2183 [details]
testcase
Comment 2 Markus Heigl 2008-01-08 13:18:04 UTC
Created attachment 2184 [details]
assembler output
Comment 3 Markus Heigl 2008-01-08 13:18:58 UTC
Created attachment 2185 [details]
linker output
Comment 4 Markus Heigl 2008-01-08 13:44:12 UTC
For a2.out I removed h->root.u.def.value

*** /fme/users/mhaigl/essen-gcc/binutils-2.18/bfd/elf-bfd.h     2008-01-08 
14:36:57.000000000 +0100
--- /fme/users/mhaigl/cross/binutils-2.18/bfd/elf-bfd.h 2007-08-06 
21:59:22.000000000 +0200
*************** extern bfd_boolean _sh_elf_set_mach_from
*** 2096,2102 ****
               library.  */                                             \
            unresolved_reloc = TRUE;                                    \
          else                                                          \
!           relocation = (                              \
                          + sec->output_section->vma                    \
                          + sec->output_offset);                        \
        }                                                               \
--- 2096,2102 ----
               library.  */                                             \
            unresolved_reloc = TRUE;                                    \
          else                                                          \
!           relocation = (h->root.u.def.value                           \
                          + sec->output_section->vma                    \
                          + sec->output_offset);                        \
        }                                                               \

This helped to produce the right adresses for the testcase, but altough
I do not know much about the linker I am pretty sure that this will break
almost everything else. So this is only a hint where it goes wrong.
Comment 5 Andreas Schwab 2008-01-08 13:55:21 UTC
The assembler output is already broken.

foo.o:     file format elf32-fr30

RELOCATION RECORDS FOR [.data]:
OFFSET   TYPE              VALUE 
00000004 R_FR30_32         foo+0x00000004
00000008 R_FR30_32         foo+0x00000004
00000014 R_FR30_32         bar+0x00000014
00000018 R_FR30_32         bar+0x00000014
                                       ^^
Comment 6 Markus Heigl 2008-01-08 17:17:49 UTC
So should this one be moved to gas or should I open 
a new one and we close this bug?
Comment 7 Nick Clifton 2008-01-09 12:27:12 UTC
Created attachment 2191 [details]
Set partial_inplace to FALSE for FR30 relocs
Comment 8 Nick Clifton 2008-01-09 12:29:30 UTC
Hi Markus,

  This was a problem with the reloc descriptions in the elf32-fr30.c file - they
had the partial_inplace field set to TRUE which is the wrong thing to do for
ports which use RELA type relocs.  I have applied the uploaded patch to fix this.

Cheers
  Nick

bfd/ChangeLog
	PR gas/5552
	* elf32-fr30.c (fr30_elf_howto_table): Set partial_inplace field
	to FALSE for all relocs.