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]

REL target user sections with relocs


Dynamic reloc sections in REL targets are seen as RELA for user
sections with names starting with "a".  I thought I'd fixed this
problem a long time ago, but apparently not.

bfd/
	* elflink.c (_bfd_elf_make_dynamic_reloc_section): Override
	sh_type according to is_rela.
ld/testsuite/
	* ld-elf/rel.c, ld-elf/relmain.c, ld-elf/relmain.out: New test.
	* ld-elf/shared.exp: Build and run it.

Index: bfd/elflink.c
===================================================================
RCS file: /cvs/src/src/bfd/elflink.c,v
retrieving revision 1.473
diff -u -p -r1.473 elflink.c
--- bfd/elflink.c	18 Mar 2013 02:47:02 -0000	1.473
+++ bfd/elflink.c	20 Mar 2013 00:29:56 -0000
@@ -13025,6 +13025,11 @@ _bfd_elf_make_dynamic_reloc_section (ase
 	  reloc_sec = bfd_make_section_anyway_with_flags (dynobj, name, flags);
 	  if (reloc_sec != NULL)
 	    {
+	      /* _bfd_elf_get_sec_type_attr chooses a section type by
+		 name.  Override as it may be wrong, eg. for a user
+		 section named "auto" we'll get ".relauto" which is
+		 seen to be a .rela section.  */
+	      elf_section_type (reloc_sec) = is_rela ? SHT_RELA : SHT_REL;
 	      if (! bfd_set_section_alignment (dynobj, reloc_sec, alignment))
 		reloc_sec = NULL;
 	    }
Index: ld/testsuite/ld-elf/rel.c
===================================================================
RCS file: ld/testsuite/ld-elf/rel.c
diff -N ld/testsuite/ld-elf/rel.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/rel.c	20 Mar 2013 03:06:32 -0000
@@ -0,0 +1,9 @@
+static int seven = 7;
+static int *__attribute__((section("auto"))) auto_10 = &seven;
+
+int
+eight (void)
+{
+  extern int *__start_auto[], *__stop_auto[];
+  return *auto_10 + __stop_auto - __start_auto;
+}
Index: ld/testsuite/ld-elf/relmain.c
===================================================================
RCS file: ld/testsuite/ld-elf/relmain.c
diff -N ld/testsuite/ld-elf/relmain.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ ld/testsuite/ld-elf/relmain.c	20 Mar 2013 03:06:32 -0000
@@ -0,0 +1,7 @@
+extern int eight (void);
+
+int
+main (void)
+{
+  return eight () - 8;
+}
Index: ld/testsuite/ld-elf/relmain.out
===================================================================
RCS file: ld/testsuite/ld-elf/relmain.out
diff -N ld/testsuite/ld-elf/relmain.out
Index: ld/testsuite/ld-elf/shared.exp
===================================================================
RCS file: /cvs/src/src/ld/testsuite/ld-elf/shared.exp,v
retrieving revision 1.26
diff -u -p -r1.26 shared.exp
--- ld/testsuite/ld-elf/shared.exp	7 Dec 2012 05:26:39 -0000	1.26
+++ ld/testsuite/ld-elf/shared.exp	20 Mar 2013 03:06:32 -0000
@@ -203,6 +203,9 @@ set build_tests {
   {"Build needed1b.so with --no-copy-dt-needed-entries"
    "-shared tmpdir/libneeded1pic.o -Wl,--no-copy-dt-needed-entries -Ltmpdir -lneeded1a" ""
    {dummy.c} {} "needed1d.so"}
+  {"Build librel.so"
+   "-shared" "-fPIC"
+   {rel.c} {} "librel.so"}
 }
 
 run_cc_link_tests $build_tests
@@ -347,6 +350,9 @@ set run_tests {
     {"Link with --copy-dt-needed-entries"
      "tmpdir/libneeded1c.o --copy-dt-needed-entries -rpath=tmpdir -Ltmpdir -lneeded1a" ""
      {dummy.c} "needed1b" "needed1.out"}
+    {"Run relmain"
+     "--no-as-needed -rpath=tmpdir -Ltmpdir -lrel" ""
+     {relmain.c} "relmain" "relmain.out"}
 }
 
 # NetBSD ELF systems do not currently support the .*_array sections.

-- 
Alan Modra
Australia Development Lab, IBM


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