[ELF][PPC64] Rename some PPC64 ELFv2 specific RelExpr from R_PPC_* to R_PPC64_*

The following abstract relocation types (RelExpr) are PPC64 ELFv2 ABI specific,
not used by PPC32. So rename them to prevent confusion when the PPC32 port is improved.

* R_PPC_CALL R_PPC_CALL_PLT:
  R_PPC_CALL_PLT represents R_PPC64_REL14 and R_PPC64_REL24.
  If the function is not preemptable, R_PPC_CALL_PLT can be optimized to R_PPC_CALL:
  the formula adjusts the symbol VA from the global entry point to the local entry point.
* R_PPC_TOC: represents R_PPC64_TOC.  We don't have a test. Add one to ppc64-relocs.s
  Rename it to R_PPC64_TOCBASE because `@tocbase` is the assembly form.

Reviewed By: ruiu

Differential Revision: https://reviews.llvm.org/D62800

git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@362359 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/ELF/Arch/PPC64.cpp b/ELF/Arch/PPC64.cpp
index a79e9c8..9e2543e 100644
--- a/ELF/Arch/PPC64.cpp
+++ b/ELF/Arch/PPC64.cpp
@@ -545,10 +545,10 @@
   case R_PPC64_TOC16_LO_DS:
     return Config->TocOptimize ? R_PPC64_RELAX_TOC : R_GOTREL;
   case R_PPC64_TOC:
-    return R_PPC_TOC;
+    return R_PPC64_TOCBASE;
   case R_PPC64_REL14:
   case R_PPC64_REL24:
-    return R_PPC_CALL_PLT;
+    return R_PPC64_CALL_PLT;
   case R_PPC64_REL16_LO:
   case R_PPC64_REL16_HA:
   case R_PPC64_REL32:
diff --git a/ELF/InputSection.cpp b/ELF/InputSection.cpp
index 45bafd3..74a8028 100644
--- a/ELF/InputSection.cpp
+++ b/ELF/InputSection.cpp
@@ -717,9 +717,9 @@
   case R_PLT:
     return Sym.getPltVA() + A;
   case R_PLT_PC:
-  case R_PPC_CALL_PLT:
+  case R_PPC64_CALL_PLT:
     return Sym.getPltVA() + A - P;
-  case R_PPC_CALL: {
+  case R_PPC64_CALL: {
     uint64_t SymVA = Sym.getVA(A);
     // If we have an undefined weak symbol, we might get here with a symbol
     // address of zero. That could overflow, but the code must be unreachable,
@@ -735,7 +735,7 @@
     // branching to the local entry point.
     return SymVA - P + getPPC64GlobalEntryToLocalEntryOffset(Sym.StOther);
   }
-  case R_PPC_TOC:
+  case R_PPC64_TOCBASE:
     return getPPC64TocBase() + A;
   case R_RELAX_GOT_PC:
     return Sym.getVA(A) - P;
@@ -922,7 +922,7 @@
     case R_RELAX_TLS_GD_TO_IE_GOTPLT:
       Target->relaxTlsGdToIe(BufLoc, Type, TargetVA);
       break;
-    case R_PPC_CALL:
+    case R_PPC64_CALL:
       // If this is a call to __tls_get_addr, it may be part of a TLS
       // sequence that has been relaxed and turned into a nop. In this
       // case, we don't want to handle it as a call.
diff --git a/ELF/Relocations.cpp b/ELF/Relocations.cpp
index fe10234..5f1149a 100644
--- a/ELF/Relocations.cpp
+++ b/ELF/Relocations.cpp
@@ -363,7 +363,7 @@
 
 // Returns true if Expr refers a PLT entry.
 static bool needsPlt(RelExpr Expr) {
-  return oneof<R_PLT_PC, R_PPC_CALL_PLT, R_PLT>(Expr);
+  return oneof<R_PLT_PC, R_PPC64_CALL_PLT, R_PLT>(Expr);
 }
 
 // Returns true if Expr refers a GOT entry. Note that this function
@@ -378,8 +378,9 @@
 // True if this expression is of the form Sym - X, where X is a position in the
 // file (PC, or GOT for example).
 static bool isRelExpr(RelExpr Expr) {
-  return oneof<R_PC, R_GOTREL, R_GOTPLTREL, R_MIPS_GOTREL, R_PPC_CALL,
-               R_PPC64_RELAX_TOC, R_PPC_CALL_PLT, R_AARCH64_PAGE_PC, R_RELAX_GOT_PC>(Expr);
+  return oneof<R_PC, R_GOTREL, R_GOTPLTREL, R_MIPS_GOTREL, R_PPC64_CALL,
+               R_PPC64_CALL_PLT, R_PPC64_RELAX_TOC, R_AARCH64_PAGE_PC,
+               R_RELAX_GOT_PC>(Expr);
 }
 
 // Returns true if a given relocation can be computed at link-time.
@@ -398,7 +399,7 @@
             R_MIPS_GOT_LOCAL_PAGE, R_MIPS_GOTREL, R_MIPS_GOT_OFF,
             R_MIPS_GOT_OFF32, R_MIPS_GOT_GP_PC, R_MIPS_TLSGD,
             R_AARCH64_GOT_PAGE_PC, R_GOT_PC, R_GOTONLY_PC, R_GOTPLTONLY_PC,
-            R_PLT_PC, R_TLSGD_GOT, R_TLSGD_GOTPLT, R_TLSGD_PC, R_PPC_CALL_PLT,
+            R_PLT_PC, R_TLSGD_GOT, R_TLSGD_GOTPLT, R_TLSGD_PC, R_PPC64_CALL_PLT,
             R_PPC64_RELAX_TOC, R_TLSDESC_CALL, R_TLSDESC_PC,
             R_AARCH64_TLSDESC_PAGE, R_HINT, R_TLSLD_HINT, R_TLSIE_HINT>(E))
     return true;
