This is the mail archive of the 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]

ppc32 profiling of shared libx

Profiling doesn't work at all on ppc32 -msecure-plt shared libraries,
and not reliably on PIEs.  The problem is that a ppc32 PIC PLT call
stub uses r30 (GOT pointer) to load the function address from the PLT,
r30 being set up in the function prologue, but _mcount is called
before the function prologue.  So chances are good that r30 will be
pointing to the executable GOT when trying to call _mcount in a shared
lib function.  A similary problem can occur in a PIE if a shared lib
calls a function in the executable.

The proper fix is to move _mcount to libc_nonshared.a for ppc32, but
until everyone has this fix in their libc we can just force bss-plt.

	* elf32-ppc.c (ppc_elf_select_plt_layout): Force bss-plt when
	shared and call to _mcount will go via plt.

Index: bfd/elf32-ppc.c
RCS file: /cvs/src/src/bfd/elf32-ppc.c,v
retrieving revision 1.300
diff -u -p -r1.300 elf32-ppc.c
--- bfd/elf32-ppc.c	5 Aug 2011 02:24:08 -0000	1.300
+++ bfd/elf32-ppc.c	14 Aug 2011 03:49:01 -0000
@@ -4256,8 +4256,27 @@ ppc_elf_select_plt_layout (bfd *output_b
   if (htab->plt_type == PLT_UNSET)
+      struct elf_link_hash_entry *h;
       if (plt_style == PLT_OLD)
 	htab->plt_type = PLT_OLD;
+      else if (info->shared
+	       && htab->elf.dynamic_sections_created
+	       && (h = elf_link_hash_lookup (&htab->elf, "_mcount",
+					     FALSE, FALSE, TRUE)) != NULL
+	       && (h->type == STT_FUNC
+		   || h->needs_plt)
+	       && h->ref_regular
+	       && !(SYMBOL_CALLS_LOCAL (info, h)
+		    || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT
+			&& h->root.type == bfd_link_hash_undefweak)))
+	{
+	  /* Profiling of shared libs (and pies) is not supported with
+	     secure plt, because ppc32 does profiling before a
+	     function prologue and a secure plt pic call stubs needs
+	     r30 to be set up.  */
+	  htab->plt_type = PLT_OLD;
+	}
 	  bfd *ibfd;
@@ -4285,7 +4304,13 @@ ppc_elf_select_plt_layout (bfd *output_b
   if (htab->plt_type == PLT_OLD && plt_style == PLT_NEW)
-    info->callbacks->einfo (_("%P: bss-plt forced due to %B\n"), htab->old_bfd);
+    {
+      if (htab->old_bfd != NULL)
+	info->callbacks->einfo (_("%P: bss-plt forced due to %B\n"),
+				htab->old_bfd);
+      else
+	info->callbacks->einfo (_("%P: bss-plt forced by profiling\n"));
+    }
   BFD_ASSERT (htab->plt_type != PLT_VXWORKS);

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]