Blame SOURCES/gdb-rhbz1125820-ppc64le-enablement-14of37.patch

7ab123
commit 52a82034ac9a288d2d8e60efa880623288b5d228
7ab123
Author: Alan Modra <amodra@gmail.com>
7ab123
Date:   Fri Nov 1 19:25:56 2013 +1030
7ab123
7ab123
    Edit ELFv2 global entry prologue to non-PIC
7ab123
    
7ab123
    Changing addis r2,r12,..; addi r2,r2,.. to lis r2,..; addi r2,r2..
7ab123
    in non-PIC executables has the benefit of removing a dependency on r12.
7ab123
    
7ab123
    bfd/
7ab123
    	* elf64-ppc.c (ppc64_elf_relocate_section): Edit global entry
7ab123
    	prologue to non-PIC in non-PIC executables.
7ab123
    ld/testsuite/
7ab123
    	* ld-powerpc/elfv2exe.d: Adjust for non-PIC global entry.
7ab123
7ab123
Index: gdb-7.6.1/bfd/elf64-ppc.c
7ab123
===================================================================
7ab123
--- gdb-7.6.1.orig/bfd/elf64-ppc.c
7ab123
+++ gdb-7.6.1/bfd/elf64-ppc.c
7ab123
@@ -13280,6 +13280,39 @@ ppc64_elf_relocate_section (bfd *output_
7ab123
 	      rel->r_info = ELF64_R_INFO (r_symndx, r_type);
7ab123
 	    }
7ab123
 	  break;
7ab123
+
7ab123
+	case R_PPC64_REL16_HA:
7ab123
+	  /* If we are generating a non-PIC executable, edit
7ab123
+	     .	0:	addis 2,12,.TOC.-0b@ha
7ab123
+	     .		addi 2,2,.TOC.-0b@l
7ab123
+	     used by ELFv2 global entry points to set up r2, to
7ab123
+	     .		lis 2,.TOC.@ha
7ab123
+	     .		addi 2,2,.TOC.@l
7ab123
+	     if .TOC. is in range.  */
7ab123
+	  if (!info->shared
7ab123
+	      && h != NULL && &h->elf == htab->elf.hgot
7ab123
+	      && rel + 1 < relend
7ab123
+	      && rel[1].r_info == ELF64_R_INFO (r_symndx, R_PPC64_REL16_LO)
7ab123
+	      && rel[1].r_offset == rel->r_offset + 4
7ab123
+	      && rel[1].r_addend == rel->r_addend + 4
7ab123
+	      && relocation + 0x80008000 <= 0xffffffff)
7ab123
+	    {
7ab123
+	      unsigned int insn1, insn2;
7ab123
+	      bfd_vma offset = rel->r_offset - d_offset;
7ab123
+	      insn1 = bfd_get_32 (output_bfd, contents + offset);
7ab123
+	      insn2 = bfd_get_32 (output_bfd, contents + offset + 4);
7ab123
+	      if ((insn1 & 0xffff0000) == 0x3c4c0000 /* addis 2,12 */
7ab123
+		  && (insn2 & 0xffff0000) == 0x38420000 /* addi 2,2 */)
7ab123
+		{
7ab123
+		  r_type = R_PPC64_ADDR16_HA;
7ab123
+		  rel->r_info = ELF64_R_INFO (r_symndx, r_type);
7ab123
+		  rel->r_addend -= d_offset;
7ab123
+		  rel[1].r_info = ELF64_R_INFO (r_symndx, R_PPC64_ADDR16_LO);
7ab123
+		  rel[1].r_addend -= d_offset + 4;
7ab123
+		  bfd_put_32 (output_bfd, 0x3c400000, contents + offset);
7ab123
+		}
7ab123
+	    }
7ab123
+	  break;
7ab123
 	}
7ab123
 
7ab123
       /* Handle other relocations that tweak non-addend part of insn.  */