clang 20.0.0git
UEFI.cpp
Go to the documentation of this file.
1//===--- UEFI.cpp - UEFI ToolChain Implementations -----------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
9#include "UEFI.h"
10#include "CommonArgs.h"
11#include "Darwin.h"
13#include "clang/Basic/Version.h"
14#include "clang/Config/config.h"
16#include "clang/Driver/Driver.h"
19#include "llvm/ADT/StringExtras.h"
20#include "llvm/ADT/StringSwitch.h"
21#include "llvm/Option/Arg.h"
22#include "llvm/Option/ArgList.h"
23#include "llvm/Support/FileSystem.h"
24#include "llvm/Support/MemoryBuffer.h"
25#include "llvm/Support/VirtualFileSystem.h"
26#include "llvm/TargetParser/Host.h"
27
28using namespace clang::driver;
29using namespace clang::driver::toolchains;
30using namespace clang;
31using namespace llvm::opt;
32
33UEFI::UEFI(const Driver &D, const llvm::Triple &Triple, const ArgList &Args)
34 : ToolChain(D, Triple, Args) {}
35
36Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); }
37
39 const InputInfo &Output,
40 const InputInfoList &Inputs,
41 const ArgList &Args,
42 const char *LinkingOutput) const {
43 ArgStringList CmdArgs;
44 auto &TC = static_cast<const toolchains::UEFI &>(getToolChain());
45
46 assert((Output.isFilename() || Output.isNothing()) && "invalid output");
47 if (Output.isFilename())
48 CmdArgs.push_back(
49 Args.MakeArgString(std::string("-out:") + Output.getFilename()));
50
51 CmdArgs.push_back("-nologo");
52
53 // TODO: Other UEFI binary subsystems that are currently unsupported:
54 // efi_boot_service_driver, efi_rom, efi_runtime_driver.
55 CmdArgs.push_back("-subsystem:efi_application");
56
57 // Default entry function name according to the TianoCore reference
58 // implementation is EfiMain.
59 // TODO: Provide a flag to override the entry function name.
60 CmdArgs.push_back("-entry:EfiMain");
61
62 // "Terminal Service Aware" flag is not needed for UEFI applications.
63 CmdArgs.push_back("-tsaware:no");
64
65 // EFI_APPLICATION to be linked as DLL by default.
66 CmdArgs.push_back("-dll");
67
68 if (Args.hasArg(options::OPT_g_Group, options::OPT__SLASH_Z7))
69 CmdArgs.push_back("-debug");
70
71 Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link);
72
73 AddLinkerInputs(TC, Inputs, Args, CmdArgs, JA);
74
75 // This should ideally be handled by ToolChain::GetLinkerPath but we need
76 // to special case some linker paths. In the case of lld, we need to
77 // translate 'lld' into 'lld-link'.
78 StringRef Linker =
79 Args.getLastArgValue(options::OPT_fuse_ld_EQ, CLANG_DEFAULT_LINKER);
80 if (Linker.empty() || Linker == "lld")
81 Linker = "lld-link";
82
83 auto LinkerPath = TC.GetProgramPath(Linker.str().c_str());
84 auto LinkCmd = std::make_unique<Command>(
86 Args.MakeArgString(LinkerPath), CmdArgs, Inputs, Output);
87 C.addCommand(std::move(LinkCmd));
88}
const Decl * D
Defines version macros and version-related utility functions for Clang.
Compilation - A set of tasks to perform for a single driver invocation.
Definition: Compilation.h:45
Driver - Encapsulate logic for constructing compilation processes from a set of gcc-driver-like comma...
Definition: Driver.h:77
InputInfo - Wrapper for information about an input source.
Definition: InputInfo.h:22
const char * getFilename() const
Definition: InputInfo.h:83
bool isNothing() const
Definition: InputInfo.h:74
bool isFilename() const
Definition: InputInfo.h:75
ToolChain - Access to tools for a single platform.
Definition: ToolChain.h:92
Tool - Information on a specific compilation tool.
Definition: Tool.h:32
Tool * buildLinker() const override
Definition: UEFI.cpp:36
UEFI(const Driver &D, const llvm::Triple &Triple, const llvm::opt::ArgList &Args)
Definition: UEFI.cpp:33
void ConstructJob(Compilation &C, const JobAction &JA, const InputInfo &Output, const InputInfoList &Inputs, const llvm::opt::ArgList &TCArgs, const char *LinkingOutput) const override
ConstructJob - Construct jobs to perform the action JA, writing to Output and with Inputs,...
Definition: UEFI.cpp:38
void AddLinkerInputs(const ToolChain &TC, const InputInfoList &Inputs, const llvm::opt::ArgList &Args, llvm::opt::ArgStringList &CmdArgs, const JobAction &JA)
The JSON file list parser is used to communicate input to InstallAPI.
static constexpr ResponseFileSupport AtFileUTF16()
Definition: Job.h:99