Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/lib/Basic/Targets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,8 @@ std::unique_ptr<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
case llvm::Triple::Hurd:
return std::make_unique<HurdTargetInfo<AArch64leTargetInfo>>(Triple,
Opts);
case llvm::Triple::UEFI:
return std::make_unique<UEFIAArch64TargetInfo>(Triple, Opts);
case llvm::Triple::Win32:
switch (Triple.getEnvironment()) {
case llvm::Triple::GNU:
Expand Down
43 changes: 43 additions & 0 deletions clang/lib/Basic/Targets/AArch64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,41 @@ MinGWARM64TargetInfo::MinGWARM64TargetInfo(const llvm::Triple &Triple,
TheCXXABI.set(TargetCXXABI::GenericAArch64);
}

TargetInfo::BuiltinVaListKind
UEFIAArch64TargetInfo::getBuiltinVaListKind() const {
return TargetInfo::CharPtrBuiltinVaList;
}

void UEFIAArch64TargetInfo::getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const {
AArch64leTargetInfo::getTargetDefines(Opts, Builder);
Builder.defineMacro("_M_ARM64", "1");
UEFIAArch64TargetInfo::getOSDefines(Opts, getTriple(), Builder);
}

TargetInfo::CallingConvCheckResult
UEFIAArch64TargetInfo::checkCallingConvention(CallingConv CC) const {
switch (CC) {
case CC_C:
case CC_PreserveMost:
case CC_PreserveAll:
case CC_Win64:
return CCCR_OK;
default:
return CCCR_Warning;
}
}

TargetInfo::CallingConvKind
UEFIAArch64TargetInfo::getCallingConvKind(bool ClangABICompat4) const {
return CCK_MicrosoftWin64;
}

void UEFIAArch64TargetInfo::setDataLayout() {
resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-p:64:64-i32:32-"
"i64:64-i128:128-n32:64-S128-Fn32");
}

AppleMachOAArch64TargetInfo::AppleMachOAArch64TargetInfo(
const llvm::Triple &Triple, const TargetOptions &Opts)
: AppleMachOTargetInfo<AArch64leTargetInfo>(Triple, Opts) {}
Expand Down Expand Up @@ -1832,6 +1867,14 @@ void DarwinAArch64TargetInfo::getOSDefines(const LangOptions &Opts,
DarwinTargetInfo<AArch64leTargetInfo>::getOSDefines(Opts, Triple, Builder);
}

// void UEFIAArch64TargetInfo::getOSDefines(const LangOptions &Opts,
// const llvm::Triple &Triple,
// MacroBuilder &Builder) const{

// UEFITargetInfo<AArch64leTargetInfo>::getOSDefines(Opts, Triple, Builder);
// // Builder.defineMacro("__UEFI__");
// }

TargetInfo::BuiltinVaListKind
DarwinAArch64TargetInfo::getBuiltinVaListKind() const {
return TargetInfo::CharPtrBuiltinVaList;
Expand Down
31 changes: 31 additions & 0 deletions clang/lib/Basic/Targets/AArch64.h
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,37 @@ class LLVM_LIBRARY_VISIBILITY DarwinAArch64TargetInfo
MacroBuilder &Builder) const override;
};

// aarch64 UEFI target
class LLVM_LIBRARY_VISIBILITY UEFIAArch64TargetInfo
: public UEFITargetInfo<AArch64leTargetInfo> {
public:
UEFIAArch64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
: UEFITargetInfo<AArch64leTargetInfo>(Triple, Opts) {
this->TheCXXABI.set(TargetCXXABI::Microsoft);
// This is an LLP64 platform.
// int:4, long:4, long long:8, long double:8.
IntWidth = IntAlign = 32;
LongWidth = LongAlign = 32;
DoubleAlign = LongLongAlign = 64;
LongDoubleWidth = LongDoubleAlign = 64;
LongDoubleFormat = &llvm::APFloat::IEEEdouble();
IntMaxType = SignedLongLong;
Int64Type = SignedLongLong;
SizeType = UnsignedLongLong;
PtrDiffType = SignedLongLong;
IntPtrType = SignedLongLong;
}
BuiltinVaListKind getBuiltinVaListKind() const override;
void getTargetDefines(const LangOptions &Opts,
MacroBuilder &Builder) const override;
CallingConvCheckResult checkCallingConvention(CallingConv CC) const override;
TargetInfo::CallingConvKind
getCallingConvKind(bool ClangABICompat4) const override;

private:
void setDataLayout() override;
};

} // namespace targets
} // namespace clang

Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CodeGen/CodeGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ createTargetCodeGenInfo(CodeGenModule &CGM) {
AArch64ABIKind Kind = AArch64ABIKind::AAPCS;
if (Target.getABI() == "darwinpcs")
Kind = AArch64ABIKind::DarwinPCS;
else if (Triple.isOSWindows())
else if (Triple.isOSWindows() || Triple.isUEFI())
return createWindowsAArch64TargetCodeGenInfo(CGM, AArch64ABIKind::Win64);
else if (Target.getABI() == "aapcs-soft")
Kind = AArch64ABIKind::AAPCSSoft;
Expand Down
6 changes: 4 additions & 2 deletions clang/lib/Driver/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,10 @@ static llvm::Triple computeTargetTriple(const Driver &D,
}
}

