Skip to content

Commit 8edf759

Browse files
committed
[PowerPC][Triple] Use elfv2 on freebsd>=13 and linux-musl
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
1 parent fb6e80d commit 8edf759

File tree

8 files changed

+20
-13
lines changed

8 files changed

+20
-13
lines changed

clang/lib/Basic/Targets/PPC.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ class LLVM_LIBRARY_VISIBILITY PPC64TargetInfo : public PPCTargetInfo {
390390
ABI = "elfv2";
391391
} else {
392392
resetDataLayout("E-m:e-i64:64-n32:64");
393-
ABI = Triple.getEnvironment() == llvm::Triple::ELFv2 ? "elfv2" : "elfv1";
393+
ABI = "elfv1";
394394
}
395395

396396
if (Triple.getOS() == llvm::Triple::AIX)

clang/lib/Driver/ToolChains/Clang.cpp

+7-2
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,8 @@ void Clang::AddPPCTargetArgs(const ArgList &Args,
19001900
ArgStringList &CmdArgs) const {
19011901
// Select the ABI to use.
19021902
const char *ABIName = nullptr;
1903-
if (getToolChain().getTriple().isOSLinux())
1903+
const llvm::Triple &T = getToolChain().getTriple();
1904+
if (T.isOSBinFormatELF()) {
19041905
switch (getToolChain().getArch()) {
19051906
case llvm::Triple::ppc64: {
19061907
// When targeting a processor that supports QPX, or if QPX is
@@ -1915,7 +1916,10 @@ void Clang::AddPPCTargetArgs(const ArgList &Args,
19151916
break;
19161917
}
19171918

1918-
ABIName = "elfv1";
1919+
if (T.isMusl() || (T.isOSFreeBSD() && T.getOSMajorVersion() >= 13))
1920+
ABIName = "elfv2";
1921+
else
1922+
ABIName = "elfv1";
19191923
break;
19201924
}
19211925
case llvm::Triple::ppc64le:
@@ -1924,6 +1928,7 @@ void Clang::AddPPCTargetArgs(const ArgList &Args,
19241928
default:
19251929
break;
19261930
}
1931+
}
19271932

19281933
bool IEEELongDouble = false;
19291934
for (const Arg *A : Args.filtered(options::OPT_mabi_EQ)) {

clang/test/Driver/ppc-abi.c

+6
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@
2424
// RUN: %clang -target powerpc64le-unknown-linux-gnu %s -### -o %t.o 2>&1 \
2525
// RUN: -mabi=altivec | FileCheck -check-prefix=CHECK-ELFv2 %s
2626

27+
// RUN: %clang -target powerpc64-unknown-freebsd11 %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv1 %s
28+
// RUN: %clang -target powerpc64-unknown-freebsd12 %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv1 %s
29+
// RUN: %clang -target powerpc64-unknown-freebsd13 %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv2-BE %s
30+
// RUN: %clang -target powerpc64-unknown-freebsd14 %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv2-BE %s
31+
// RUN: %clang -target powerpc64-linux-musl %s -### 2>&1 | FileCheck --check-prefix=CHECK-ELFv2-BE %s
32+
2733
// CHECK-ELFv1: "-mrelocation-model" "pic" "-pic-level" "2"
2834
// CHECK-ELFv1: "-target-abi" "elfv1"
2935
// CHECK-ELFv1-LE: "-mrelocation-model" "static"

clang/test/Preprocessor/init-ppc64.c

+6
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,12 @@
10561056
// 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
10571057
// 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
10581058
// 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
1059+
1060+
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd11 -target-abi elfv1 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv1 %s
1061+
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd12 -target-abi elfv1 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv1 %s
1062+
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-unknown-freebsd13 -target-abi elfv2 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv2 %s
1063+
// RUN: %clang_cc1 -E -dM -ffreestanding -triple=powerpc64-linux-musl -target-abi elfv2 -xc /dev/null | FileCheck --check-prefix=PPC64-ELFv2 %s
1064+
10591065
// PPC64-ELFv1:#define _CALL_ELF 1
10601066
// PPC64-ELFv2:#define _CALL_ELF 2
10611067
//

llvm/include/llvm/ADT/Triple.h

-2
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,6 @@ class Triple {
203203
CODE16,
204204
EABI,
205205
EABIHF,
206-
ELFv1,
207-
ELFv2,
208206
Android,
209207
Musl,
210208
MuslEABI,

llvm/lib/Support/Triple.cpp

-4
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,6 @@ StringRef Triple::getEnvironmentTypeName(EnvironmentType Kind) {
228228
case CODE16: return "code16";
229229
case EABI: return "eabi";
230230
case EABIHF: return "eabihf";
231-
case ELFv1: return "elfv1";
232-
case ELFv2: return "elfv2";
233231
case Android: return "android";
234232
case Musl: return "musl";
235233
case MuslEABI: return "musleabi";
@@ -524,8 +522,6 @@ static Triple::EnvironmentType parseEnvironment(StringRef EnvironmentName) {
524522
return StringSwitch<Triple::EnvironmentType>(EnvironmentName)
525523
.StartsWith("eabihf", Triple::EABIHF)
526524
.StartsWith("eabi", Triple::EABI)
527-
.StartsWith("elfv1", Triple::ELFv1)
528-
.StartsWith("elfv2", Triple::ELFv2)
529525
.StartsWith("gnuabin32", Triple::GNUABIN32)
530526
.StartsWith("gnuabi64", Triple::GNUABI64)
531527
.StartsWith("gnueabihf", Triple::GNUEABIHF)

llvm/lib/Target/PowerPC/PPCTargetMachine.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,6 @@ static PPCTargetMachine::PPCABI computeTargetABI(const Triple &TT,
215215
case Triple::ppc64le:
216216
return PPCTargetMachine::PPC_ABI_ELFv2;
217217
case Triple::ppc64:
218-
if (TT.getEnvironment() == llvm::Triple::ELFv2)
219-
return PPCTargetMachine::PPC_ABI_ELFv2;
220218
return PPCTargetMachine::PPC_ABI_ELFv1;
221219
default:
222220
return PPCTargetMachine::PPC_ABI_UNKNOWN;

llvm/test/CodeGen/PowerPC/ppc64-elf-abi.ll

-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd < %s | FileCheck %s -check-prefix=CHECK-ELFv1
99
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd -target-abi elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1
1010
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd -target-abi elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2
11-
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd-elfv1 < %s | FileCheck %s -check-prefix=CHECK-ELFv1
12-
; RUN: llc -verify-machineinstrs -mtriple=powerpc64-unknown-freebsd-elfv2 < %s | FileCheck %s -check-prefix=CHECK-ELFv2
1311

1412
; CHECK-ELFv2: .abiversion 2
1513
; CHECK-ELFv1-NOT: .abiversion 2

0 commit comments

Comments
 (0)