[PPC64] Parse -elfv1 -elfv2 when specified on target triple

Summary:
For big-endian powerpc64, the default ABI is ELFv1. OpenPower ABI ELFv2 is supported when -mabi=elfv2 is specified. FreeBSD support for PowerPC64 ELFv2 ABI with LLVM is in progress[1]. This patch adds an alternative way to specify ELFv2 ABI on target triple [2].

The following results are expected:

ELFv1 when using:
-target powerpc64-unknown-freebsd12.0
-target powerpc64-unknown-freebsd12.0 -mabi=elfv1
-target powerpc64-unknown-freebsd12.0-elfv1

ELFv2 when using:
-target powerpc64-unknown-freebsd12.0 -mabi=elfv2
-target powerpc64-unknown-freebsd12.0-elfv2

[1] https://wiki.freebsd.org/powerpc/llvm-elfv2
[2] https://clang.llvm.org/docs/CrossCompilation.html

Patch by Alfredo Dal'Ava Júnior!

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

llvm-svn: 361355
This commit is contained in:
Fangrui Song 2019-05-22 07:29:59 +00:00
parent eec021658b
commit 1c61471ab1
5 changed files with 15 additions and 4 deletions

View File

@ -379,13 +379,11 @@ public:
if ((Triple.getArch() == llvm::Triple::ppc64le)) { if ((Triple.getArch() == llvm::Triple::ppc64le)) {
resetDataLayout("e-m:e-i64:64-n32:64"); resetDataLayout("e-m:e-i64:64-n32:64");
ABI = "elfv2";
} else { } else {
resetDataLayout("E-m:e-i64:64-n32:64"); resetDataLayout("E-m:e-i64:64-n32:64");
ABI = "elfv1";
} }
switch (getTriple().getOS()) { switch (Triple.getOS()) {
case llvm::Triple::FreeBSD: case llvm::Triple::FreeBSD:
LongDoubleWidth = LongDoubleAlign = 64; LongDoubleWidth = LongDoubleAlign = 64;
LongDoubleFormat = &llvm::APFloat::IEEEdouble(); LongDoubleFormat = &llvm::APFloat::IEEEdouble();

View File

@ -202,6 +202,8 @@ public:
CODE16, CODE16,
EABI, EABI,
EABIHF, EABIHF,
ELFv1,
ELFv2,
Android, Android,
Musl, Musl,
MuslEABI, MuslEABI,

View File

@ -228,6 +228,8 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
case CODE16: return "code16"; case CODE16: return "code16";
case EABI: return "eabi"; case EABI: return "eabi";
case EABIHF: return "eabihf"; case EABIHF: return "eabihf";
case ELFv1: return "elfv1";
case ELFv2: return "elfv2";
case Android: return "android"; case Android: return "android";
case Musl: return "musl"; case Musl: return "musl";
case MuslEABI: return "musleabi"; case MuslEABI: return "musleabi";
@ -521,6 +523,8 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
return StringSwitch<Triple::EnvironmentType>(EnvironmentName) return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
.StartsWith("eabihf", Triple::EABIHF) .StartsWith("eabihf", Triple::EABIHF)
.StartsWith("eabi", Triple::EABI) .StartsWith("eabi", Triple::EABI)
.StartsWith("elfv1", Triple::ELFv1)
.StartsWith("elfv2", Triple::ELFv2)
.StartsWith("gnuabin32", Triple::GNUABIN32) .StartsWith("gnuabin32", Triple::GNUABIN32)
.StartsWith("gnuabi64", Triple::GNUABI64) .StartsWith("gnuabi64", Triple::GNUABI64)
.StartsWith("gnueabihf", Triple::GNUEABIHF) .StartsWith("gnueabihf", Triple::GNUEABIHF)

View File

@ -214,6 +214,8 @@ static PPCTargetMachine::PPCABI computeTargetABI(const Triple &TT,
case Triple::ppc64le: case Triple::ppc64le:
return PPCTargetMachine::PPC_ABI_ELFv2; return PPCTargetMachine::PPC_ABI_ELFv2;
case Triple::ppc64: case Triple::ppc64:
if (TT.getEnvironment() == llvm::Triple::ELFv2)
return PPCTargetMachine::PPC_ABI_ELFv2;
return PPCTargetMachine::PPC_ABI_ELFv1; return PPCTargetMachine::PPC_ABI_ELFv1;
default: default:
return PPCTargetMachine::PPC_ABI_UNKNOWN; return PPCTargetMachine::PPC_ABI_UNKNOWN;

View File

@ -5,6 +5,11 @@
; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1
; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2 ; RUN: llc -verify-machineinstrs -mtriple=powerpc64le-unknown-linux-gnu -target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd < %s | FileCheck %s -check-prefix=CHECK-ELFv1
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd -target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd -target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd-elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd-elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2
; CHECK-ELFv2: .abiversion 2 ; CHECK-ELFv2: .abiversion 2
; CHECK-ELFv1-NOT: .abiversion 2 ; CHECK-ELFv1-NOT: .abiversion 2