powerpc64 tail calls

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

powerpc64 tail calls

Alan Modra
See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=25380.  Attempting to
compile powerpc64-linux shared libs without -fpic can lead to trouble
with tail calls.  This forces the linker to resolve them locally.
Which breaks ELF shared lib symbol resolution rules, but I can't warn
here because self-recursion via a tail call is fine.

        * elf64-ppc.c (ppc64_elf_relocate_section): Force tail calls in
        shared libs to resolve locally.

Index: bfd/elf64-ppc.c
===================================================================
RCS file: /cvs/src/src/bfd/elf64-ppc.c,v
retrieving revision 1.227
diff -u -p -r1.227 elf64-ppc.c
--- bfd/elf64-ppc.c 12 Dec 2005 03:59:52 -0000 1.227
+++ bfd/elf64-ppc.c 13 Dec 2005 05:32:54 -0000
@@ -10070,10 +10070,12 @@ ppc64_elf_relocate_section (bfd *output_
   if (stub_entry->stub_type == ppc_stub_plt_call)
     {
       /* If this is a plain branch rather than a branch
- and link, don't require a nop.  */
+ and link, don't require a nop.  However, don't
+ allow tail calls in a shared library as they
+ will result in r2 being corrupted.  */
       unsigned long br;
       br = bfd_get_32 (input_bfd, contents + rel->r_offset);
-      if ((br & 1) == 0)
+      if (info->executable && (br & 1) == 0)
  can_plt_call = TRUE;
       else
  stub_entry = NULL;

--
Alan Modra
IBM OzLabs - Linux Technology Centre