[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -819,6 +819,43 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { } }; +// x86-64 UEFI target +class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo +: public UEFITargetInfo { +public: + UEFIX86_64TargetInfo(const llvm::Triple , const TargetOptions ) + : UEFITargetInfo(Triple, Opts) { MaskRay wrote: Still waiting for a calling convention test https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
MaskRay wrote: Some older toolchains were probably contributed with a lot of `CmdArgs.push_back` uncovered by tests. They are not good examples to follow. For new toolchains, we do want all constructed `CmdArgs.push_back` to be covered. This allows refactoring by someone who is unfamiliar with your usage pattern. https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -0,0 +1,92 @@ +//===--- 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 +// +//===--===// + +#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 , const llvm::Triple , const ArgList ) +: ToolChain(D, Triple, Args) { + getProgramPaths().push_back(getDriver().getInstalledDir()); + if (getDriver().getInstalledDir() != getDriver().Dir) +getProgramPaths().push_back(getDriver().Dir); +} + +Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); } + +void tools::uefi::Linker::ConstructJob(Compilation , const JobAction , + const InputInfo , + const InputInfoList , + const ArgList , + const char *LinkingOutput) const { + ArgStringList CmdArgs; + auto = static_cast(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"); + + // "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"); + + Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link); + + 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.equals("lld")) +Linker = "lld-link"; + + auto LinkerPath = TC.GetProgramPath(Linker.str().c_str()); + auto LinkCmd = std::make_unique( + JA, *this, ResponseFileSupport::AtFileUTF16(), Prabhuk wrote: Yes. This maintains compatibility with LINK.exe which only supports UTF-16. https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -0,0 +1,92 @@ +//===--- 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 +// +//===--===// + +#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 , const llvm::Triple , const ArgList ) +: ToolChain(D, Triple, Args) { + getProgramPaths().push_back(getDriver().getInstalledDir()); + if (getDriver().getInstalledDir() != getDriver().Dir) Prabhuk wrote: I see the getInstalledDir still present after your changes. Except the definition been changed. Am I missing something here? https://github.com/llvm/llvm-project/commit/2b5cd8be3af43e5aa5b76b6aeb1edd3141b803ca#diff-2c12c1bdb5245225094e1125ceb698aa4ed7e69cd1d154a4004f5adc54691624R428 https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -0,0 +1,115 @@ +//===--- 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 +// +//===--===// + +#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 , const llvm::Triple , const ArgList ) +: ToolChain(D, Triple, Args) { + getProgramPaths().push_back(getDriver().getInstalledDir()); + if (getDriver().getInstalledDir() != getDriver().Dir) +getProgramPaths().push_back(getDriver().Dir); +} + +Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); } + +void tools::uefi::Linker::ConstructJob(Compilation , const JobAction , + const InputInfo , + const InputInfoList , + const ArgList , + const char *LinkingOutput) const { + ArgStringList CmdArgs; + + auto = static_cast(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"); + + // "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"); MaskRay wrote: This logic from MSVC.cpp seems incorrect to me. If the intention is for `-g` to enable `-debug`, then `-g -g0` should be able to remove `-debug`. https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -0,0 +1,92 @@ +//===--- 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 +// +//===--===// + +#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 , const llvm::Triple , const ArgList ) +: ToolChain(D, Triple, Args) { + getProgramPaths().push_back(getDriver().getInstalledDir()); + if (getDriver().getInstalledDir() != getDriver().Dir) +getProgramPaths().push_back(getDriver().Dir); +} + +Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); } + +void tools::uefi::Linker::ConstructJob(Compilation , const JobAction , + const InputInfo , + const InputInfoList , + const ArgList , + const char *LinkingOutput) const { + ArgStringList CmdArgs; + auto = static_cast(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"); + + // "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"); + + Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link); + + 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.equals("lld")) +Linker = "lld-link"; + + auto LinkerPath = TC.GetProgramPath(Linker.str().c_str()); + auto LinkCmd = std::make_unique( + JA, *this, ResponseFileSupport::AtFileUTF16(), MaskRay wrote: Is this intended to be UTF-16 like MSVC? https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -0,0 +1,92 @@ +//===--- 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 +// +//===--===// + +#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 , const llvm::Triple , const ArgList ) +: ToolChain(D, Triple, Args) { + getProgramPaths().push_back(getDriver().getInstalledDir()); + if (getDriver().getInstalledDir() != getDriver().Dir) +getProgramPaths().push_back(getDriver().Dir); +} + +Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); } + +void tools::uefi::Linker::ConstructJob(Compilation , const JobAction , + const InputInfo , + const InputInfoList , + const ArgList , + const char *LinkingOutput) const { + ArgStringList CmdArgs; + auto = static_cast(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"); + + // "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"); + + Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link); + + 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.equals("lld")) MaskRay wrote: Nit: Prefer `==` to `equals` https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -0,0 +1,92 @@ +//===--- 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 +// +//===--===// + +#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 , const llvm::Triple , const ArgList ) +: ToolChain(D, Triple, Args) { + getProgramPaths().push_back(getDriver().getInstalledDir()); + if (getDriver().getInstalledDir() != getDriver().Dir) +getProgramPaths().push_back(getDriver().Dir); +} + +Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); } + +void tools::uefi::Linker::ConstructJob(Compilation , const JobAction , + const InputInfo , + const InputInfoList , + const ArgList , + const char *LinkingOutput) const { + ArgStringList CmdArgs; + auto = static_cast(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"); + + // "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"); + + Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link); MaskRay wrote: We need tests for this. https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -0,0 +1,92 @@ +//===--- 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 +// +//===--===// + +#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 , const llvm::Triple , const ArgList ) +: ToolChain(D, Triple, Args) { + getProgramPaths().push_back(getDriver().getInstalledDir()); + if (getDriver().getInstalledDir() != getDriver().Dir) MaskRay wrote: I have removed getInstalledDir in #80527 and follow-ups. This needs an update. https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -0,0 +1,61 @@ +//===--- 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 { +namespace driver { +namespace tools { +namespace uefi { +class LLVM_LIBRARY_VISIBILITY Linker : public Tool { +public: + Linker(const ToolChain ) : Tool("uefi::Linker", "lld-link", TC) {} + + bool hasIntegratedCPP() const override { return false; } + bool isLinkJob() const override { return true; } + + void ConstructJob(Compilation , const JobAction , +const InputInfo , const InputInfoList , +const llvm::opt::ArgList , +const char *LinkingOutput) const override; +}; +} // end namespace uefi +} // end namespace tools + +namespace toolchains { + +class LLVM_LIBRARY_VISIBILITY UEFI : public ToolChain { +public: + UEFI(const Driver , const llvm::Triple , + const llvm::opt::ArgList ); + +protected: + Tool *buildLinker() const override; + +public: + bool HasNativeLLVMSupport() const override { return true; } + UnwindTableLevel + getDefaultUnwindTableLevel(const llvm::opt::ArgList ) const override { +return UnwindTableLevel::Asynchronous; + } + bool isPICDefault() const override { return true; } Prabhuk wrote: I am matching the behavior of the MSVC toolchain in setting isPICDefault and isPICDefaultForced. https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -0,0 +1,115 @@ +//===--- 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 +// +//===--===// + +#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 , const llvm::Triple , const ArgList ) +: ToolChain(D, Triple, Args) { + getProgramPaths().push_back(getDriver().getInstalledDir()); + if (getDriver().getInstalledDir() != getDriver().Dir) +getProgramPaths().push_back(getDriver().Dir); +} + +Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); } + +void tools::uefi::Linker::ConstructJob(Compilation , const JobAction , + const InputInfo , + const InputInfoList , + const ArgList , + const char *LinkingOutput) const { + ArgStringList CmdArgs; + + auto = static_cast(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"); Prabhuk wrote: For the initial implementation to compile simple EFI applciations, I am using Tianacore's reference implementation as mentioned in the inline comment. I had mentioned this in my RFC here: https://discourse.llvm.org/t/rfc-uefi-driver-support-uefi-target/73261 https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -819,6 +819,43 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { } }; +// x86-64 UEFI target +class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo +: public UEFITargetInfo { +public: + UEFIX86_64TargetInfo(const llvm::Triple , const TargetOptions ) + : UEFITargetInfo(Triple, Opts) { Prabhuk wrote: I have added layout test to target-data.c. I am trying to figure out where to add a test for the calling convention. https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -0,0 +1,115 @@ +//===--- 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 +// +//===--===// + +#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 , const llvm::Triple , const ArgList ) +: ToolChain(D, Triple, Args) { + getProgramPaths().push_back(getDriver().getInstalledDir()); + if (getDriver().getInstalledDir() != getDriver().Dir) +getProgramPaths().push_back(getDriver().Dir); +} + +Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); } + +void tools::uefi::Linker::ConstructJob(Compilation , const JobAction , + const InputInfo , + const InputInfoList , + const ArgList , + const char *LinkingOutput) const { + ArgStringList CmdArgs; + + auto = static_cast(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"); + + // "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 wrote: Added debug flag test to Driver/uefi.c file https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
https://github.com/Prabhuk updated https://github.com/llvm/llvm-project/pull/76838 >From dea3d410a96ee48c3e224575a9d578235074d442 Mon Sep 17 00:00:00 2001 From: prabhukr Date: Mon, 4 Dec 2023 08:54:14 -0800 Subject: [PATCH] [UEFI] X86_64 UEFI Clang Driver Introduce changes necessary for UEFI X86_64 target Clang driver. Reviewed By: phosek Differential Revision: https://reviews.llvm.org/D159541 --- clang/lib/Basic/Targets.cpp | 3 + clang/lib/Basic/Targets/OSTargets.h | 15 + clang/lib/Basic/Targets/X86.h| 37 +++ clang/lib/Driver/CMakeLists.txt | 1 + clang/lib/Driver/Driver.cpp | 4 ++ clang/lib/Driver/ToolChains/UEFI.cpp | 92 clang/lib/Driver/ToolChains/UEFI.h | 61 ++ clang/test/CodeGen/target-data.c | 4 ++ clang/test/Driver/uefi.c | 12 9 files changed, 229 insertions(+) create mode 100644 clang/lib/Driver/ToolChains/UEFI.cpp create mode 100644 clang/lib/Driver/ToolChains/UEFI.h create mode 100644 clang/test/Driver/uefi.c diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index e3283510c6aac78..7a35a421765c55e 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -625,6 +625,9 @@ std::unique_ptr AllocateTarget(const llvm::Triple , case llvm::Triple::Solaris: return std::make_unique>(Triple, Opts); +case llvm::Triple::UEFI: + return std::make_unique(Triple, Opts); + case llvm::Triple::Win32: { switch (Triple.getEnvironment()) { case llvm::Triple::Cygnus: diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index 4366c1149e40530..fae1a67bd4237b1 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -778,6 +778,21 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo { } }; +// UEFI target +template +class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { +protected: + void getOSDefines(const LangOptions , const llvm::Triple , +MacroBuilder ) const override {} + +public: + UEFITargetInfo(const llvm::Triple , const TargetOptions ) + : OSTargetInfo(Triple, Opts) { +this->WCharType = TargetInfo::UnsignedShort; +this->WIntType = TargetInfo::UnsignedShort; + } +}; + void addWindowsDefines(const llvm::Triple , const LangOptions , MacroBuilder ); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index d2232c7d5275abf..86241af45d17f3e 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -825,6 +825,43 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { } }; +// x86-64 UEFI target +class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo +: public UEFITargetInfo { +public: + UEFIX86_64TargetInfo(const llvm::Triple , const TargetOptions ) + : UEFITargetInfo(Triple, Opts) { +this->TheCXXABI.set(TargetCXXABI::Microsoft); +this->MaxTLSAlign = 8192u * this->getCharWidth(); +this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-" + "i64:64-i128:128-f80:128-n8:16:32:64-S128"); + } + + void getTargetDefines(const LangOptions , +MacroBuilder ) const override { +getOSDefines(Opts, X86TargetInfo::getTriple(), Builder); + } + + BuiltinVaListKind getBuiltinVaListKind() const override { +return TargetInfo::CharPtrBuiltinVaList; + } + + CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { +switch (CC) { +case CC_C: +case CC_Win64: + return CCCR_OK; +default: + return CCCR_Warning; +} + } + + TargetInfo::CallingConvKind + getCallingConvKind(bool ClangABICompat4) const override { +return CCK_MicrosoftWin64; + } +}; + // x86-64 Windows target class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo : public WindowsTargetInfo { diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 58427e3f83c4201..7d05822b64b61b6 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -78,6 +78,7 @@ add_clang_library(clangDriver ToolChains/Solaris.cpp ToolChains/SPIRV.cpp ToolChains/TCE.cpp + ToolChains/UEFI.cpp ToolChains/VEToolchain.cpp ToolChains/WebAssembly.cpp ToolChains/XCore.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 00e14071a4afecc..455d9bad69f9e1b 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -45,6 +45,7 @@ #include "ToolChains/SPIRV.h" #include "ToolChains/Solaris.h" #include "ToolChains/TCE.h" +#include "ToolChains/UEFI.h" #include "ToolChains/VEToolchain.h" #include "ToolChains/WebAssembly.h" #include "ToolChains/XCore.h" @@ -6288,6 +6289,9 @@ const ToolChain ::getToolChain(const ArgList , case
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
brad0 wrote: Ping. https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -819,6 +819,43 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { } }; +// x86-64 UEFI target +class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo +: public UEFITargetInfo { +public: + UEFIX86_64TargetInfo(const llvm::Triple , const TargetOptions ) + : UEFITargetInfo(Triple, Opts) { MaskRay wrote: This clangBasic change needs a `clang/test/CodeGen` test for things including: data layout , calling convention. https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -0,0 +1,115 @@ +//===--- 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 +// +//===--===// + +#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 , const llvm::Triple , const ArgList ) +: ToolChain(D, Triple, Args) { + getProgramPaths().push_back(getDriver().getInstalledDir()); + if (getDriver().getInstalledDir() != getDriver().Dir) +getProgramPaths().push_back(getDriver().Dir); +} + +Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); } + +void tools::uefi::Linker::ConstructJob(Compilation , const JobAction , + const InputInfo , + const InputInfoList , + const ArgList , + const char *LinkingOutput) const { + ArgStringList CmdArgs; + + auto = static_cast(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"); + + // "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"); + + Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link); + + // Add filenames, libraries, and other linker inputs. + for (const auto : Inputs) { +if (Input.isFilename()) { + CmdArgs.push_back(Input.getFilename()); + continue; +} + +const Arg = Input.getInputArg(); +if (A.getOption().matches(options::OPT_l)) { + StringRef Lib = A.getValue(); + const char *LinkLibArg; + if (Lib.ends_with(".lib")) MaskRay wrote: The `-l` behavior is untested. Does it really behave this way detecting `.lib`? lld-link appends `.lib` if the name does not contain a `.`. For linker input, `AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);` https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -0,0 +1,115 @@ +//===--- 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 +// +//===--===// + +#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 , const llvm::Triple , const ArgList ) +: ToolChain(D, Triple, Args) { + getProgramPaths().push_back(getDriver().getInstalledDir()); + if (getDriver().getInstalledDir() != getDriver().Dir) +getProgramPaths().push_back(getDriver().Dir); +} + +Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); } + +void tools::uefi::Linker::ConstructJob(Compilation , const JobAction , + const InputInfo , + const InputInfoList , + const ArgList , + const char *LinkingOutput) const { + ArgStringList CmdArgs; + + auto = static_cast(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"); + + // "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"); MaskRay wrote: untested https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -0,0 +1,115 @@ +//===--- 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 +// +//===--===// + +#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 , const llvm::Triple , const ArgList ) +: ToolChain(D, Triple, Args) { + getProgramPaths().push_back(getDriver().getInstalledDir()); + if (getDriver().getInstalledDir() != getDriver().Dir) +getProgramPaths().push_back(getDriver().Dir); +} + +Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); } + +void tools::uefi::Linker::ConstructJob(Compilation , const JobAction , + const InputInfo , + const InputInfoList , + const ArgList , + const char *LinkingOutput) const { + ArgStringList CmdArgs; + + auto = static_cast(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 wrote: Is there a specification that this is `EfiMain`? https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -0,0 +1,61 @@ +//===--- 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 { +namespace driver { +namespace tools { +namespace uefi { +class LLVM_LIBRARY_VISIBILITY Linker : public Tool { +public: + Linker(const ToolChain ) : Tool("uefi::Linker", "lld-link", TC) {} + + bool hasIntegratedCPP() const override { return false; } + bool isLinkJob() const override { return true; } + + void ConstructJob(Compilation , const JobAction , +const InputInfo , const InputInfoList , +const llvm::opt::ArgList , +const char *LinkingOutput) const override; +}; +} // end namespace uefi +} // end namespace tools + +namespace toolchains { + +class LLVM_LIBRARY_VISIBILITY UEFI : public ToolChain { +public: + UEFI(const Driver , const llvm::Triple , + const llvm::opt::ArgList ); + +protected: + Tool *buildLinker() const override; + +public: + bool HasNativeLLVMSupport() const override { return true; } + UnwindTableLevel + getDefaultUnwindTableLevel(const llvm::opt::ArgList ) const override { +return UnwindTableLevel::Asynchronous; + } + bool isPICDefault() const override { return true; } MaskRay wrote: Q: why is this PIC and forced (`-fno-pic` will error)? https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -0,0 +1,115 @@ +//===--- 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 +// +//===--===// + +#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 , const llvm::Triple , const ArgList ) +: ToolChain(D, Triple, Args) { + getProgramPaths().push_back(getDriver().getInstalledDir()); + if (getDriver().getInstalledDir() != getDriver().Dir) +getProgramPaths().push_back(getDriver().Dir); +} + +Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); } + +void tools::uefi::Linker::ConstructJob(Compilation , const JobAction , + const InputInfo , + const InputInfoList , + const ArgList , + const char *LinkingOutput) const { + ArgStringList CmdArgs; + + auto = static_cast(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"); + + // "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"); + + Args.AddAllArgValues(CmdArgs, options::OPT__SLASH_link); + + // Add filenames, libraries, and other linker inputs. + for (const auto : Inputs) { +if (Input.isFilename()) { + CmdArgs.push_back(Input.getFilename()); + continue; +} + +const Arg = Input.getInputArg(); +if (A.getOption().matches(options::OPT_l)) { + StringRef Lib = A.getValue(); + const char *LinkLibArg; + if (Lib.ends_with(".lib")) +LinkLibArg = Args.MakeArgString(Lib); + else +LinkLibArg = Args.MakeArgString(Lib + ".lib"); + CmdArgs.push_back(LinkLibArg); + continue; +} + +// Otherwise, this is some other kind of linker input option like -Wl, -z, +// or -L. +A.renderAsInput(Args, CmdArgs); + } + + // 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.equals_insensitive("lld")) MaskRay wrote: If we don't model after existing constraints (e.g. MSVC), avoid `_insensitive` https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
@@ -0,0 +1,115 @@ +//===--- 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 +// +//===--===// + +#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 , const llvm::Triple , const ArgList ) +: ToolChain(D, Triple, Args) { + getProgramPaths().push_back(getDriver().getInstalledDir()); + if (getDriver().getInstalledDir() != getDriver().Dir) +getProgramPaths().push_back(getDriver().Dir); +} + +Tool *UEFI::buildLinker() const { return new tools::uefi::Linker(*this); } + +void tools::uefi::Linker::ConstructJob(Compilation , const JobAction , + const InputInfo , + const InputInfoList , + const ArgList , + const char *LinkingOutput) const { + ArgStringList CmdArgs; + MaskRay wrote: delete line https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
https://github.com/MaskRay requested changes to this pull request. https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
https://github.com/MaskRay edited https://github.com/llvm/llvm-project/pull/76838 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
llvmbot wrote: @llvm/pr-subscribers-clang Author: Prabhuk (Prabhuk) Changes Introduce changes necessary for UEFI X86_64 target Clang driver. Addressed the review comments originally suggested in Phabricator. Differential Revision: https://reviews.llvm.org/D159541 --- Full diff: https://github.com/llvm/llvm-project/pull/76838.diff 8 Files Affected: - (modified) clang/lib/Basic/Targets.cpp (+3) - (modified) clang/lib/Basic/Targets/OSTargets.h (+15) - (modified) clang/lib/Basic/Targets/X86.h (+37) - (modified) clang/lib/Driver/CMakeLists.txt (+1) - (modified) clang/lib/Driver/Driver.cpp (+4) - (added) clang/lib/Driver/ToolChains/UEFI.cpp (+115) - (added) clang/lib/Driver/ToolChains/UEFI.h (+61) - (added) clang/test/Driver/uefi.c (+11) ``diff diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index ea002bb464fcc5..fc39ba35de2bb0 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -625,6 +625,9 @@ std::unique_ptr AllocateTarget(const llvm::Triple , case llvm::Triple::Solaris: return std::make_unique>(Triple, Opts); +case llvm::Triple::UEFI: + return std::make_unique(Triple, Opts); + case llvm::Triple::Win32: { switch (Triple.getEnvironment()) { case llvm::Triple::Cygnus: diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index 342af4bbc42b7b..12a7b4a03f63cd 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -774,6 +774,21 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo { } }; +// UEFI target +template +class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { +protected: + void getOSDefines(const LangOptions , const llvm::Triple , +MacroBuilder ) const override {} + +public: + UEFITargetInfo(const llvm::Triple , const TargetOptions ) + : OSTargetInfo(Triple, Opts) { +this->WCharType = TargetInfo::UnsignedShort; +this->WIntType = TargetInfo::UnsignedShort; + } +}; + void addWindowsDefines(const llvm::Triple , const LangOptions , MacroBuilder ); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 0ab1c10833db26..18880a6a32727c 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -819,6 +819,43 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { } }; +// x86-64 UEFI target +class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo +: public UEFITargetInfo { +public: + UEFIX86_64TargetInfo(const llvm::Triple , const TargetOptions ) + : UEFITargetInfo(Triple, Opts) { +this->TheCXXABI.set(TargetCXXABI::Microsoft); +this->MaxTLSAlign = 8192u * this->getCharWidth(); +this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-" + "i64:64-i128:128-f80:128-n8:16:32:64-S128"); + } + + void getTargetDefines(const LangOptions , +MacroBuilder ) const override { +getOSDefines(Opts, X86TargetInfo::getTriple(), Builder); + } + + BuiltinVaListKind getBuiltinVaListKind() const override { +return TargetInfo::CharPtrBuiltinVaList; + } + + CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { +switch (CC) { +case CC_C: +case CC_Win64: + return CCCR_OK; +default: + return CCCR_Warning; +} + } + + TargetInfo::CallingConvKind + getCallingConvKind(bool ClangABICompat4) const override { +return CCK_MicrosoftWin64; + } +}; + // x86-64 Windows target class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo : public WindowsTargetInfo { diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 58427e3f83c420..7d05822b64b61b 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -78,6 +78,7 @@ add_clang_library(clangDriver ToolChains/Solaris.cpp ToolChains/SPIRV.cpp ToolChains/TCE.cpp + ToolChains/UEFI.cpp ToolChains/VEToolchain.cpp ToolChains/WebAssembly.cpp ToolChains/XCore.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 9b2f2a37480983..e5acef61bb72ba 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -45,6 +45,7 @@ #include "ToolChains/SPIRV.h" #include "ToolChains/Solaris.h" #include "ToolChains/TCE.h" +#include "ToolChains/UEFI.h" #include "ToolChains/VEToolchain.h" #include "ToolChains/WebAssembly.h" #include "ToolChains/XCore.h" @@ -6259,6 +6260,9 @@ const ToolChain ::getToolChain(const ArgList , case llvm::Triple::Mesa3D: TC = std::make_unique(*this, Target, Args); break; +case llvm::Triple::UEFI: + TC = std::make_unique(*this, Target, Args); + break; case llvm::Triple::Win32: switch (Target.getEnvironment()) { default: diff --git
[clang] [UEFI] X86_64 UEFI Clang Driver (PR #76838)
https://github.com/Prabhuk created https://github.com/llvm/llvm-project/pull/76838 Introduce changes necessary for UEFI X86_64 target Clang driver. Addressed the review comments originally suggested in Phabricator. Differential Revision: https://reviews.llvm.org/D159541 >From 178a1852982d1294bf96f688242dba983850974f Mon Sep 17 00:00:00 2001 From: prabhukr Date: Mon, 4 Dec 2023 08:54:14 -0800 Subject: [PATCH] [UEFI] X86_64 UEFI Clang Driver Introduce changes necessary for UEFI X86_64 target Clang driver. Reviewed By: phosek Differential Revision: https://reviews.llvm.org/D159541 --- clang/lib/Basic/Targets.cpp | 3 + clang/lib/Basic/Targets/OSTargets.h | 15 clang/lib/Basic/Targets/X86.h| 37 + clang/lib/Driver/CMakeLists.txt | 1 + clang/lib/Driver/Driver.cpp | 4 + clang/lib/Driver/ToolChains/UEFI.cpp | 115 +++ clang/lib/Driver/ToolChains/UEFI.h | 61 ++ clang/test/Driver/uefi.c | 11 +++ 8 files changed, 247 insertions(+) create mode 100644 clang/lib/Driver/ToolChains/UEFI.cpp create mode 100644 clang/lib/Driver/ToolChains/UEFI.h create mode 100644 clang/test/Driver/uefi.c diff --git a/clang/lib/Basic/Targets.cpp b/clang/lib/Basic/Targets.cpp index ea002bb464fcc5..fc39ba35de2bb0 100644 --- a/clang/lib/Basic/Targets.cpp +++ b/clang/lib/Basic/Targets.cpp @@ -625,6 +625,9 @@ std::unique_ptr AllocateTarget(const llvm::Triple , case llvm::Triple::Solaris: return std::make_unique>(Triple, Opts); +case llvm::Triple::UEFI: + return std::make_unique(Triple, Opts); + case llvm::Triple::Win32: { switch (Triple.getEnvironment()) { case llvm::Triple::Cygnus: diff --git a/clang/lib/Basic/Targets/OSTargets.h b/clang/lib/Basic/Targets/OSTargets.h index 342af4bbc42b7b..12a7b4a03f63cd 100644 --- a/clang/lib/Basic/Targets/OSTargets.h +++ b/clang/lib/Basic/Targets/OSTargets.h @@ -774,6 +774,21 @@ class LLVM_LIBRARY_VISIBILITY ZOSTargetInfo : public OSTargetInfo { } }; +// UEFI target +template +class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo { +protected: + void getOSDefines(const LangOptions , const llvm::Triple , +MacroBuilder ) const override {} + +public: + UEFITargetInfo(const llvm::Triple , const TargetOptions ) + : OSTargetInfo(Triple, Opts) { +this->WCharType = TargetInfo::UnsignedShort; +this->WIntType = TargetInfo::UnsignedShort; + } +}; + void addWindowsDefines(const llvm::Triple , const LangOptions , MacroBuilder ); diff --git a/clang/lib/Basic/Targets/X86.h b/clang/lib/Basic/Targets/X86.h index 0ab1c10833db26..18880a6a32727c 100644 --- a/clang/lib/Basic/Targets/X86.h +++ b/clang/lib/Basic/Targets/X86.h @@ -819,6 +819,43 @@ class LLVM_LIBRARY_VISIBILITY X86_64TargetInfo : public X86TargetInfo { } }; +// x86-64 UEFI target +class LLVM_LIBRARY_VISIBILITY UEFIX86_64TargetInfo +: public UEFITargetInfo { +public: + UEFIX86_64TargetInfo(const llvm::Triple , const TargetOptions ) + : UEFITargetInfo(Triple, Opts) { +this->TheCXXABI.set(TargetCXXABI::Microsoft); +this->MaxTLSAlign = 8192u * this->getCharWidth(); +this->resetDataLayout("e-m:w-p270:32:32-p271:32:32-p272:64:64-" + "i64:64-i128:128-f80:128-n8:16:32:64-S128"); + } + + void getTargetDefines(const LangOptions , +MacroBuilder ) const override { +getOSDefines(Opts, X86TargetInfo::getTriple(), Builder); + } + + BuiltinVaListKind getBuiltinVaListKind() const override { +return TargetInfo::CharPtrBuiltinVaList; + } + + CallingConvCheckResult checkCallingConvention(CallingConv CC) const override { +switch (CC) { +case CC_C: +case CC_Win64: + return CCCR_OK; +default: + return CCCR_Warning; +} + } + + TargetInfo::CallingConvKind + getCallingConvKind(bool ClangABICompat4) const override { +return CCK_MicrosoftWin64; + } +}; + // x86-64 Windows target class LLVM_LIBRARY_VISIBILITY WindowsX86_64TargetInfo : public WindowsTargetInfo { diff --git a/clang/lib/Driver/CMakeLists.txt b/clang/lib/Driver/CMakeLists.txt index 58427e3f83c420..7d05822b64b61b 100644 --- a/clang/lib/Driver/CMakeLists.txt +++ b/clang/lib/Driver/CMakeLists.txt @@ -78,6 +78,7 @@ add_clang_library(clangDriver ToolChains/Solaris.cpp ToolChains/SPIRV.cpp ToolChains/TCE.cpp + ToolChains/UEFI.cpp ToolChains/VEToolchain.cpp ToolChains/WebAssembly.cpp ToolChains/XCore.cpp diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 9b2f2a37480983..e5acef61bb72ba 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -45,6 +45,7 @@ #include "ToolChains/SPIRV.h" #include "ToolChains/Solaris.h" #include "ToolChains/TCE.h" +#include "ToolChains/UEFI.h" #include "ToolChains/VEToolchain.h" #include