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] x86: Add -z print-local-ifuncs to ELF linker


On Wed, Jun 7, 2017 at 6:33 PM, Alan Modra <amodra@gmail.com> wrote:
> On Wed, Jun 07, 2017 at 06:05:55AM -0700, H.J. Lu wrote:
>> Add -z print-local-ifuncs to x86 ELF linker to list local IFUNC functions
>> when generating executables and shared objects.
>>
>> Any comments?
>
> I'm wondering if it would be better to dump this output to a map file,
> using minfo rather than einfo.  If you do that then there is possibly
> no need to have an option to control the output;  If a mapfile is
> requested then you will see a list of these symbols.  In any case, I
> don't see a need for -z noprint-local-ifuncs.
>

Thanks for your suggestion.  This is what I checked in.

-- 
H.J.
From 6322e5c5cb7ffe1c26c50f117765503717b0431c Mon Sep 17 00:00:00 2001
From: "H.J. Lu" <hjl.tools@gmail.com>
Date: Wed, 7 Jun 2017 21:18:01 -0700
Subject: [PATCH] x86: Dump local IFUNC functions in the map file

Dump local IFUNC functions in the map file when generating IRELATIVE
relocations if -Map is used.

bfd/

	* elf32-i386.c (elf_i386_check_relocs): Set local IFUNC symbol
	name.  Use local IFUNC symbol name string to report unsupported
	non-PIC call to IFUNC function.
	(elf_i386_relocate_section): Dump local IFUNC name with minfo
	when generating R_386_IRELATIVE relocation.
	(elf_i386_finish_dynamic_symbol): Likewise.
	* elf_x86_64_check_relocs (elf_x86_64_check_relocs): Set local
	IFUNC symbol name.
	(elf_x86_64_relocate_section): Dump local IFUNC name with minfo
	when generating R_X86_64_IRELATIVE relocation.
	(elf_x86_64_finish_dynamic_symbol): Likewise.

ld/

	* testsuite/ld-ifunc/ifunc-1-local-x86.d: Pass
	"-Map tmpdir/ifunc-1-local-x86.map" to ld and check
	ifunc-1-local-x86.map.
	* testsuite/ld-ifunc/ifunc-1-x86.d: Pass
	"-Map tmpdir/ifunc-1-x86.map" to ld and check ifunc-1-x86.map.
	* testsuite/ld-ifunc/ifunc-1-local-x86.map: New file.
	* testsuite/ld-ifunc/ifunc-1-x86.map: Likewise.
---
 bfd/elf32-i386.c                            | 27 ++++++++++++++++++---------
 bfd/elf64-x86-64.c                          | 15 +++++++++++++++
 ld/testsuite/ld-ifunc/ifunc-1-local-x86.d   |  3 ++-
 ld/testsuite/ld-ifunc/ifunc-1-local-x86.map |  3 +++
 ld/testsuite/ld-ifunc/ifunc-1-x86.d         |  3 ++-
 ld/testsuite/ld-ifunc/ifunc-1-x86.map       |  3 +++
 6 files changed, 43 insertions(+), 11 deletions(-)
 create mode 100644 ld/testsuite/ld-ifunc/ifunc-1-local-x86.map
 create mode 100644 ld/testsuite/ld-ifunc/ifunc-1-x86.map

diff --git a/bfd/elf32-i386.c b/bfd/elf32-i386.c
index 1fdc06c..e447e3d 100644
--- a/bfd/elf32-i386.c
+++ b/bfd/elf32-i386.c
@@ -1945,6 +1945,8 @@ elf_i386_check_relocs (bfd *abfd,
 		goto error_return;
 
 	      /* Fake a STT_GNU_IFUNC symbol.  */
+	      h->root.root.string = bfd_elf_sym_name (abfd, symtab_hdr,
+						      isym, NULL);
 	      h->type = STT_GNU_IFUNC;
 	      h->def_regular = 1;
 	      h->ref_regular = 1;
@@ -2181,15 +2183,10 @@ do_relocation:
 		  else if (h->type == STT_GNU_IFUNC
 			   && bfd_link_pic (info))
 		    {
-		    if (isym == NULL)
-		      name = h->root.root.string;
-		    else
-		      name = bfd_elf_sym_name (abfd, symtab_hdr, isym,
-					       NULL);
-		    _bfd_error_handler
-		      /* xgettext:c-format */
-		      (_("%B: unsupported non-PIC call to IFUNC `%s'"),
-		       abfd, name);
+		      _bfd_error_handler
+			/* xgettext:c-format */
+			(_("%B: unsupported non-PIC call to IFUNC `%s'"),
+			 abfd, h->root.root.string);
 		      bfd_set_error (bfd_error_bad_value);
 		      goto error_return;
 		    }
@@ -4081,6 +4078,10 @@ do_ifunc_pointer:
 		      || h->forced_local
 		      || bfd_link_executable (info))
 		    {
+		      info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"),
+					      h->root.root.string,
+					      h->root.u.def.section->owner);
+
 		      /* This symbol is resolved locally.  */
 		      outrel.r_info = ELF32_R_INFO (0, R_386_IRELATIVE);
 		      bfd_put_32 (output_bfd,
@@ -5413,6 +5414,10 @@ elf_i386_finish_dynamic_symbol (bfd *output_bfd,
 		  && h->def_regular
 		  && h->type == STT_GNU_IFUNC))
 	    {
+	      info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"),
+				      h->root.root.string,
+				      h->root.u.def.section->owner);
+
 	      /* If an STT_GNU_IFUNC symbol is locally defined, generate
 		 R_386_IRELATIVE instead of R_386_JUMP_SLOT.  Store addend
 		 in the .got.plt section.  */
