Skip to content

Commit

Permalink
[PowerPC][Triple] Use elfv2 on freebsd>=13 and linux-musl
Browse files Browse the repository at this point in the history
Summary:
Every powerpc64le platform uses elfv2.

For powerpc64, the environments "elfv1" and "elfv2" were added for
FreeBSD ELFv1->ELFv2 migration in D61950.  FreeBSD developers have
decided to use OS versions to select ABI, and no one is relying on the
environments.

Also use elfv2 on powerpc64-linux-musl.

Users can always use -mabi=elfv1 and -mabi=elfv2 to override the default
ABI.

Reviewed By: adalava

Differential Revision: https://reviews.llvm.org/D72352
  • Loading branch information
MaskRay committed Jan 7, 2020
1 parent fb6e80d commit 8edf759
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 13 deletions.
2 changes: 1 addition & 1 deletion clang/lib/Basic/Targets/PPC.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ class LLVM_LIBRARY_VISIBILITY PPC64TargetInfo : public PPCTargetInfo {
ABI = "elfv2";
} else {
resetDataLayout("E-m:e-i64:64-n32:64");
ABI = Triple.getEnvironment() == llvm::Triple::ELFv2 ? "elfv2" : "elfv1";
ABI = "elfv1";
}

if (Triple.getOS() == llvm::Triple::AIX)
Expand Down
9 changes: 7 additions & 2 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1900,7 +1900,8 @@ void Clang::AddPPCTargetArgs(const ArgList &Args,
ArgStringList &CmdArgs) const {
// Select the ABI to use.
const char *ABIName = nullptr;
if (getToolChain().getTriple().isOSLinux())
const llvm::Triple &T = getToolChain().getTriple();
if (T.isOSBinFormatELF()) {
switch (getToolChain().getArch()) {
case llvm::Triple::ppc64: {
// When targeting a processor that supports QPX, or if QPX is
Expand All @@ -1915,7 +1916,10 @@ void Clang::AddPPCTargetArgs(const ArgList &Args,
break;
}

ABIName = "elfv1";
if (T.isMusl() || (T.isOSFreeBSD() && T.getOSMajorVersion() >= 13))
ABIName = "elfv2";
else
ABIName = "elfv1";
break;
}
case llvm::Triple::ppc64le:
Expand All @@ -1924,6 +1928,7 @@ void Clang::AddPPCTargetArgs(const ArgList &Args,
default:
break;
}
}

bool IEEELongDouble = false;
for (const Arg *A : Args.filtered(options::OPT_mabi_EQ)) {
Expand Down
6 changes: 6 additions & 0 deletions clang/test/Driver/ppc-abi.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
// RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
// RUN: -mabi=altivec | FileCheck -check-prefix=CHECK-ELFv2 %s

// RUN: %clang -target powerpc64-unknown-freebsd11 %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv1 %s
// RUN: %clang -target powerpc64-unknown-freebsd12 %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv1 %s
// RUN: %clang -target powerpc64-unknown-freebsd13 %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv2-BE %s
// RUN: %clang -target powerpc64-unknown-freebsd14 %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv2-BE %s
// RUN: %clang -target powerpc64-linux-musl %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv2-BE %s

// CHECK-ELFv1: "-mrelocation-model" "pic" "-pic-level" "2"
// CHECK-ELFv1: "-target-abi" "elfv1"
// CHECK-ELFv1-LE: "-mrelocation-model" "static"
Expand Down
6 changes: 6 additions & 0 deletions clang/test/Preprocessor/init-ppc64.c
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,12 @@
// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64le-unknown-linux-gnu < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv2 %s
// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64le-unknown-linux-gnu -target-abi elfv1 < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv1 %s
// RUN: %clang_cc1 -E -dM -ffreestanding -fgnuc-version=4.2.1 -triple=powerpc64le-unknown-linux-gnu -target-abi elfv2 < /dev/null | FileCheck -match-full-lines -check-prefix PPC64-ELFv2 %s

// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd11 -target-abi elfv1 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv1 %s
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd12 -target-abi elfv1 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv1 %s
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd13 -target-abi elfv2 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv2 %s
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-linux-musl -target-abi elfv2 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv2 %s

// PPC64-ELFv1:#define _CALL_ELF 1
// PPC64-ELFv2:#define _CALL_ELF 2
//
Expand Down
2 changes: 0 additions & 2 deletions llvm/include/llvm/ADT/Triple.h
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,6 @@ class Triple {
CODE16,
EABI,
EABIHF,
ELFv1,
ELFv2,
Android,
Musl,
MuslEABI,
Expand Down
4 changes: 0 additions & 4 deletions llvm/lib/Support/Triple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,6 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
case CODE16: return "code16";
case EABI: return "eabi";
case EABIHF: return "eabihf";
case ELFv1: return "elfv1";
case ELFv2: return "elfv2";
case Android: return "android";
case Musl: return "musl";
case MuslEABI: return "musleabi";
Expand Down Expand Up @@ -524,8 +522,6 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
.StartsWith("eabihf", Triple::EABIHF)
.StartsWith("eabi", Triple::EABI)
.StartsWith("elfv1", Triple::ELFv1)
.StartsWith("elfv2", Triple::ELFv2)
.StartsWith("gnuabin32", Triple::GNUABIN32)
.StartsWith("gnuabi64", Triple::GNUABI64)
.StartsWith("gnueabihf", Triple::GNUEABIHF)
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/Target/PowerPC/PPCTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,8 +215,6 @@ static PPCTargetMachine::PPCABI computeTargetABI(const Triple &TT,
case Triple::ppc64le:
return PPCTargetMachine::PPC_ABI_ELFv2;
case Triple::ppc64:
if (TT.getEnvironment() == llvm::Triple::ELFv2)
return PPCTargetMachine::PPC_ABI_ELFv2;
return PPCTargetMachine::PPC_ABI_ELFv1;
default:
return PPCTargetMachine::PPC_ABI_UNKNOWN;
Expand Down
2 changes: 0 additions & 2 deletions llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
; 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-ELFv1-NOT: .abiversion 2

0 comments on commit 8edf759

Please sign in to comment.