@@ -452,8 +453,8 @@
 
 static RelExpr toPlt(RelExpr Expr) {
   switch (Expr) {
-  case R_PPC_CALL:
-    return R_PPC_CALL_PLT;
+  case R_PPC64_CALL:
+    return R_PPC64_CALL_PLT;
   case R_PC:
     return R_PLT_PC;
   case R_ABS:
@@ -469,8 +470,8 @@
   switch (Expr) {
   case R_PLT_PC:
     return R_PC;
-  case R_PPC_CALL_PLT:
-    return R_PPC_CALL;
+  case R_PPC64_CALL_PLT:
+    return R_PPC64_CALL;
   case R_PLT:
     return R_ABS;
   default:
@@ -1125,7 +1126,8 @@
   // The 4 types that relative GOTPLT are all x86 and x86-64 specific.
   if (oneof<R_GOTPLTONLY_PC, R_GOTPLTREL, R_GOTPLT, R_TLSGD_GOTPLT>(Expr)) {
     In.GotPlt->HasGotPltOffRel = true;
-  } else if (oneof<R_GOTONLY_PC, R_GOTREL, R_PPC_TOC, R_PPC64_RELAX_TOC>(Expr)) {
+  } else if (oneof<R_GOTONLY_PC, R_GOTREL, R_PPC64_TOCBASE, R_PPC64_RELAX_TOC>(
+                 Expr)) {
     In.Got->HasGotOffRel = true;
   }
 
diff --git a/ELF/Relocations.h b/ELF/Relocations.h
index 00156f5..064feb0 100644
--- a/ELF/Relocations.h
+++ b/ELF/Relocations.h
@@ -91,10 +91,10 @@
   R_MIPS_GOT_OFF32,
   R_MIPS_TLSGD,
   R_MIPS_TLSLD,
-  R_PPC_CALL,
-  R_PPC_CALL_PLT,
-  R_PPC_TOC,
+  R_PPC64_CALL,
+  R_PPC64_CALL_PLT,
   R_PPC64_RELAX_TOC,
+  R_PPC64_TOCBASE,
   R_RISCV_PC_INDIRECT,
 };
 
diff --git a/test/ELF/ppc64-relocs.s b/test/ELF/ppc64-relocs.s
index 1804db9..5e8c529 100644
--- a/test/ELF/ppc64-relocs.s
+++ b/test/ELF/ppc64-relocs.s
@@ -2,12 +2,12 @@
 
 # RUN: llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux %s -o %t.o
 # RUN: ld.lld --no-toc-optimize %t.o -o %t
-# RUN: llvm-readelf -x .rodata -x .eh_frame %t | FileCheck %s --check-prefix=DATALE
+# RUN: llvm-readelf -x .rodata -x .R_PPC64_TOC -x .eh_frame %t | FileCheck %s --check-prefix=DATALE
 # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
 
 # RUN: llvm-mc -filetype=obj -triple=powerpc64-unknown-linux %s -o %t.o
 # RUN: ld.lld --no-toc-optimize %t.o -o %t
-# RUN: llvm-readelf -x .rodata -x .eh_frame %t | FileCheck %s --check-prefix=DATABE
+# RUN: llvm-readelf -x .rodata -x .R_PPC64_TOC -x .eh_frame %t | FileCheck %s --check-prefix=DATABE
 # RUN: llvm-objdump -d --no-show-raw-insn %t | FileCheck %s
 
 .text
@@ -139,14 +139,26 @@
 __foo:
   li 3,0
 
+.section .R_PPC64_TOC,"a",@progbits
+  .quad .TOC.@tocbase
+
+# SEC: .got PROGBITS 0000000010020000
+
+## tocbase = .got+0x8000 = 0x10028000
+# DATALE-LABEL: section '.R_PPC64_TOC':
+# DATALE: 00800210 00000000
+
+# DATABE-LABEL: section '.R_PPC64_TOC':
+# DATABE: 00000000 10028000
+
 # Check that the personality (relocated by R_PPC64_REL64) in the .eh_frame
 # equals the address of __foo.
-# 0x100001e2 + 0x76fe = 0x10010058
+# 0x100001ea + 0xfe6e = 0x10010058
 # DATALE: section '.eh_frame':
-# DATALE: 0x100001e0 {{....}}76fe
+# DATALE: 0x100001e8 {{....}}6efe
 
 # DATABE: section '.eh_frame':
-# DATABE: 0x100001e0 {{[0-9a-f]+ [0-9a-f]+}} fe76{{....}}
+# DATABE: 0x100001e8 {{[0-9a-f]+ [0-9a-f]+}} fe6e{{....}}
 
 # CHECK: __foo
 # CHECK-NEXT: 10010058:       li 3, 0