@@ -5548,6 +5553,10 @@ elf_i386_finish_dynamic_symbol (bfd *output_bfd,
 		}
 	      if (SYMBOL_REFERENCES_LOCAL (info, h))
 		{
+		  info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"),
+					  h->root.root.string,
+					  h->root.u.def.section->owner);
+
 		  bfd_put_32 (output_bfd,
 			      (h->root.u.def.value
 			       + h->root.u.def.section->output_section->vma
diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c
index 7beb78e..c94d7ff 100644
--- a/bfd/elf64-x86-64.c
+++ b/bfd/elf64-x86-64.c
@@ -2281,6 +2281,8 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
 		goto error_return;
 
 	      /* Fake a STT_GNU_IFUNC symbol.  */
+	      h->root.root.string = bfd_elf_sym_name (abfd, symtab_hdr,
+						      isym, NULL);
 	      h->type = STT_GNU_IFUNC;
 	      h->def_regular = 1;
 	      h->ref_regular = 1;
@@ -4422,6 +4424,10 @@ do_ifunc_pointer:
 		      || h->forced_local
 		      || bfd_link_executable (info))
 		    {
+		      info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"),
+					      h->root.root.string,
+					      h->root.u.def.section->owner);
+
 		      /* This symbol is resolved locally.  */
 		      outrel.r_info = htab->r_info (0, R_X86_64_IRELATIVE);
 		      outrel.r_addend = (h->root.u.def.value
@@ -5791,6 +5797,10 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
 		  && h->def_regular
 		  && h->type == STT_GNU_IFUNC))
 	    {
+	      info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"),
+				      h->root.root.string,
+				      h->root.u.def.section->owner);
+
 	      /* If an STT_GNU_IFUNC symbol is locally defined, generate
 		 R_X86_64_IRELATIVE instead of R_X86_64_JUMP_SLOT.  */
 	      rela.r_info = htab->r_info (0, R_X86_64_IRELATIVE);
@@ -5941,6 +5951,11 @@ elf_x86_64_finish_dynamic_symbol (bfd *output_bfd,
 		}
 	      if (SYMBOL_REFERENCES_LOCAL (info, h))
 		{
+		  info->callbacks->minfo (_("Local IFUNC function `%s' in %B\n"),
+					  output_bfd,
+					  h->root.root.string,
+					  h->root.u.def.section->owner);
+
 		  rela.r_info = htab->r_info (0,
 					      R_X86_64_IRELATIVE);
 		  rela.r_addend = (h->root.u.def.value
diff --git a/ld/testsuite/ld-ifunc/ifunc-1-local-x86.d b/ld/testsuite/ld-ifunc/ifunc-1-local-x86.d
index 00bc474..c14cd28 100644
--- a/ld/testsuite/ld-ifunc/ifunc-1-local-x86.d
+++ b/ld/testsuite/ld-ifunc/ifunc-1-local-x86.d
@@ -1,6 +1,7 @@
-#ld: -shared
+#ld: -shared -Map tmpdir/ifunc-1-local-x86.map
 #objdump: -dw
 #target: x86_64-*-* i?86-*-*
+#map: ifunc-1-local-x86.map
 
 #...
 [ \t0-9a-f]+:[ \t0-9a-f]+call[ \t0-9a-fq]+<\*ABS\*(\+0x160|\+0x170|\+0x1e0|)@plt>
diff --git a/ld/testsuite/ld-ifunc/ifunc-1-local-x86.map b/ld/testsuite/ld-ifunc/ifunc-1-local-x86.map
new file mode 100644
index 0000000..557a446
--- /dev/null
+++ b/ld/testsuite/ld-ifunc/ifunc-1-local-x86.map
@@ -0,0 +1,3 @@
+#...
+Local IFUNC function `__GI_foo' in tmpdir/ifunc-1-local-x86.o
+#pass
diff --git a/ld/testsuite/ld-ifunc/ifunc-1-x86.d b/ld/testsuite/ld-ifunc/ifunc-1-x86.d
index f9dee1b..c245758 100644
--- a/ld/testsuite/ld-ifunc/ifunc-1-x86.d
+++ b/ld/testsuite/ld-ifunc/ifunc-1-x86.d
@@ -1,6 +1,7 @@
-#ld: -shared
+#ld: -shared -Map tmpdir/ifunc-1-x86.map
 #objdump: -dw
 #target: x86_64-*-* i?86-*-*
+#map: ifunc-1-x86.map
 
 #...
 [ \t0-9a-f]+:[ \t0-9a-f]+call[ \t0-9a-fq]+<\*ABS\*(\+0x170|\+0x190|\+0x210|)@plt>
diff --git a/ld/testsuite/ld-ifunc/ifunc-1-x86.map b/ld/testsuite/ld-ifunc/ifunc-1-x86.map
new file mode 100644
index 0000000..98bbb7a
--- /dev/null
+++ b/ld/testsuite/ld-ifunc/ifunc-1-x86.map
@@ -0,0 +1,3 @@
+#...
+Local IFUNC function `__GI_foo' in tmpdir/ifunc-1-x86.o
+#pass
-- 
2.9.4


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