-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[Driver] Add toolchain for X86_64 UEFI target #76838
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
5a05572
[UEFI] X86_64 UEFI Clang Driver
Prabhuk 3013bc0
Add end of file new lines.
Prabhuk b2ada86
Fix file first line comment. Fix nits.
Prabhuk 6e4f994
Move UEFI X86_64 datalayout codegen test under CodeGen/X86 folder
Prabhuk c7949e4
Removed trailing black line and duplicate codegen test.
Prabhuk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
//===--- UEFI.cpp - UEFI ToolChain Implementations -----------------------===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "UEFI.h" | ||
#include "CommonArgs.h" | ||
#include "Darwin.h" | ||
#include "clang/Basic/CharInfo.h" | ||
#include "clang/Basic/Version.h" | ||
#include "clang/Config/config.h" | ||
#include "clang/Driver/Compilation.h" | ||
#include "clang/Driver/Driver.h" | ||
#include "clang/Driver/Options.h" | ||
#include "clang/Driver/SanitizerArgs.h" | ||
#include "llvm/ADT/StringExtras.h" | ||
#include "llvm/ADT/StringSwitch.h" | ||
#include "llvm/Option/Arg.h" | ||
#include "llvm/Option/ArgList.h" | ||
#include "llvm/Support/FileSystem.h" | ||
#include "llvm/Support/MemoryBuffer.h" | ||
#include "llvm/Support/VirtualFileSystem.h" | ||
#include "llvm/TargetParser/Host.h" | ||
|
||
using namespace clang::driver; | ||
using namespace clang::driver::toolchains; | ||
using namespace clang; | ||
using namespace llvm::opt; | ||
|
||
UEFI::UEFI(const Driver &D, const llvm::Triple &Triple, const ArgList &Args) | ||
: ToolChain(D, Triple, Args) {} | ||
|
||
Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); } | ||
|
||
void tools::uefi::Linker::ConstructJob(Compilation &C, const JobAction &JA, | ||
const InputInfo &Output, | ||
const InputInfoList &Inputs, | ||
const ArgList &Args, | ||
const char *LinkingOutput) const { | ||
ArgStringList CmdArgs; | ||
auto &TC = static_cast<const toolchains::UEFI &>(getToolChain()); | ||
|
||
assert((Output.isFilename() || Output.isNothing()) && "invalid output"); | ||
if (Output.isFilename()) | ||
CmdArgs.push_back( | ||
Args.MakeArgString(std::string("-out:") + Output.getFilename())); | ||
|
||
CmdArgs.push_back("-nologo"); | ||
|
||
// TODO: Other UEFI binary subsystems that are currently unsupported: | ||
// efi_boot_service_driver, efi_rom, efi_runtime_driver. | ||
CmdArgs.push_back("-subsystem:efi_application"); | ||
|
||
// Default entry function name according to the TianoCore reference | ||
// implementation is EfiMain. | ||
// TODO: Provide a flag to override the entry function name. | ||
CmdArgs.push_back("-entry:EfiMain"); | ||
MaskRay marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
// "Terminal Service Aware" flag is not needed for UEFI applications. | ||
CmdArgs.push_back("-tsaware:no"); | ||
|
||
// EFI_APPLICATION to be linked as DLL by default. | ||
CmdArgs.push_back("-dll"); | ||
|
||
if (Args.hasArg(options::OPT_g_Group, options::OPT__SLASH_Z7)) | ||
CmdArgs.push_back("-debug"); | ||
Prabhuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link); | ||
Prabhuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA); | ||
|
||
// This should ideally be handled by ToolChain::GetLinkerPath but we need | ||
// to special case some linker paths. In the case of lld, we need to | ||
// translate 'lld' into 'lld-link'. | ||
StringRef Linker = | ||
Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER); | ||
if (Linker.empty() || Linker == "lld") | ||
Linker = "lld-link"; | ||
|
||
auto LinkerPath = TC.GetProgramPath(Linker.str().c_str()); | ||
auto LinkCmd = std::make_unique<Command>( | ||
JA, *this, ResponseFileSupport::AtFileUTF16(), | ||
Prabhuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
Args.MakeArgString(LinkerPath), CmdArgs, Inputs, Output); | ||
C.addCommand(std::move(LinkCmd)); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//===--- UEFI.h - UEFI ToolChain Implementations ----------*- C++ -*-===// | ||
// | ||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
// See https://llvm.org/LICENSE.txt for license information. | ||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_UEFI_H | ||
#define LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_UEFI_H | ||
|
||
#include "clang/Driver/Tool.h" | ||
#include "clang/Driver/ToolChain.h" | ||
|
||
namespace clang::driver { | ||
namespace tools { | ||
namespace uefi { | ||
class LLVM_LIBRARY_VISIBILITY Linker : public Tool { | ||
public: | ||
Linker(const ToolChain &TC) : Tool("uefi::Linker", "lld-link", TC) {} | ||
|
||
bool hasIntegratedCPP() const override { return false; } | ||
bool isLinkJob() const override { return true; } | ||
|
||
void ConstructJob(Compilation &C, const JobAction &JA, | ||
const InputInfo &Output, const InputInfoList &Inputs, | ||
const llvm::opt::ArgList &TCArgs, | ||
const char *LinkingOutput) const override; | ||
}; | ||
} // end namespace uefi | ||
} // end namespace tools | ||
|
||
namespace toolchains { | ||
|
||
class LLVM_LIBRARY_VISIBILITY UEFI : public ToolChain { | ||
public: | ||
UEFI(const Driver &D, const llvm::Triple &Triple, | ||
const llvm::opt::ArgList &Args); | ||
|
||
protected: | ||
Tool *buildLinker() const override; | ||
|
||
public: | ||
bool HasNativeLLVMSupport() const override { return true; } | ||
UnwindTableLevel | ||
getDefaultUnwindTableLevel(const llvm::opt::ArgList &Args) const override { | ||
return UnwindTableLevel::Asynchronous; | ||
} | ||
bool isPICDefault() const override { return true; } | ||
Prabhuk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
bool isPIEDefault(const llvm::opt::ArgList &Args) const override { | ||
return false; | ||
} | ||
bool isPICDefaultForced() const override { return true; } | ||
}; | ||
|
||
} // namespace toolchains | ||
} // namespace clang::driver | ||
|
||
#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_UEFI_H |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// RUN: %clang -target x86_64-unknown-uefi -S -emit-llvm -o - %s | \ | ||
// RUN: FileCheck --check-prefix=X86_64_UEFI %s | ||
// X86_64_UEFI: target datalayout = "e-m:w-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// RUN: %clang_cl -### %s --target=x86_64-unknown-uefi \ | ||
// RUN: --sysroot=%S/platform -fuse-ld=lld -g 2>&1 \ | ||
// RUN: | FileCheck -check-prefixes=CHECK %s | ||
// CHECK: "-cc1" | ||
// CHECK-SAME: "-triple" "x86_64-unknown-uefi" | ||
// CHECK-SAME: "-mrelocation-model" "pic" "-pic-level" "2" | ||
// CHECK-SAME: "-mframe-pointer=all" | ||
// CHECK-NEXT: "-nologo" | ||
// CHECK-SAME: "-subsystem:efi_application" | ||
// CHECK-SAME: "-entry:EfiMain" | ||
// CHECK-SAME: "-tsaware:no" | ||
// CHECK-SAME: "-dll" | ||
// CHECK-SAME: "-debug" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.