binutils-gdb/ld/testsuite
H.J. Lu 1622ff3b43 Check regular reference without non-GOT reference
non_got_ref may not be set when building shared library. We need to set
non_got_ref if there are any non-PIC relocations.  But we only did this
when there were no PLT/GOT relocations.  It failed when there is a PLT
relocation.  This checkin moves the non_got_ref check out.

bfd/

2013-04-15  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/15371
	* elf-ifunc.c (_bfd_elf_allocate_ifunc_dyn_relocs): Check
	regular reference without non-GOT reference when building
	shared library.

ld/testsuite/

2013-04-15  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/15371
	* ld-ifunc/ifunc-20-i386.d: New file.
	* ld-ifunc/ifunc-20-x86-64.d: Likewise.
	* ld-ifunc/ifunc-20.s: Likewise.
diff --git a/bfd/elf-ifunc.c b/bfd/elf-ifunc.c
index e56427d..7e7ec36 100644
--- a/bfd/elf-ifunc.c
+++ b/bfd/elf-ifunc.c
@@ -187,23 +187,20 @@ _bfd_elf_allocate_ifunc_dyn_relocs (struct bfd_link_info *info,

   htab = elf_hash_table (info);

+  /* When building shared library, we need to handle the case where it is
+     marked with regular reference, but not non-GOT reference since the
+     non-GOT reference bit may not be set here.  */
+  if (info->shared && !h->non_got_ref && h->ref_regular)
+    for (p = *head; p != NULL; p = p->next)
+      if (p->count)
+	{
+	  h->non_got_ref = 1;
+	  goto keep;
+	}
+
   /* Support garbage collection against STT_GNU_IFUNC symbols.  */
   if (h->plt.refcount <= 0 && h->got.refcount <= 0)
     {
-      /* When building shared library, we need to handle the case
-         where it is marked with regular reference, but not non-GOT
-	 reference.  It may happen if we didn't see STT_GNU_IFUNC
-	 symbol at the time when checking relocations.  */
-      if (info->shared
-	  && !h->non_got_ref
-	  && h->ref_regular)
-	for (p = *head; p != NULL; p = p->next)
-	  if (p->count)
-	    {
-	      h->non_got_ref = 1;
-	      goto keep;
-	    }
-
       h->got = htab->init_got_offset;
       h->plt = htab->init_plt_offset;
       *head = NULL;
diff --git a/ld/testsuite/ld-ifunc/ifunc-20-i386.d b/ld/testsuite/ld-ifunc/ifunc-20-i386.d
new file mode 100644
index 0000000..9373fcf
--- /dev/null
+++ b/ld/testsuite/ld-ifunc/ifunc-20-i386.d
@@ -0,0 +1,13 @@
+#source: ifunc-20.s
+#ld: -shared -m elf_i386 -z nocombreloc
+#as: --32
+#readelf: -r --wide
+#target: x86_64-*-* i?86-*-*
+
+Relocation section '.rel.ifunc' at offset 0x[0-9a-f]+ contains 1 entries:
+[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_32[ ]+ifunc\(\)[ ]+ifunc
+
+Relocation section '.rel.plt' at offset 0x[0-9a-f]+ contains 1 entries:
+[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_386_JUMP_SLOT[ ]+ifunc\(\)[ ]+ifunc
diff --git a/ld/testsuite/ld-ifunc/ifunc-20-x86-64.d b/ld/testsuite/ld-ifunc/ifunc-20-x86-64.d
new file mode 100644
index 0000000..39492d4
--- /dev/null
+++ b/ld/testsuite/ld-ifunc/ifunc-20-x86-64.d
@@ -0,0 +1,13 @@
+#source: ifunc-20.s
+#ld: -shared -m elf_x86_64 -z nocombreloc
+#as: --64
+#readelf: -r --wide
+#target: x86_64-*-*
+
+Relocation section '.rela.ifunc' at offset 0x[0-9a-f]+ contains 1 entries:
+[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_64[ ]+ifunc\(\)[ ]+ifunc \+ 0
+
+Relocation section '.rela.plt' at offset 0x[0-9a-f]+ contains 1 entries:
+[ ]+Offset[ ]+Info[ ]+Type[ ]+.*
+[0-9a-f]+[ ]+[0-9a-f]+[ ]+R_X86_64_JUMP_SLOT[ ]+ifunc\(\)[ ]+ifunc \+ 0
diff --git a/ld/testsuite/ld-ifunc/ifunc-20.s b/ld/testsuite/ld-ifunc/ifunc-20.s
new file mode 100644
index 0000000..9d45455
--- /dev/null
+++ b/ld/testsuite/ld-ifunc/ifunc-20.s
@@ -0,0 +1,16 @@
+	.section .data.rel,"aw",@progbits
+	.globl ifunc_ptrt
+	.type	ifunc_ptr, @object
+ifunc_ptr:
+	.dc.a ifunc
+	.text
+	.type ifunc, @gnu_indirect_function
+	.globl ifunc
+ifunc:
+	ret
+	.size	ifunc, .-ifunc
+	.type bar, @function
+	.globl bar
+bar:
+	call	ifunc@PLT
+	.size	bar, .-bar
2013-04-15 21:16:18 +00:00
..
config Add HOSTING_SCRT0 for PIE test 2013-01-19 19:36:37 +00:00
ld-aarch64 2013-04-10 Venkataramanan Kumar <venkataramanan.kumar@linaro.org> 2013-04-10 12:00:14 +00:00
ld-alpha * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-arm gas/testsuite/ChangeLog: 2013-03-15 17:55:03 +00:00
ld-auto-import
ld-bootstrap 2011-12-03 David Daney <david.daney@cavium.com> 2011-12-03 17:13:02 +00:00
ld-cdtest
ld-checks
ld-cris * ld-cris/libdso-13.d: Adjust for --enable-new-dtags now 2013-01-31 09:55:23 +00:00
ld-crx
ld-cygwin
ld-d10v
ld-discard bfd/ 2012-04-03 16:01:38 +00:00
ld-elf * ld-elf/shared.exp: Update regexp on --no-add-needed and 2013-04-04 14:51:48 +00:00
ld-elfcomm 2013-02-06 Sandra Loosemore <sandra@codesourcery.com> 2013-02-06 23:22:26 +00:00
ld-elfvers ld/testsuite/ChangeLog: 2013-03-20 12:46:27 +00:00
ld-elfvsb gas/testsuite/ChangeLog: 2013-03-15 17:55:03 +00:00
ld-elfweak * ld-elfvers/vers.exp: Add -Wl,--no-as-needed to all tests 2013-03-20 02:28:17 +00:00
ld-fastcall
ld-frv * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-gc * common.h: Fix case of "Meta". 2013-01-10 09:49:22 +00:00
ld-h8300 * elf32-h8300 (h8_relax_section): Add new relaxation of mov 2013-03-21 16:08:07 +00:00
ld-i386 * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-ia64 * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-ifunc Check regular reference without non-GOT reference 2013-04-15 21:16:18 +00:00
ld-libs * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-linkonce bfd/ 2012-04-03 16:01:38 +00:00
ld-m68hc11 2012-11-07 James Murray <jsm@jsm-net.demon.co.uk> 2012-11-07 20:35:02 +00:00
ld-m68k * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-mep
ld-metag * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-mips-elf * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-misc * ld-gc/start.d: Exclude frv-*-linux*. 2011-02-10 07:24:06 +00:00
ld-mmix * ld-mmix/sec-1.d, ld-mmix/sec-3.d: Force end-of-section symbols 2012-09-09 16:31:12 +00:00
ld-mn10300 * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-nios2 2013-02-06 Sandra Loosemore <sandra@codesourcery.com> 2013-02-06 23:22:26 +00:00
ld-pe * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-pie * ld-pie/pie.exp: Remove extra braces. 2012-04-23 18:03:28 +00:00
ld-plugin PR ld/15227 2013-04-03 11:44:41 +00:00
ld-powerpc * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-s390 * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-scripts PR ld/15222 2013-03-05 02:55:27 +00:00
ld-selective * ld-elf/linkoncerdiff.d: Don't run for hppa64-hpux. 2012-02-14 01:02:04 +00:00
ld-sh * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-shared gas/testsuite/ChangeLog: 2013-03-15 17:55:03 +00:00
ld-size Don't resolve size relocation against non-zero TLS symbol 2013-02-07 02:15:30 +00:00
ld-sparc * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-spu ld/ 2012-06-15 15:13:41 +00:00
ld-srec Add support for 64-bit ARM architecture: AArch64 2012-08-13 14:52:54 +00:00
ld-tic6x * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-tilegx * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-tilepro * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-undefined * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-unique Set unique_global only for definition 2013-02-22 01:20:48 +00:00
ld-v850
ld-vax-elf * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-versados
ld-vxworks
ld-x86-64 * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-xc16x * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-xstormy16 * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
ld-xtensa * lib/ld-lib.exp (run_ld_link_tests): Add another argument, pass 2013-02-19 01:10:06 +00:00
lib * elf64-aarch64.c (elf_backend_can_gc_sections): Enable 2013-03-08 17:37:30 +00:00
ChangeLog Check regular reference without non-GOT reference 2013-04-15 21:16:18 +00:00
ChangeLog-2004 Add copyright notices 2012-12-10 12:48:03 +00:00
ChangeLog-2005 Add copyright notices 2012-12-10 12:48:03 +00:00
ChangeLog-2006 Add copyright notices 2012-12-10 12:48:03 +00:00
ChangeLog-2007 Add copyright notices 2012-12-10 12:48:03 +00:00
ChangeLog-2008 Add copyright notices 2012-12-10 12:48:03 +00:00
ChangeLog-2009 Add copyright notices 2012-12-10 12:48:03 +00:00
ChangeLog-2010 Add copyright notices 2012-12-10 12:48:03 +00:00
ChangeLog-2011 Add copyright notices 2012-12-10 12:48:03 +00:00
ChangeLog-2012 Rotate binutils ChangeLog for 2013 2013-01-02 17:06:32 +00:00
ChangeLog-9303 Add copyright notices 2012-12-10 12:48:03 +00:00