This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RFA: run_dump_test: ld_after_inputfiles. Committed: add elf_cris_copy_indirect_symbols


I've totally missed elf_backend_copy_indirect_symbol, and now I
wonder why it ever worked before (with older glibc) because
there's been a elf_cris_link_hash_entry as long as that function
has been there, even though the struct contained a lot less
until TLS...  A heisenbug?  You won't notice until you link
something that makes use of versioned symbols, like glibc.  The
test-case will trig the newly added BFD_ASSERT in
elf_cris_got_elt_size, and if that's not there, R_CRIS_NONE
relocs will be emitted with the intended contents overwriting
or be overwritten by the reloc of the true GOT offset assignee.

You also won't notice if the DSO you link against is specified
*before* input files on the ld command line, whereas the usage
that uncovered this bug was when the DSO was specified *after*
input files, the more common usage.  The ld testsuite lacked a
way to test that, through my favorite ld-testsuite function.

Here's a patch to add a feature to run_dump_test so you can specify
options (like previously generated DSOs) after input files.  Tested
using the attached test-case; unknown run_dump_test "options" cause
errors, so no use testing on all targets in sight.  (Tests in the
ld-cris testsuite are sorted in alphanumeric order and tests matching
*dso-*.d are split out and run first and generate DSOs named
*dso-*.so.)

Ok to commit the lib/ld-lib.exp patch?

The elf32-cris change is committed.  Will commit
ld-cris/libdso-1c.d if/when run_dump_test is updated.

ld/testsuite:
	* lib/ld-lib.exp (run_dump_test): New option ld_after_inputfiles.
	* ld-cris/libdso-1c.d: New test.

bfd:
	* elf32-cris.c (elf_cris_copy_indirect_symbol): New function.
	(elf_backend_copy_indirect_symbol): Define to above.

