Skip to content

Commit

Permalink
[Triple] Add triple for UEFI
Browse files Browse the repository at this point in the history
Target triple to support "x86_64-unknown-uefi"

Reviewed By: phosek

Differential Revision: https://reviews.llvm.org/D131594
  • Loading branch information
Prabhuk committed Jun 6, 2023
1 parent 4faa6c6 commit 30198bd
Show file tree
Hide file tree
Showing 9 changed files with 29 additions and 4 deletions.
3 changes: 2 additions & 1 deletion llvm/include/llvm/MC/TargetRegistry.h
Expand Up @@ -564,7 +564,8 @@ class Target {
case Triple::UnknownObjectFormat:
llvm_unreachable("Unknown object format");
case Triple::COFF:
assert(T.isOSWindows() && "only Windows COFF is supported");
assert((T.isOSWindows() || T.isUEFI()) &&
"only Windows and UEFI COFF are supported");
S = COFFStreamerCtorFn(Ctx, std::move(TAB), std::move(OW),
std::move(Emitter), RelaxAll,
IncrementalLinkerCompatible);
Expand Down
6 changes: 6 additions & 0 deletions llvm/include/llvm/TargetParser/Triple.h
Expand Up @@ -199,6 +199,7 @@ class Triple {
NetBSD,
OpenBSD,
Solaris,
UEFI,
Win32,
ZOS,
Haiku,
Expand Down Expand Up @@ -580,6 +581,11 @@ class Triple {
return getOS() == Triple::Haiku;
}

/// Tests whether the OS is UEFI.
bool isUEFI() const {
return getOS() == Triple::UEFI;
}

/// Tests whether the OS is Windows.
bool isOSWindows() const {
return getOS() == Triple::Win32;
Expand Down
2 changes: 1 addition & 1 deletion llvm/lib/MC/MCContext.cpp
Expand Up @@ -85,7 +85,7 @@ MCContext::MCContext(const Triple &TheTriple, const MCAsmInfo *mai,
Env = IsMachO;
break;
case Triple::COFF:
if (!TheTriple.isOSWindows())
if (!TheTriple.isOSWindows() && !TheTriple.isUEFI())
report_fatal_error(
"Cannot initialize MC for non-Windows COFF object files.");

Expand Down
6 changes: 6 additions & 0 deletions llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
Expand Up @@ -1516,6 +1516,12 @@ MCAsmBackend *llvm::createX86_64AsmBackend(const Target &T,
if (TheTriple.isOSWindows() && TheTriple.isOSBinFormatCOFF())
return new WindowsX86AsmBackend(T, true, STI);

if (TheTriple.isUEFI()) {
assert(TheTriple.isOSBinFormatCOFF() &&
"Only COFF format is supported in UEFI environment.");
return new WindowsX86AsmBackend(T, true, STI);
}

uint8_t OSABI = MCELFObjectTargetWriter::getOSABI(TheTriple.getOS());

if (TheTriple.isX32())
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/X86/MCTargetDesc/X86MCAsmInfo.cpp
Expand Up @@ -153,7 +153,8 @@ X86MCAsmInfoMicrosoftMASM::X86MCAsmInfoMicrosoftMASM(const Triple &Triple)
void X86MCAsmInfoGNUCOFF::anchor() { }

X86MCAsmInfoGNUCOFF::X86MCAsmInfoGNUCOFF(const Triple &Triple) {
assert(Triple.isOSWindows() && "Windows is the only supported COFF target");
assert((Triple.isOSWindows() || Triple.isUEFI()) &&
"Windows and UEFI are the only supported COFF targets");
if (Triple.getArch() == Triple::x86_64) {
PrivateGlobalPrefix = ".L";
PrivateLabelPrefix = ".L";
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/Target/X86/MCTargetDesc/X86MCTargetDesc.cpp
Expand Up @@ -441,6 +441,8 @@ static MCAsmInfo *createX86MCAsmInfo(const MCRegisterInfo &MRI,
} else if (TheTriple.isOSCygMing() ||
TheTriple.isWindowsItaniumEnvironment()) {
MAI = new X86MCAsmInfoGNUCOFF(TheTriple);
} else if (TheTriple.isUEFI()) {
MAI = new X86MCAsmInfoGNUCOFF(TheTriple);
} else {
// The default is ELF.
MAI = new X86ELFMCAsmInfo(TheTriple);
Expand Down
3 changes: 2 additions & 1 deletion llvm/lib/Target/X86/X86MCInstLower.cpp
Expand Up @@ -1555,7 +1555,8 @@ static void printConstant(const Constant *COp, unsigned BitWidth,

void X86AsmPrinter::EmitSEHInstruction(const MachineInstr *MI) {
assert(MF->hasWinCFI() && "SEH_ instruction in function without WinCFI?");
assert(getSubtarget().isOSWindows() && "SEH_ instruction Windows only");
assert((getSubtarget().isOSWindows() || TM.getTargetTriple().isUEFI()) &&
"SEH_ instruction Windows and UEFI only");

// Use the .cv_fpo directives if we're emitting CodeView on 32-bit x86.
if (EmitFPOData) {
Expand Down
2 changes: 2 additions & 0 deletions llvm/lib/TargetParser/Triple.cpp
Expand Up @@ -238,6 +238,7 @@ StringRef Triple::getOSTypeName(OSType Kind) {
case RTEMS: return "rtems";
case Solaris: return "solaris";
case TvOS: return "tvos";
case UEFI: return "uefi";
case WASI: return "wasi";
case WatchOS: return "watchos";
case Win32: return "windows";
Expand Down Expand Up @@ -588,6 +589,7 @@ static Triple::OSType parseOS(StringRef OSName) {
.StartsWith("netbsd", Triple::NetBSD)
.StartsWith("openbsd", Triple::OpenBSD)
.StartsWith("solaris", Triple::Solaris)
.StartsWith("uefi", Triple::UEFI)
.StartsWith("win32", Triple::Win32)
.StartsWith("windows", Triple::Win32)
.StartsWith("zos", Triple::ZOS)
Expand Down
6 changes: 6 additions & 0 deletions llvm/unittests/TargetParser/TripleTest.cpp
Expand Up @@ -349,6 +349,12 @@ TEST(TripleTest, ParsedIDs) {
EXPECT_EQ(Triple::HermitCore, T.getOS());
EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());

T = Triple("x86_64-unknown-uefi");
EXPECT_EQ(Triple::x86_64, T.getArch());
EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
EXPECT_EQ(Triple::UEFI, T.getOS());
EXPECT_EQ(Triple::UnknownEnvironment, T.getEnvironment());

T = Triple("wasm32-unknown-unknown");
EXPECT_EQ(Triple::wasm32, T.getArch());
EXPECT_EQ(Triple::UnknownVendor, T.getVendor());
Expand Down

0 comments on commit 30198bd

Please sign in to comment.