// Currently the only architecture supported by *-uefi triples are x86_64.
if (Target.isUEFI() && Target.getArch() != llvm::Triple::x86_64)
// Currently the only architectures supported by *-uefi triples are x86_64
// and aarch64.
if (Target.isUEFI() && Target.getArch() != llvm::Triple::x86_64 &&
Target.getArch() != llvm::Triple::aarch64)
D.Diag(diag::err_target_unknown_triple) << Target.str();

// The `-maix[32|64]` flags are only valid for AIX targets.
Expand Down
14 changes: 5 additions & 9 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1178,7 +1178,7 @@ static bool isSignedCharDefault(const llvm::Triple &Triple) {
case llvm::Triple::armeb:
case llvm::Triple::thumb:
case llvm::Triple::thumbeb:
if (Triple.isOSDarwin() || Triple.isOSWindows())
if (Triple.isOSDarwin() || Triple.isOSWindows() || Triple.isUEFI())
return true;
return false;

Expand Down Expand Up @@ -7044,7 +7044,7 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
if (!Args.hasFlag(
options::OPT_fuse_cxa_atexit, options::OPT_fno_use_cxa_atexit,
!RawTriple.isOSAIX() &&
(!RawTriple.isOSWindows() ||
((!RawTriple.isOSWindows() && !RawTriple.isUEFI()) ||
RawTriple.isWindowsCygwinEnvironment()) &&
((RawTriple.getVendor() != llvm::Triple::MipsTechnologies) ||
RawTriple.hasEnvironment())) ||
Expand Down Expand Up @@ -7079,16 +7079,12 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
CmdArgs.push_back("-fkeep-system-includes");
}

// -fms-extensions=0 is default.
if (Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
IsWindowsMSVC || IsUEFI))
CmdArgs.push_back("-fms-extensions");

// -fms-compatibility=0 is default.
bool IsMSVCCompat = Args.hasFlag(
options::OPT_fms_compatibility, options::OPT_fno_ms_compatibility,
(IsWindowsMSVC && Args.hasFlag(options::OPT_fms_extensions,
options::OPT_fno_ms_extensions, true)));
((IsWindowsMSVC || IsUEFI) &&
Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions,
true)));
if (IsMSVCCompat) {
CmdArgs.push_back("-fms-compatibility");
if (!types::isCXX(Input.getType()) &&
Expand Down
5 changes: 4 additions & 1 deletion clang/lib/Driver/ToolChains/CommonArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ static bool useFramePointerForTargetByDefault(const llvm::opt::ArgList &Args,
}
}

if (Triple.isUEFI())
return false;

if (Triple.isOSWindows()) {
switch (Triple.getArch()) {
case llvm::Triple::x86:
Expand Down Expand Up @@ -198,7 +201,7 @@ static bool mustMaintainValidFrameChain(const llvm::opt::ArgList &Args,
// Arm64 Windows requires that the frame chain is valid, as there is no
// way to indicate during a stack walk that a frame has used the frame
// pointer as a general purpose register.
return Triple.isOSWindows();
return Triple.isOSWindows() || Triple.isUEFI();
}
}

Expand Down
19 changes: 19 additions & 0 deletions clang/test/Driver/aarch64-uefi-constructed-args.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// RUN: %clang -### --target=aarch64-unknown-uefi -g -- %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK %s
// RUN: %clang_cl -### --target=aarch64-unknown-uefi -g -- %s 2>&1 \
// RUN: | FileCheck -check-prefixes=CHECK %s
// CHECK: "-cc1"
// CHECK-SAME: "-triple" "aarch64-unknown-uefi"
// CHECK-SAME: "-mrelocation-model" "pic" "-pic-level" "2"
// CHECK-SAME: "-mframe-pointer=all"
// CHECK-SAME: "-fms-extensions"
// CHECK-NEXT: "/nologo"
// CHECK-SAME: "/subsystem:efi_application"
// CHECK-SAME: "/entry:EfiMain"
// CHECK-SAME: "/tsaware:no"
// CHECK-SAME: "/debug"

// RUN: %clang -### --target=aarch64-unknown-uefi -print-search-dirs 2>&1 \
// RUN: | FileCheck -check-prefixes=PROGPATH %s
// PROGPATH: InstalledDir: [[DRIVER_INSTALLED_DIR:.*]]
// PROGPATH: programs: =[[DRIVER_INSTALLED_DIR]]
1 change: 1 addition & 0 deletions clang/test/Driver/uefi-defines.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// RUN: %clang -target x86_64-unknown-uefi %s -emit-llvm -S -c -o - | FileCheck %s
// RUN: %clang -target aarch64-unknown-uefi %s -emit-llvm -S -c -o - | FileCheck %s

// CHECK: __UEFI__defined
#ifdef __UEFI__
Expand Down
6 changes: 0 additions & 6 deletions clang/test/Driver/unsupported-target-arch.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,6 @@
// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-PPCMAC %s
// CHECK-PPCMAC: error: unknown target triple 'unknown-apple-macosx{{.*}}'

// RUN: not %clang --target=aarch64-unknown-uefi -o %t.o %s 2> %t.err
// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-AARCH64 %s
// RUN: not %clang_cl --target=aarch64-unknown-uefi -o %t.o %s 2> %t.err
// RUN: FileCheck --input-file=%t.err --check-prefix=CHECK-AARCH64 %s
// CHECK-AARCH64: error: unknown target triple 'aarch64-unknown-uefi'{{$}}

// RUN: not %clang --target=arm-unknown-uefi -o %t.o %s 2> %t.err
// RUN: FileCheck --input-file=%t.err -check-prefixes=CHECK-ARM %s
// RUN: not %clang_cl --target=arm-unknown-uefi -o %t.o %s 2> %t.err
Expand Down
2 changes: 2 additions & 0 deletions clang/test/Preprocessor/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -2843,6 +2843,8 @@

// RUN: %clang_cc1 -dM -triple=x86_64-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s
// RUN: %clang_cc1 -dM -triple=x86_64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s
// RUN: %clang_cc1 -dM -triple=aarch64-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s
// RUN: %clang_cc1 -dM -triple=aarch64-unknown-uefi -E /dev/null | FileCheck -match-full-lines -check-prefix UEFI %s

// UEFI: #define __UEFI__ 1

Expand Down
3 changes: 3 additions & 0 deletions llvm/include/llvm/TargetParser/Triple.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,9 @@ class Triple {
bool isWindowsMSVCEnvironment() const {
return isKnownWindowsMSVCEnvironment() ||
(isOSWindows() && getEnvironment() == Triple::UnknownEnvironment);
// ||
// (isUEFI() && isAArch64() && getEnvironment() ==
// Triple::UnknownEnvironment);
}

// Checks if we're using the Windows Arm64EC ABI.
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Target/AArch64/AArch64MCInstLower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ MCSymbol *AArch64MCInstLower::GetGlobalValueSymbol(const GlobalValue *GV,
if (!TheTriple.isOSBinFormatCOFF())
return Printer.getSymbolPreferLocal(*GV);

assert(TheTriple.isOSWindows() &&
"Windows is the only supported COFF target");
assert((TheTriple.isOSWindows() || TheTriple.isUEFI()) &&
"Windows and UEFI are the only supported COFF targets");

bool IsIndirect =
(TargetFlags & (AArch64II::MO_DLLIMPORT | AArch64II::MO_COFFSTUB));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ static MCAsmInfo *createAArch64MCAsmInfo(const MCRegisterInfo &MRI,
MAI = new AArch64MCAsmInfoDarwin(TheTriple.getArch() == Triple::aarch64_32);
else if (TheTriple.isOSBinFormatELF())
MAI = new AArch64MCAsmInfoELF(TheTriple);
else if (TheTriple.isWindowsMSVCEnvironment())
else if (TheTriple.isWindowsMSVCEnvironment() || TheTriple.isUEFI())
MAI = new AArch64MCAsmInfoMicrosoftCOFF();
else if (TheTriple.isOSBinFormatCOFF())
MAI = new AArch64MCAsmInfoGNUCOFF();
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/TargetParser/AArch64TargetParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void AArch64::fillValidCPUArchList(SmallVectorImpl<StringRef> &Values) {

bool AArch64::isX18ReservedByDefault(const Triple &TT) {
return TT.isAndroid() || TT.isOSDarwin() || TT.isOSFuchsia() ||
TT.isOSWindows() || TT.isOHOSFamily();
TT.isOSWindows() || TT.isUEFI() || TT.isOHOSFamily();
}

// Allows partial match, ex. "v8a" matches "armv8a".
Expand Down
Loading