[PATCH] D46076: [PPC64] Replace several endianess checks with abi checks.

Sean Fertile via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 25 12:17:16 PDT 2018


sfertile created this revision.
sfertile added reviewers: syzaara, ruiu, espindola.
Herald added subscribers: kbarton, arichardson, nemanjai, emaste.

There is no limitation that restricts the V2 abi to little endian machines. Rather then checking based on endianess we should be gating behavior based on abi flags.

This cleans up most of the existing checks, but unfortunately the PPC64 target constructor has one such endianess check that comes before we have processed the e_flags and don't know the abi version yet. Since we are working on a patch to remove the remaining V1 abi specific code I've left that check as is for now.


Repository:
  rLLD LLVM Linker

https://reviews.llvm.org/D46076

Files:
  ELF/Arch/PPC64.cpp
  ELF/Target.h


Index: ELF/Target.h
===================================================================
--- ELF/Target.h
+++ ELF/Target.h
@@ -154,6 +154,9 @@
   return getErrorPlace(Loc).Loc;
 }
 
+// Checks for abi version 2 when targeting PPC64.
+bool isPPC64ElfV2();
+
 uint64_t getPPC64TocBase();
 uint64_t getAArch64Page(uint64_t Expr);
 
Index: ELF/Arch/PPC64.cpp
===================================================================
--- ELF/Arch/PPC64.cpp
+++ ELF/Arch/PPC64.cpp
@@ -22,6 +22,8 @@
 
 static uint64_t PPC64TocOffset = 0x8000;
 
+enum { AbiV1 = 1, AbiV2 = 2 };
+
 uint64_t elf::getPPC64TocBase() {
   // The TOC consists of sections .got, .toc, .tocbss, .plt in that order. The
   // TOC starts where the first of these sections starts. We always create a
@@ -36,6 +38,12 @@
   return TocVA + PPC64TocOffset;
 }
 
+bool elf::isPPC64ElfV2() {
+  assert(Config->EMachine == EM_PPC64 &&
+         "Should only be called when targeting PPC64!");
+  return  (Config->EFlags & EF_PPC64_ABI) == AbiV2;
+}
+
 namespace {
 class PPC64 final : public TargetInfo {
 public:
@@ -109,12 +117,12 @@
     if (uint32_t EFlags =
         cast<ObjFile<ELF64BE>>(File)->getObj().getHeader()->e_flags)
       return EFlags;
-    return 1;
+    return AbiV1;
   case ELF64LEKind:
     if (uint32_t EFlags =
         cast<ObjFile<ELF64LE>>(File)->getObj().getHeader()->e_flags)
       return EFlags;
-    return 2;
+    return AbiV2;
   default:
     llvm_unreachable("unknown Config->EKind");
   }
@@ -157,16 +165,16 @@
 }
 
 void PPC64::writeGotHeader(uint8_t *Buf) const {
-  if (Config->EKind == ELF64LEKind)
+  if (isPPC64ElfV2())
     write64(Buf, getPPC64TocBase());
 }
 
 void PPC64::writePlt(uint8_t *Buf, uint64_t GotPltEntryAddr,
                      uint64_t PltEntryAddr, int32_t Index,
                      unsigned RelOff) const {
   uint64_t Off = GotPltEntryAddr - getPPC64TocBase();
 
-  if (Config->EKind == ELF64LEKind) {
+  if (isPPC64ElfV2()) {
     // The most-common form of the plt stub. This assumes that the toc-pointer
     // register is properly initalized, and that the stub must save the toc
     // pointer value to the stack-save slot reserved for it (sp + 24).


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46076.143977.patch
Type: text/x-patch
Size: 2179 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180425/ae50f683/attachment.bin>


More information about the llvm-commits mailing list