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]

Re: PATCH: PR ld/3953: ld crashes upon use of .gnu.warning.<symbol> sections


On Fri, Feb 02, 2007 at 11:51:48AM -0800, H. J. Lu wrote:
> We need to check warning symbol when adding default symbol.
> 
> 

Here is a patch with testcases.


H.J.
---
bfd/

2007-02-09  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/3953
	* elflink.c (_bfd_elf_add_default_symbol): Check warning symbol
	when adding default symbol.

ld/testsuite/

2007-02-09  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/3953
	* ld-elf/elf.exp: Build libwarn3a.so and libwarn3b.so.

	* ld-elf/warn3.map: New file.
	* ld-elf/warn3a.d: Likewise.
	* ld-elf/warn3b.d: Likewise.
	* ld-elf/warn3refw.c: Likewise.
	* ld-elf/warn3sym.c: Likewise.

--- binutils/bfd/elflink.c.warn	2007-02-10 07:14:07.000000000 -0800
+++ binutils/bfd/elflink.c	2007-02-10 09:21:16.000000000 -0800
@@ -1595,6 +1595,10 @@ _bfd_elf_add_default_symbol (bfd *abfd,
       hi = h;
     }
 
+  /* Check if HI is a warning symbol.  */
+  if (hi->root.type == bfd_link_hash_warning)
+    hi = (struct elf_link_hash_entry *) hi->root.u.i.link;
+
   /* If there is a duplicate definition somewhere, then HI may not
      point to an indirect symbol.  We will have reported an error to
      the user in that case.  */
--- binutils/ld/testsuite/ld-elf/elf.exp.warn	2005-11-15 00:32:02.000000000 -0800
+++ binutils/ld/testsuite/ld-elf/elf.exp	2007-02-10 09:19:45.000000000 -0800
@@ -1,5 +1,5 @@
 # Expect script for various ELF tests.
-#   Copyright 2002, 2003 Free Software Foundation, Inc.
+#   Copyright 2002, 2003, 2007 Free Software Foundation, Inc.
 #
 # This file is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -22,6 +22,16 @@ if ![is_elf_format] {
     return
 }
 
+set build_tests {
+  {"Build libwarn3a.so"
+   "-shared" "-fPIC"
+   {warn3refw.c warn3sym.c} {} "libwarn3a.so"}
+  {"Build libwarn3b.so"
+   "-shared -Wl,--version-script=warn3.map" "-fPIC"
+   {warn3sym.c} {} "libwarn3b.so"}
+}
+
+run_cc_link_tests $build_tests
 set test_list [lsort [glob -nocomplain $srcdir/$subdir/*.d]]
 foreach t $test_list {
     # We need to strip the ".d", but can leave the dirname.
--- binutils/ld/testsuite/ld-elf/warn3.map.warn	2007-02-10 09:23:37.000000000 -0800
+++ binutils/ld/testsuite/ld-elf/warn3.map	2007-02-10 09:07:47.000000000 -0800
@@ -0,0 +1,4 @@
+FOO {
+  global: foo;
+  local: *;
+};
--- binutils/ld/testsuite/ld-elf/warn3a.d.warn	2007-02-10 09:23:37.000000000 -0800
+++ binutils/ld/testsuite/ld-elf/warn3a.d	2007-02-10 09:20:29.000000000 -0800
@@ -0,0 +1,13 @@
+#source: start.s
+#ld: tmpdir/warn3refw.o tmpdir/libwarn3a.so
+#warning: ^.*\): warning: function foo is deprecated$
+#readelf: -s
+#target: *-*-linux*
+
+# Check that warnings are generated for the .gnu.warning.SYMBOL
+# construct, that the symbol still appears as expected and linker
+# won't crash
+
+#...
+[ 	]+[0-9]+:[ 	]+[0-9a-f]+[ 	]+[0-9a-f]+[ 	]+FUNC[	 ]+GLOBAL DEFAULT[ 	]+UND foo
+#pass
--- binutils/ld/testsuite/ld-elf/warn3b.d.warn	2007-02-10 09:23:37.000000000 -0800
+++ binutils/ld/testsuite/ld-elf/warn3b.d	2007-02-10 09:23:07.000000000 -0800
@@ -0,0 +1,13 @@
+#source: start.s
+#ld: tmpdir/warn3refw.o tmpdir/libwarn3b.so
+#warning: ^.*\): warning: function foo is deprecated$
+#readelf: -s
+#target: *-*-linux*
+
+# Check that warnings are generated for the .gnu.warning.SYMBOL
+# construct, that the symbol still appears as expected and linker
+# won't crash
+
+#...
+[ 	]+[0-9]+:[ 	]+[0-9a-f]+[ 	]+[0-9a-f]+[ 	]+FUNC[	 ]+GLOBAL DEFAULT[ 	]+UND foo@@FOO
+#pass
--- binutils/ld/testsuite/ld-elf/warn3refw.c.warn	2007-02-10 09:23:37.000000000 -0800
+++ binutils/ld/testsuite/ld-elf/warn3refw.c	2007-02-10 08:27:22.000000000 -0800
@@ -0,0 +1,9 @@
+static const char _evoke_link_warning_foo []
+  __attribute__ ((used, section (".gnu.warning.foo")))
+    = "function foo is deprecated";
+
+extern void foo (void);
+
+static void (*const init_array []) (void)
+  __attribute__ ((used, section (".init_array"), aligned (sizeof (void *))))
+  = { foo };
--- binutils/ld/testsuite/ld-elf/warn3sym.c.warn	2007-02-10 09:23:37.000000000 -0800
+++ binutils/ld/testsuite/ld-elf/warn3sym.c	2007-02-10 08:40:35.000000000 -0800
@@ -0,0 +1,4 @@
+void
+foo ()
+{
+}


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