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]

Committed: fix CRIS linker SEGV trigged by --as-needed.


See the test-case for the description.

bfd:
	* elf32-cris.c (cris_elf_check_relocs): Don't assume
	a registered dynobj means that a .got has been created.

ld/testsuite:
	* ld-cris/asneed1.d: New test.

--- /dev/null	Tue Oct 29 15:57:07 2002
+++ ld-cris/asneed1.d	Fri Oct 18 04:20:37 2013
@@ -0,0 +1,25 @@
+#source: start1.s
+#source: dso-2.s
+#source: dso-1.s
+#as: --pic --no-underscore --em=criself
+#ld: -m crislinux --as-needed tmpdir/libdso-1.so
+#objdump: -p
+
+# Using --as-needed caused a elf_hash_table (info)->dynobj to be
+# registered before cris_elf_check_relocs was called, thereby
+# voiding an assumption that it was the sole setter of
+# htab->dynobj, trigging a SEGV due to a NULL dereference for
+# the variable holding the .got section.
+# The test-case would FAIL for the SEGV and we also check that
+# we don't get the DT_NEEDED tag (indeed no dynamic things at
+# all) because the library isn't needed and would have to move
+# to the end of the link-line to have effect if actually needed.
+
+.*:     file format elf32-cris
+
+Program Header:
+    LOAD off    .*
+         filesz .*
+    LOAD off    .*
+         filesz .*
+private flags = 0:



Index: elf32-cris.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-cris.c,v
retrieving revision 1.131
diff -u -p -r1.131 elf32-cris.c
--- elf32-cris.c	30 Mar 2013 10:14:14 -0000	1.131
+++ elf32-cris.c	18 Oct 2013 00:58:37 -0000
@@ -3236,15 +3236,20 @@ cris_elf_check_relocs (bfd *abfd,
 		     abfd, sec);
 		  return FALSE;
 		}
+	    }
 
-	      /* Create the .got section, so we can assume it's always
-		 present whenever there's a dynobj.  */
+	  if (sgot == NULL)
+	    {
+	      /* We may have a dynobj but no .got section, if machine-
+		 independent parts of the linker found a reason to create
+		 a dynobj.  We want to create the .got section now, so we
+		 can assume it's always present whenever there's a dynobj.
+		 It's ok to call this function more than once.  */
 	      if (!_bfd_elf_create_got_section (dynobj, info))
 		return FALSE;
-	    }
 
-	  if (sgot == NULL)
-	    sgot = bfd_get_linker_section (dynobj, ".got");
+	      sgot = bfd_get_linker_section (dynobj, ".got");
+	    }
 
 	  if (local_got_refcounts == NULL)
 	    {

brgds, H-P


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