Skip to content

Commit 21ed37e

Browse files
mgornytru
authored andcommitted
[LLVM] [Clang] Backport "Support for Gentoo *t64 triples (64-bit time_t ABIs)"
This is a backport of 387b37a for 19.x, adjusted to add new Triple::EnvironmentType members at the end to avoid breaking backwards ABI compatibility. Gentoo is planning to introduce a `*t64` suffix for triples that will be used by 32-bit platforms that use 64-bit `time_t`. Add support for parsing and accepting these triples, and while at it make clang automatically enable the necessary glibc feature macros when this suffix is used.
1 parent 19c571a commit 21ed37e

File tree

16 files changed

+138
-12
lines changed

16 files changed

+138
-12
lines changed

clang/lib/Basic/Targets/ARM.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,9 @@ ARMTargetInfo::ARMTargetInfo(const llvm::Triple &Triple,
311311
switch (Triple.getEnvironment()) {
312312
case llvm::Triple::Android:
313313
case llvm::Triple::GNUEABI:
314+
case llvm::Triple::GNUEABIT64:
314315
case llvm::Triple::GNUEABIHF:
316+
case llvm::Triple::GNUEABIHFT64:
315317
case llvm::Triple::MuslEABI:
316318
case llvm::Triple::MuslEABIHF:
317319
case llvm::Triple::OpenHOS:

clang/lib/Basic/Targets/OSTargets.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,10 @@ class LLVM_LIBRARY_VISIBILITY LinuxTargetInfo : public OSTargetInfo<Target> {
337337
Builder.defineMacro("_GNU_SOURCE");
338338
if (this->HasFloat128)
339339
Builder.defineMacro("__FLOAT128__");
340+
if (Triple.isTime64ABI()) {
341+
Builder.defineMacro("_FILE_OFFSET_BITS", "64");
342+
Builder.defineMacro("_TIME_BITS", "64");
343+
}
340344
}
341345

342346
public:

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,7 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
177177
else if (ABIStr == "aapcs16")
178178
Kind = ARMABIKind::AAPCS16_VFP;
179179
else if (CodeGenOpts.FloatABI == "hard" ||
180-
(CodeGenOpts.FloatABI != "soft" &&
181-
(Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||
182-
Triple.getEnvironment() == llvm::Triple::MuslEABIHF ||
183-
Triple.getEnvironment() == llvm::Triple::EABIHF)))
180+
(CodeGenOpts.FloatABI != "soft" && Triple.isHardFloatABI()))
184181
Kind = ARMABIKind::AAPCS_VFP;
185182

186183
return createARMTargetCodeGenInfo(CGM, Kind);

clang/lib/CodeGen/Targets/ARM.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ class ARMABIInfo : public ABIInfo {
3535
case llvm::Triple::EABI:
3636
case llvm::Triple::EABIHF:
3737
case llvm::Triple::GNUEABI:
38+
case llvm::Triple::GNUEABIT64:
3839
case llvm::Triple::GNUEABIHF:
40+
case llvm::Triple::GNUEABIHFT64:
3941
case llvm::Triple::MuslEABI:
4042
case llvm::Triple::MuslEABIHF:
4143
return true;
@@ -48,6 +50,7 @@ class ARMABIInfo : public ABIInfo {
4850
switch (getTarget().getTriple().getEnvironment()) {
4951
case llvm::Triple::EABIHF:
5052
case llvm::Triple::GNUEABIHF:
53+
case llvm::Triple::GNUEABIHFT64:
5154
case llvm::Triple::MuslEABIHF:
5255
return true;
5356
default:

clang/lib/Driver/Driver.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,8 @@ static llvm::Triple computeTargetTriple(const Driver &D,
602602
if (A->getOption().matches(options::OPT_m64) ||
603603
A->getOption().matches(options::OPT_maix64)) {
604604
AT = Target.get64BitArchVariant().getArch();
605-
if (Target.getEnvironment() == llvm::Triple::GNUX32)
605+
if (Target.getEnvironment() == llvm::Triple::GNUX32 ||
606+
Target.getEnvironment() == llvm::Triple::GNUT64)
606607
Target.setEnvironment(llvm::Triple::GNU);
607608
else if (Target.getEnvironment() == llvm::Triple::MuslX32)
608609
Target.setEnvironment(llvm::Triple::Musl);
@@ -665,11 +666,13 @@ static llvm::Triple computeTargetTriple(const Driver &D,
665666
} else if (ABIName == "n32") {
666667
Target = Target.get64BitArchVariant();
667668
if (Target.getEnvironment() == llvm::Triple::GNU ||
669+
Target.getEnvironment() == llvm::Triple::GNUT64 ||
668670
Target.getEnvironment() == llvm::Triple::GNUABI64)
669671
Target.setEnvironment(llvm::Triple::GNUABIN32);
670672
} else if (ABIName == "64") {
671673
Target = Target.get64BitArchVariant();
672674
if (Target.getEnvironment() == llvm::Triple::GNU ||
675+
Target.getEnvironment() == llvm::Triple::GNUT64 ||
673676
Target.getEnvironment() == llvm::Triple::GNUABIN32)
674677
Target.setEnvironment(llvm::Triple::GNUABI64);
675678
}

clang/lib/Driver/ToolChains/Arch/ARM.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,11 @@ void arm::setFloatABIInTriple(const Driver &D, const ArgList &Args,
327327
Triple.setEnvironment(isHardFloat ? llvm::Triple::GNUEABIHF
328328
: llvm::Triple::GNUEABI);
329329
break;
330+
case llvm::Triple::GNUEABIT64:
331+
case llvm::Triple::GNUEABIHFT64:
332+
Triple.setEnvironment(isHardFloat ? llvm::Triple::GNUEABIHFT64
333+
: llvm::Triple::GNUEABIT64);
334+
break;
330335
case llvm::Triple::EABI:
331336
case llvm::Triple::EABIHF:
332337
Triple.setEnvironment(isHardFloat ? llvm::Triple::EABIHF
@@ -414,10 +419,12 @@ arm::FloatABI arm::getDefaultFloatABI(const llvm::Triple &Triple) {
414419
return FloatABI::Soft;
415420
switch (Triple.getEnvironment()) {
416421
case llvm::Triple::GNUEABIHF:
422+
case llvm::Triple::GNUEABIHFT64:
417423
case llvm::Triple::MuslEABIHF:
418424
case llvm::Triple::EABIHF:
419425
return FloatABI::Hard;
420426
case llvm::Triple::GNUEABI:
427+
case llvm::Triple::GNUEABIT64:
421428
case llvm::Triple::MuslEABI:
422429
case llvm::Triple::EABI:
423430
// EABI is always AAPCS, and if it was not marked 'hard', it's softfp

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2694,6 +2694,7 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
26942694
case llvm::Triple::thumb:
26952695
LibDirs.append(begin(ARMLibDirs), end(ARMLibDirs));
26962696
if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF ||
2697+
TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHFT64 ||
26972698
TargetTriple.getEnvironment() == llvm::Triple::MuslEABIHF ||
26982699
TargetTriple.getEnvironment() == llvm::Triple::EABIHF) {
26992700
TripleAliases.append(begin(ARMHFTriples), end(ARMHFTriples));
@@ -2705,6 +2706,7 @@ void Generic_GCC::GCCInstallationDetector::AddDefaultGCCPrefixes(
27052706
case llvm::Triple::thumbeb:
27062707
LibDirs.append(begin(ARMebLibDirs), end(ARMebLibDirs));
27072708
if (TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHF ||
2709+
TargetTriple.getEnvironment() == llvm::Triple::GNUEABIHFT64 ||
27082710
TargetTriple.getEnvironment() == llvm::Triple::MuslEABIHF ||
27092711
TargetTriple.getEnvironment() == llvm::Triple::EABIHF) {
27102712
TripleAliases.append(begin(ARMebHFTriples), end(ARMebHFTriples));

clang/lib/Driver/ToolChains/Linux.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,7 @@ std::string Linux::getDynamicLinker(const ArgList &Args) const {
508508
case llvm::Triple::thumbeb: {
509509
const bool HF =
510510
Triple.getEnvironment() == llvm::Triple::GNUEABIHF ||
511+
Triple.getEnvironment() == llvm::Triple::GNUEABIHFT64 ||
511512
tools::arm::getARMFloatABI(*this, Args) == tools::arm::FloatABI::Hard;
512513

513514
LibDir = "lib";

clang/test/Preprocessor/time64.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %clang_cc1 -E -dM -triple=i686-pc-linux-gnu /dev/null | FileCheck -match-full-lines -check-prefix TIME32 %s
2+
// RUN: %clang_cc1 -E -dM -triple=i686-pc-linux-gnut64 /dev/null | FileCheck -match-full-lines -check-prefix TIME64 %s
3+
// RUN: %clang_cc1 -E -dM -triple=armv5tel-softfloat-linux-gnueabi /dev/null | FileCheck -match-full-lines -check-prefix TIME32 %s
4+
// RUN: %clang_cc1 -E -dM -triple=armv5tel-softfloat-linux-gnueabit64 /dev/null | FileCheck -match-full-lines -check-prefix TIME64 %s
5+
// RUN: %clang_cc1 -E -dM -triple=armv7a-unknown-linux-gnueabihf /dev/null | FileCheck -match-full-lines -check-prefix TIME32 %s
6+
// RUN: %clang_cc1 -E -dM -triple=armv7a-unknown-linux-gnueabihft64 /dev/null | FileCheck -match-full-lines -check-prefix TIME64 %s
7+
//
8+
// TIME32-NOT:#define _FILE_OFFSET_BITS 64
9+
// TIME32-NOT:#define _TIME_BITS 64
10+
//
11+
// TIME64:#define _FILE_OFFSET_BITS 64
12+
// TIME64:#define _TIME_BITS 64

llvm/include/llvm/TargetParser/Triple.h

Lines changed: 29 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,11 @@ class Triple {
294294

295295
PAuthTest,
296296

297-
LastEnvironmentType = PAuthTest
297+
GNUT64,
298+
GNUEABIT64,
299+
GNUEABIHFT64,
300+
301+
LastEnvironmentType = GNUEABIHFT64
298302
};
299303
enum ObjectFormatType {
300304
UnknownObjectFormat,
@@ -605,11 +609,12 @@ class Triple {
605609

606610
bool isGNUEnvironment() const {
607611
EnvironmentType Env = getEnvironment();
608-
return Env == Triple::GNU || Env == Triple::GNUABIN32 ||
609-
Env == Triple::GNUABI64 || Env == Triple::GNUEABI ||
610-
Env == Triple::GNUEABIHF || Env == Triple::GNUF32 ||
611-
Env == Triple::GNUF64 || Env == Triple::GNUSF ||
612-
Env == Triple::GNUX32;
612+
return Env == Triple::GNU || Env == Triple::GNUT64 ||
613+
Env == Triple::GNUABIN32 || Env == Triple::GNUABI64 ||
614+
Env == Triple::GNUEABI || Env == Triple::GNUEABIT64 ||
615+
Env == Triple::GNUEABIHF || Env == Triple::GNUEABIHFT64 ||
616+
Env == Triple::GNUF32 || Env == Triple::GNUF64 ||
617+
Env == Triple::GNUSF || Env == Triple::GNUX32;
613618
}
614619

615620
/// Tests whether the OS is Haiku.
@@ -866,9 +871,11 @@ class Triple {
866871
return (isARM() || isThumb()) &&
867872
(getEnvironment() == Triple::EABI ||
868873
getEnvironment() == Triple::GNUEABI ||
874+
getEnvironment() == Triple::GNUEABIT64 ||
869875
getEnvironment() == Triple::MuslEABI ||
870876
getEnvironment() == Triple::EABIHF ||
871877
getEnvironment() == Triple::GNUEABIHF ||
878+
getEnvironment() == Triple::GNUEABIHFT64 ||
872879
getEnvironment() == Triple::OpenHOS ||
873880
getEnvironment() == Triple::MuslEABIHF || isAndroid()) &&
874881
isOSBinFormatELF();
@@ -1046,6 +1053,22 @@ class Triple {
10461053
return getArch() == Triple::bpfel || getArch() == Triple::bpfeb;
10471054
}
10481055

1056+
/// Tests if the target forces 64-bit time_t on a 32-bit architecture.
1057+
bool isTime64ABI() const {
1058+
EnvironmentType Env = getEnvironment();
1059+
return Env == Triple::GNUT64 || Env == Triple::GNUEABIT64 ||
1060+
Env == Triple::GNUEABIHFT64;
1061+
}
1062+
1063+
/// Tests if the target forces hardfloat.
1064+
bool isHardFloatABI() const {
1065+
EnvironmentType Env = getEnvironment();
1066+
return Env == llvm::Triple::GNUEABIHF ||
1067+
Env == llvm::Triple::GNUEABIHFT64 ||
1068+
Env == llvm::Triple::MuslEABIHF ||
1069+
Env == llvm::Triple::EABIHF;
1070+
}
1071+
10491072
/// Tests whether the target supports comdat
10501073
bool supportsCOMDAT() const {
10511074
return !(isOSBinFormatMachO() || isOSBinFormatXCOFF() ||

0 commit comments

Comments
 (0)