Committed: fix CRIS copy relocs. ARM heads-up!
Hans-Peter Nilsson
hans-peter.nilsson@axis.com
Mon Jan 19 17:38:00 GMT 2009
No R_CRIS_COPY was generated at all, instead a relocation in an
executable against a weak alias from a shared library got 0!
Thankfully quite distinctive. Regarding the value of the
relocation, it's not obvious that the relocation must be against
the *strong* alias; see
<http://sourceware.org/ml/binutils/2007-07/msg00301.html>.
While investigating how the relocation was lost (it had once
worked), I noticed that arm-linux gets the relocation value
wrong: their relocation is against the weak alias. That is, if
the ld command lines below are sufficient, no extra options
needed for arm-linux.
How about I put the following reasonably generic code in the
generic *-*-linux* ld testsuite and make sure e.g. readelf
output matches a ".*COPY.* ystrongy"? Assembles and links for
arm-linux (except as mentioned, the COPY relocation is wrong),
native i686-linux, m68k-linux, cris-linux. Note that the
reference must be from a read-only section or else ix86 emits an
ordinary relocation.
dso.s:
.global ystrongy
.section .rodata
.p2align 2
.LC0:
.string "holy mackerel"
.section .data.rel.local,"aw",%progbits
.p2align 2
.type ystrongy, %object
.size ystrongy, 4
ystrongy:
.long .LC0
.weak xweakx
.set xweakx,ystrongy
executable.s:
.globl x
.section .rodata
.p2align 2
.type x, %object
.size x, 4
x:
.long xweakx
.text
.p2align 2
.global _start
.type _start, %function
_start:
nop
.size _start, .-_start
ld -o libdso.o -shared dso.o
ld -o exe executable.o libdso.so
readelf -r | egrep ".*COPY.* ystrongy"
(figuratively speaking).
Anyway, the following is committed.
Note the spurious-symbol adjustment for __expobj2 below. I
can't tell why that, but not __expfn2, is emitted as an
undefined symbol, but I guess it's slightly more correct that it
be emitted as a non-weak reference.
ld/testsuite:
* ld-cris/expdref3.s, ld-cris/expdref4.s, ld-cris/weakref3.d,
ld-cris/weakref4.d: New tests.
* ld-cris/libdso-15b.d: Adjust for recent weakref fix.
bfd:
* elf32-cris.c (elf_cris_copy_indirect_symbol): For other symbol
types than bfd_link_hash_indirect, before early return, call
_bfd_elf_link_hash_copy_indirect.
Index: elf32-cris.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-cris.c,v
retrieving revision 1.97
diff -p -u -r1.97 elf32-cris.c
--- elf32-cris.c 7 Jan 2009 03:28:45 -0000 1.97
+++ elf32-cris.c 19 Jan 2009 17:27:46 -0000
@@ -3055,7 +3055,11 @@ elf_cris_copy_indirect_symbol (struct bf
/* Only indirect symbols are replaced; we're not interested in
updating any of EIND's fields for other symbols. */
if (eind->root.root.type != bfd_link_hash_indirect)
- return;
+ {
+ /* Still, we need to copy flags for e.g. weak definitions. */
+ _bfd_elf_link_hash_copy_indirect (info, dir, ind);
+ return;
+ }
BFD_ASSERT (edir->pcrel_relocs_copied == NULL);
BFD_ASSERT (edir->gotplt_offset == 0 || eind->gotplt_offset == 0);
Index: ld-cris/expdref3.s
===================================================================
RCS file: ld-cris/expdref3.s
diff -N ld-cris/expdref3.s
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld-cris/expdref3.s 19 Jan 2009 17:26:45 -0000
@@ -0,0 +1,9 @@
+ .text
+ .global x
+ .type x,@function
+x:
+ move.d expobj2,$r10
+ move.d expfn2,$r10
+.Lfe1:
+ .size x,.Lfe1-x
+
Index: ld-cris/expdref4.s
===================================================================
RCS file: ld-cris/expdref4.s
diff -N ld-cris/expdref4.s
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld-cris/expdref4.s 19 Jan 2009 17:26:45 -0000
@@ -0,0 +1,7 @@
+ .data
+ .global x
+ .type x,@object
+x:
+ .dword expobj2
+.Lfe1:
+ .size x,.Lfe1-x
Index: ld-cris/libdso-15b.d
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-cris/libdso-15b.d,v
retrieving revision 1.1
diff -p -u -r1.1 libdso-15b.d
--- ld-cris/libdso-15b.d 23 Dec 2008 11:45:25 -0000 1.1
+++ ld-cris/libdso-15b.d 19 Jan 2009 17:26:45 -0000
@@ -9,12 +9,14 @@
# definition is also in the other DSO.
# There was a bug causing GOT markups to be during symbol handling,
# with a newly added assertion failure and a reloc turned R_CRIS_NONE.
+# The dynamic __expobj2 entry is unused and seems spurious, or there
+# should at least be a similar __expfn2 reference
.*: file format elf32-cris
DYNAMIC SYMBOL TABLE:
#...
-0+ w[ ]+DO \*UND\*[ ]+0+ TST3[ ]+__expobj2
+0+[ ]+DO \*UND\*[ ]+0+ TST3[ ]+__expobj2
#...
0+[ ]+DO \*UND\*[ ]+0+ TST3[ ]+expobj2
0+[ ]+DF \*UND\*[ ]+0+ TST3[ ]+expfn2
Index: ld-cris/weakref3.d
===================================================================
RCS file: ld-cris/weakref3.d
diff -N ld-cris/weakref3.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld-cris/weakref3.d 19 Jan 2009 17:26:45 -0000
@@ -0,0 +1,36 @@
+#source: start1.s
+#source: expdref3.s
+#as: --no-underscore --em=criself
+#ld: -m crislinux
+#ld_after_inputfiles: tmpdir/libdso-15.so
+#readelf: -a -x 10
+
+# Like libdso-15b.d, but referencing the weak symbol and function from
+# a program. At some time we broke emitting a copy reloc for the
+# object, instead yielding NULL.
+
+#...
+ \[[0-9]+\] .got PROGBITS 0+82314 000314 000010 04 WA 0 0 4
+#...
+ \[[0-9]+\] .bss NOBITS 0+82324 .*
+#...
+Relocation section '.rela.dyn' at offset 0x... contains 1 entries:
+ Offset Info Type Sym.Value Sym. Name \+ Addend
+00082324 00000109 R_CRIS_COPY 00082324 __expobj2 \+ 0
+
+Relocation section '.rela.plt' at offset 0x... contains 1 entries:
+ Offset Info Type Sym.Value Sym. Name \+ Addend
+00082320 0000030b R_CRIS_JUMP_SLOT 00080238 expfn2 \+ 0
+
+There are no unwind sections in this file.
+
+Symbol table '.dynsym' contains . entries:
+#...
+ .: 00082324 4 OBJECT GLOBAL DEFAULT 13 __expobj2@TST3 \(2\)
+#...
+ .: 00080238 0 FUNC GLOBAL DEFAULT UND expfn2@TST3 \(2\)
+#...
+Symbol table '.symtab' contains .. entries:
+#...
+Hex dump of section '\.text':
+ 0x0008024c 41b20000 6fae2423 08006fae 38020800 .*
Index: ld-cris/weakref4.d
===================================================================
RCS file: ld-cris/weakref4.d
diff -N ld-cris/weakref4.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ ld-cris/weakref4.d 19 Jan 2009 17:26:45 -0000
@@ -0,0 +1,32 @@
+#source: start1.s
+#source: expdref4.s
+#as: --no-underscore --em=criself
+#ld: -m crislinux
+#ld_after_inputfiles: tmpdir/libdso-15.so
+#readelf: -a -x 11
+
+# Like weakref3.d, but just the expobj2 referenced from .data. We
+# should avoid a copy reloc (instead emitting a R_CRIS_GLOB_DAT or
+# R_CRIS_32 against the weak symbol), but for the time being, make
+# sure we get a valid reloc.
+
+#...
+ \[[0-9]+\] .data PROGBITS 0+822a4 0002a4 000004 00 WA 0 0 1
+#...
+ \[[0-9]+\] .bss NOBITS 0+822a8 .*
+#...
+Relocation section '.rela.dyn' at offset 0x... contains 1 entries:
+#...
+000822a8 00000109 R_CRIS_COPY 000822a8 __expobj2 \+ 0
+
+There are no unwind sections in this file.
+
+Symbol table '.dynsym' contains . entries:
+#...
+ .: 000822a8 4 OBJECT GLOBAL DEFAULT 12 __expobj2@TST3 \(2\)
+#...
+Symbol table '.symtab' contains .. entries:
+#...
+Hex dump of section '.data':
+ 0x000822a4 a8220800 .*
+
brgds, H-P
More information about the Binutils
mailing list