[lld] r336372 - Simplify PPC64::calcEFlags().

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 5 09:58:42 PDT 2018


Author: ruiu
Date: Thu Jul  5 09:58:42 2018
New Revision: 336372

URL: http://llvm.org/viewvc/llvm-project?rev=336372&view=rev
Log:
Simplify PPC64::calcEFlags().

In this file we only have to handle the v2 ABI, so what we need to do
is to just make sure that all object files have v2 or unspecified version
number.

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

Added:
    lld/trunk/test/ELF/ppc64-abi-version.s
Modified:
    lld/trunk/ELF/Arch/PPC64.cpp

Modified: lld/trunk/ELF/Arch/PPC64.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Arch/PPC64.cpp?rev=336372&r1=336371&r2=336372&view=diff
==============================================================================
--- lld/trunk/ELF/Arch/PPC64.cpp (original)
+++ lld/trunk/ELF/Arch/PPC64.cpp Thu Jul  5 09:58:42 2018
@@ -111,52 +111,21 @@ PPC64::PPC64() {
 }
 
 static uint32_t getEFlags(InputFile *File) {
-  // Get the e_flag from the input file and issue an error if incompatible
-  // e_flag encountered.
-  uint32_t EFlags;
-  switch (Config->EKind) {
-  case ELF64BEKind:
-    EFlags = cast<ObjFile<ELF64BE>>(File)->getObj().getHeader()->e_flags;
-    break;
-  case ELF64LEKind:
-    EFlags = cast<ObjFile<ELF64LE>>(File)->getObj().getHeader()->e_flags;
-    break;
-  default:
-    llvm_unreachable("unknown Config->EKind");
-  }
-  if (EFlags > 2) {
-    error("incompatible e_flags: " +  toString(File));
-    return 0;
-  }
-  return EFlags;
+  if (Config->EKind == ELF64BEKind)
+    return cast<ObjFile<ELF64BE>>(File)->getObj().getHeader()->e_flags;
+  return cast<ObjFile<ELF64LE>>(File)->getObj().getHeader()->e_flags;
 }
 
+// This file implements v2 ABI. This function makes sure that all
+// object files have v2 or an unspecified version as an ABI version.
 uint32_t PPC64::calcEFlags() const {
-  assert(!ObjectFiles.empty());
-
-  uint32_t NonZeroFlag;
-  for (InputFile *F : makeArrayRef(ObjectFiles)) {
-    NonZeroFlag = getEFlags(F);
-    if (NonZeroFlag)
-      break;
-  }
-
-  // Verify that all input files have either the same e_flags, or zero.
   for (InputFile *F : makeArrayRef(ObjectFiles)) {
     uint32_t Flag = getEFlags(F);
-    if (Flag == 0 || Flag == NonZeroFlag)
-      continue;
-    error(toString(F) + ": ABI version " + Twine(Flag) +
-          " is not compatible with ABI version " + Twine(NonZeroFlag) +
-          " output");
-    return 0;
-  }
-
-  if (NonZeroFlag == 1) {
-    error("PPC64 V1 ABI not supported");
-    return 0;
+    if (Flag == 1)
+      error(toString(F) + ": ABI version 1 is not supported");
+    else if (Flag > 2)
+      error(toString(F) + ": unrecognized e_flags: " + Twine(Flag));
   }
-
   return 2;
 }
 

Added: lld/trunk/test/ELF/ppc64-abi-version.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/ppc64-abi-version.s?rev=336372&view=auto
==============================================================================
--- lld/trunk/test/ELF/ppc64-abi-version.s (added)
+++ lld/trunk/test/ELF/ppc64-abi-version.s Thu Jul  5 09:58:42 2018
@@ -0,0 +1,11 @@
+# REQUIRES: ppc
+
+# RUN: echo '.abiversion 1' | llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux - -o %t1.o
+# RUN: not ld.lld -o /dev/null %t1.o 2>&1 | FileCheck -check-prefix=ERR1 %s
+
+# ERR1: ABI version 1 is not supported
+
+# RUN: echo '.abiversion 3' | llvm-mc -filetype=obj -triple=powerpc64le-unknown-linux - -o %t1.o
+# RUN: not ld.lld -o /dev/null %t1.o 2>&1 | FileCheck -check-prefix=ERR2 %s
+
+# ERR2: unrecognized e_flags: 3




More information about the llvm-commits mailing list