Index: lib/ld-lib.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/lib/ld-lib.exp,v
retrieving revision 1.55
diff -p -u -r1.55 ld-lib.exp
--- lib/ld-lib.exp	20 Sep 2008 08:42:53 -0000	1.55
+++ lib/ld-lib.exp	15 Dec 2008 01:01:12 -0000
@@ -564,6 +564,9 @@ proc simple_diff { file_1 file_2 } {
 #       Link assembled files using FLAGS, in the order of the "source"
 #       directives, when using multiple files.
 #
+#   ld_after_inputfiles: FLAGS
+#       Similar to "ld", but put after all input files.
+#
 #   objcopy_linked_file: FLAGS
 #	Run objcopy on the linked file with the specified flags.
 #	This lets you transform the linked file using objcopy, before the
@@ -650,6 +653,7 @@ proc run_dump_test { name } {
     set run_objcopy 0
     set opts(as) {}
     set opts(ld) {}
+    set opts(ld_after_inputfiles) {}
     set opts(xfail) {}
     set opts(target) {}
     set opts(notarget) {}
@@ -842,7 +846,7 @@ proc run_dump_test { name } {
 	# Add -L$srcdir/$subdir so that the linker command can use
 	# linker scripts in the source directory.
 	set cmd "$LD $LDFLAGS -L$srcdir/$subdir \
-		   $opts(ld) -o $objfile $objfiles"
+		   $opts(ld) -o $objfile $objfiles $opts(ld_after_inputfiles)"
 
 	send_log "$cmd\n"
 	set cmdret [remote_exec host [concat sh -c [list "$cmd 2>&1"]] "" "/dev/null" "ld.tmp"]
Index: ld-cris/libdso-1c.d
===================================================================
RCS file: ld-cris/libdso-1c.d
diff -N ld-cris/libdso-1c.d
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld-cris/libdso-1c.d	15 Dec 2008 01:01:12 -0000
@@ -0,0 +1,35 @@
+#source: expdref1.s
+#as: --pic --no-underscore --em=criself
+#ld: --shared -m crislinux
+#ld_after_inputfiles: tmpdir/libdso-1b.so
+#objdump: -s -T
+
+# A DSO linked to another DSO that has two versioned symbols, to which
+# this DSO refers with two relocs each, a GOT and a PLT reference.
+# There was a bug such that GOT markups were lost, resulting in wrong
+# offsets into the GOT, with a tell-tale sign being one or more
+# R_CRIS_NONE relocs.  There should be two GOT relocs here, one each
+# for the symbols.
+
+.*:     file format elf32-cris
+
+DYNAMIC SYMBOL TABLE:
+#...
+0+[ 	]+DF \*UND\*	0+[ 	]+TST2[	 ]+expobj
+0+[ 	]+DF \*UND\*	0+[ 	]+TST2[	 ]+expfn
+#...
+Contents of section .rela.dyn:
+ 01a4 cc220000 0a030000 00000000 d0220000  .*
+ 01b4 0a040000 00000000                    .*
+Contents of section .plt:
+ 01bc fce17e7e 0401307a 08013009 00000000  .*
+ 01cc 00000000 6f0d0c00 00003009 3f7e0000  .*
+ 01dc 00002ffe ecffffff 6f0d1000 00003009  .*
+ 01ec 3f7e0000 00002ffe ecffffff           .*
+Contents of section .text:
+ 01f8 6fae0c00 00006fae ccffffff 6fae1000  .*
+ 0208 00006fae d4ffffff                    .*
+#...
+Contents of section .got:
+ 22c0 10220000 00000000 00000000 00000000  .*
+ 22d0 00000000                             .*
Index: elf32-cris.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-cris.c,v
retrieving revision 1.88
diff -p -u -r1.88 elf32-cris.c
--- elf32-cris.c	25 Nov 2008 13:03:55 -0000	1.88
+++ elf32-cris.c	15 Dec 2008 00:58:35 -0000
@@ -3006,6 +3012,35 @@ elf_cris_adjust_dynamic_symbol (info, h)
   return _bfd_elf_adjust_dynamic_copy (h, s);
 }
 
+/* Adjust our "subclass" elements for an indirect symbol.  */
+
+static void
+elf_cris_copy_indirect_symbol (struct bfd_link_info *info,
+			       struct elf_link_hash_entry *dir,
+			       struct elf_link_hash_entry *ind)
+{
+  struct elf_cris_link_hash_entry *edir, *eind;
+
+  edir = (struct elf_cris_link_hash_entry *) dir;
+  eind = (struct elf_cris_link_hash_entry *) ind;
+
+  BFD_ASSERT (edir->pcrel_relocs_copied == NULL);
+  BFD_ASSERT (edir->gotplt_offset == 0 || eind->gotplt_offset == 0);
+
+#define XMOVOPZ(F, OP, Z) edir->F OP eind->F; eind->F = Z
+#define XMOVE(F) XMOVOPZ (F, +=, 0)
+  XMOVOPZ (pcrel_relocs_copied, =, NULL);
+  XMOVE (gotplt_refcount);
+  XMOVE (gotplt_offset);
+  XMOVE (reg_got_refcount);
+  XMOVE (tprel_refcount);
+  XMOVE (dtp_refcount);
+#undef XMOVE
+#undef XMOVOPZ
+
+  _bfd_elf_link_hash_copy_indirect (info, dir, ind);
+}
+
 /* Look through the relocs for a section during the first phase.  */
 
 static bfd_boolean
@@ -4177,6 +4267,8 @@ elf_cris_got_elt_size (bfd *abfd ATTRIBU
 	elf_cris_link_hash_table_create
 #define elf_backend_adjust_dynamic_symbol \
 	elf_cris_adjust_dynamic_symbol
+#define elf_backend_copy_indirect_symbol \
+	elf_cris_copy_indirect_symbol
 #define elf_backend_size_dynamic_sections \
 	elf_cris_size_dynamic_sections
 #define elf_backend_init_index_section		_bfd_elf_init_1_index_section

brgds, H-P


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]