Skip to content

Conversation

Prabhuk
Copy link
Contributor

@Prabhuk Prabhuk commented Jan 3, 2024

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

@Prabhuk Prabhuk self-assigned this Jan 3, 2024
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Jan 3, 2024
@llvmbot
Copy link
Member

llvmbot commented Jan 3, 2024

@llvm/pr-subscribers-backend-x86
@llvm/pr-subscribers-clang-driver

@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 --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<TargetInfo> AllocateTarget(const llvm::Triple &Triple,
     case llvm::Triple::Solaris:
       return std::make_unique<SolarisTargetInfo<X86_64TargetInfo>>(Triple,
                                                                    Opts);
+    case llvm::Triple::UEFI:
+      return std::make_unique<UEFIX86_64TargetInfo>(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<Target> {
   }
 };
 
+// UEFI target
+template <typename Target>
+class LLVM_LIBRARY_VISIBILITY UEFITargetInfo : public OSTargetInfo<Target> {
+protected:
+  void getOSDefines(const LangOptions &Opts, const llvm::Triple &Triple,
+                    MacroBuilder &Builder) const override {}
+
+public:
+  UEFITargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+      : OSTargetInfo<Target>(Triple, Opts) {
+    this->WCharType = TargetInfo::UnsignedShort;
+    this->WIntType = TargetInfo::UnsignedShort;
+  }
+};
+
 void addWindowsDefines(const llvm::Triple &Triple, const LangOptions &Opts,
                        MacroBuilder &Builder);
 
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<X86_64TargetInfo> {
+public:
+  UEFIX86_64TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
+      : UEFITargetInfo<X86_64TargetInfo>(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 &Opts,
+                        MacroBuilder &Builder) 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<X86_64TargetInfo> {
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 &Driver::getToolChain(const ArgList &Args,
     case llvm::Triple::Mesa3D:
       TC = std::make_unique<toolchains::AMDGPUToolChain>(*this, Target, Args);
       break;
+    case llvm::Triple::UEFI:
+      TC = std::make_unique<toolchains::UEFI>(*this, Target, Args);
+      break;
     case llvm::Triple::Win32:
       switch (Target.getEnvironment()) {
       default:
diff --git a/clang/lib/Driver/ToolChains/UEFI.cpp b/clang/lib/Driver/ToolChains/UEFI.cpp
new file mode 100644
index 00000000000000..9030aaada93b5a
--- /dev/null
+++ b/clang/lib/Driver/ToolChains/UEFI.cpp
@@ -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 &D, const llvm::Triple &Triple, const ArgList &Args)
+    : 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 &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");
+
+  // "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 &Input : Inputs) {
+    if (Input.isFilename()) {
+      CmdArgs.push_back(Input.getFilename());
+      continue;
+    }
+
+    const Arg &A = 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"))
+    Linker = "lld-link";
+
+  auto LinkerPath = TC.GetProgramPath(Linker.str().c_str());
+  auto LinkCmd = std::make_unique<Command>(
+      JA, *this, ResponseFileSupport::AtFileUTF16(),
+      Args.MakeArgString(LinkerPath), CmdArgs, Inputs, Output);
+  C.addCommand(std::move(LinkCmd));
+}
diff --git a/clang/lib/Driver/ToolChains/UEFI.h b/clang/lib/Driver/ToolChains/UEFI.h
new file mode 100644
index 00000000000000..3e1cc558aa7d17
--- /dev/null
+++ b/clang/lib/Driver/ToolChains/UEFI.h
@@ -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 &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; }
+  bool isPIEDefault(const llvm::opt::ArgList &Args) const override {
+    return false;
+  }
+  bool isPICDefaultForced() const override { return true; }
+};
+
+} // namespace toolchains
+} // namespace driver
+} // namespace clang
+
+#endif // LLVM_CLANG_LIB_DRIVER_TOOLCHAINS_UEFI_H
diff --git a/clang/test/Driver/uefi.c b/clang/test/Driver/uefi.c
new file mode 100644
index 00000000000000..df4edfeb4bcdbe
--- /dev/null
+++ b/clang/test/Driver/uefi.c
@@ -0,0 +1,11 @@
+// RUN: %clang -### %s --target=x86_64-unknown-uefi \
+// RUN:     --sysroot=%S/platform -fuse-ld=lld 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: "-subsystem:efi_application"
+// CHECK-SAME: "-entry:EfiMain"
+// CHECK-SAME: "-tsaware:no"
+// CHECK-SAME: "-dll"

@brad0
Copy link
Contributor

brad0 commented Jan 26, 2024

Ping.

@brad0 brad0 requested a review from MaskRay March 8, 2024 23:14
@MaskRay
Copy link
Member

MaskRay commented May 10, 2024

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.

@Prabhuk
Copy link
Contributor Author

Prabhuk commented Sep 3, 2024

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.

Thank you! I believe the test in clang/test/Driver/uefi-constructed-args.c covers all constructed args. PTAL.

@Prabhuk Prabhuk requested a review from mysterymath September 11, 2024 17:24
Copy link
Contributor

@mysterymath mysterymath left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM from my POV.

@MaskRay
Copy link
Member

MaskRay commented Sep 17, 2024

`[Driver] Add toolchain for ...' might be a more conventional patch subject.

@Prabhuk Prabhuk changed the title [UEFI] X86_64 UEFI Clang Driver [Driver] Add toolchain for X86_64 UEFI Sep 18, 2024
@Prabhuk Prabhuk changed the title [Driver] Add toolchain for X86_64 UEFI [Driver] Add toolchain for X86_64 UEFI targets Sep 18, 2024
@Prabhuk Prabhuk changed the title [Driver] Add toolchain for X86_64 UEFI targets [Driver] Add toolchain for X86_64 UEFI target Sep 18, 2024
@Prabhuk Prabhuk merged commit d1335fb into llvm:main Sep 19, 2024
5 of 7 checks passed
@Prabhuk Prabhuk deleted the uefi_support branch September 19, 2024 18:47
@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 19, 2024

LLVM Buildbot has detected a new failure on builder llvm-clang-aarch64-darwin running on doug-worker-4 while building clang at step 6 "test-build-unified-tree-check-all".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/190/builds/6103

Here is the relevant piece of the build log for the reference
Step 6 (test-build-unified-tree-check-all) failure: test (failure)
******************** TEST 'Clang :: Driver/uefi-constructed-args.c' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
RUN: at line 1: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang --driver-mode=cl -### /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/uefi-constructed-args.c --target=x86_64-unknown-uefi      --sysroot=/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/platform -fuse-ld=lld -g 2>&1      | /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefixes=CHECK /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/uefi-constructed-args.c
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/clang --driver-mode=cl -### /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/uefi-constructed-args.c --target=x86_64-unknown-uefi --sysroot=/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/platform -fuse-ld=lld -g
+ /Users/buildbot/buildbot-root/aarch64-darwin/build/bin/FileCheck -check-prefixes=CHECK /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/uefi-constructed-args.c
�[1m/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/uefi-constructed-args.c:4:11: �[0m�[0;1;31merror: �[0m�[1mCHECK: expected string not found in input
�[0m// CHECK: "-cc1"
�[0;1;32m          ^
�[0m�[1m<stdin>:1:1: �[0m�[0;1;30mnote: �[0m�[1mscanning from here
�[0mclang: warning: unknown argument ignored in clang-cl: '--sysroot=/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/platform' [-Wunknown-argument]
�[0;1;32m^
�[0m�[1m<stdin>:1:49: �[0m�[0;1;30mnote: �[0m�[1mpossible intended match here
�[0mclang: warning: unknown argument ignored in clang-cl: '--sysroot=/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/platform' [-Wunknown-argument]
�[0;1;32m                                                ^
�[0m
Input file: <stdin>
Check file: /Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/uefi-constructed-args.c

-dump-input=help explains the following input dump.

Input was:
<<<<<<
�[1m�[0m�[0;1;30m           1: �[0m�[1m�[0;1;46mclang: warning: unknown argument ignored in clang-cl: '--sysroot=/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/platform' [-Wunknown-argument] �[0m
�[0;1;31mcheck:4'0     X~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ error: no match found
�[0m�[0;1;35mcheck:4'1                                                     ?                                                                                                                            possible intended match
�[0m�[0;1;30m           2: �[0m�[1m�[0;1;46mclang version 20.0.0git (https://github.com/llvm/llvm-project.git d1335fb86466221b0499db5fc8f158f1f64d9542) �[0m
�[0;1;31mcheck:4'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m           3: �[0m�[1m�[0;1;46mTarget: x86_64-unknown-uefi �[0m
�[0;1;31mcheck:4'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m           4: �[0m�[1m�[0;1;46mThread model: posix �[0m
�[0;1;31mcheck:4'0     ~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m           5: �[0m�[1m�[0;1;46mInstalledDir: /Users/buildbot/buildbot-root/aarch64-darwin/build/bin �[0m
�[0;1;31mcheck:4'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m           6: �[0m�[1m�[0;1;46mBuild config: +assertions �[0m
�[0;1;31mcheck:4'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m           7: �[0m�[1m�[0;1;46mclang: warning: '/Users/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/uefi-constructed-args.c' treated as the '/U' option [-Wslash-u-filename] �[0m
�[0;1;31mcheck:4'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m           8: �[0m�[1m�[0;1;46mclang: note: use '--' to treat subsequent arguments as filenames �[0m
�[0;1;31mcheck:4'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m           9: �[0m�[1m�[0;1;46mclang: warning: argument unused during compilation: '/U sers/buildbot/buildbot-root/aarch64-darwin/llvm-project/clang/test/Driver/uefi-constructed-args.c' [-Wunused-command-line-argument] �[0m
�[0;1;31mcheck:4'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m          10: �[0m�[1m�[0;1;46mclang: warning: argument unused during compilation: '-fuse-ld=lld' [-Wunused-command-line-argument] �[0m
�[0;1;31mcheck:4'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m�[0;1;30m          11: �[0m�[1m�[0;1;46mclang: warning: argument unused during compilation: '-g' [-Wunused-command-line-argument] �[0m
�[0;1;31mcheck:4'0     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
�[0m>>>>>>

...

bhandarkar-pranav added a commit to bhandarkar-pranav/llvm-project that referenced this pull request Sep 19, 2024
This PR is a fix for issue llvm#109328. libclangSerializaton.so is
needed for building clang driver unittests after
llvm#76838 was merged.
@bhandarkar-pranav
Copy link
Contributor

Hi @Prabhuk,
I am seeing this issue #109328 after this PR. Here is a proposed fix. Could you please check?

@llvm-ci
Copy link
Collaborator

llvm-ci commented Sep 19, 2024

LLVM Buildbot has detected a new failure on builder clang-ppc64le-linux-multistage running on ppc64le-clang-multistage-test while building clang at step 5 "ninja check 1".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/76/builds/2986

Here is the relevant piece of the build log for the reference
Step 5 (ninja check 1) failure: stage 1 checked (failure)
...
[77/85] Generating POWERPC64LELinuxConfig/Asan-powerpc64le-calls-Noinst-Test
[78/85] Generating ASAN_NOINST_TEST_OBJECTS.gtest-all.cc.powerpc64le-inline.o
[79/85] Generating POWERPC64LELinuxConfig/Asan-powerpc64le-inline-Noinst-Test
[80/85] Generating ASAN_INST_TEST_OBJECTS.gtest-all.cc.powerpc64le-calls.o
[81/85] Generating POWERPC64LELinuxDynamicConfig/Asan-powerpc64le-calls-Dynamic-Test
[82/85] Generating POWERPC64LELinuxConfig/Asan-powerpc64le-calls-Test
[83/85] Generating ASAN_INST_TEST_OBJECTS.gtest-all.cc.powerpc64le-inline.o
[84/85] Generating POWERPC64LELinuxDynamicConfig/Asan-powerpc64le-inline-Dynamic-Test
[85/85] Generating POWERPC64LELinuxConfig/Asan-powerpc64le-inline-Test
[1159/1165] Linking CXX executable tools/clang/unittests/Driver/ClangDriverTests
FAILED: tools/clang/unittests/Driver/ClangDriverTests 
: && /usr/lib64/ccache/c++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -fno-lifetime-dse -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wno-missing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wno-uninitialized -Wno-nonnull -Wno-class-memaccess -Wno-noexcept-type -Wdelete-non-virtual-dtor -Wno-comment -Wno-misleading-indentation -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -fno-strict-aliasing -O3 -DNDEBUG -Wl,--gc-sections tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/DistroTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/DXCModeTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/GCCVersionTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/ToolChainTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/ModuleCacheTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/MultilibBuilderTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/MultilibTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/SanitizerArgsTest.cpp.o -o tools/clang/unittests/Driver/ClangDriverTests  -Wl,-rpath,/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/lib  lib/libLLVMAArch64CodeGen.so.20.0git  lib/libLLVMAArch64AsmParser.so.20.0git  lib/libLLVMAArch64Disassembler.so.20.0git  lib/libLLVMAMDGPUCodeGen.so.20.0git  lib/libLLVMAMDGPUAsmParser.so.20.0git  lib/libLLVMAMDGPUDisassembler.so.20.0git  lib/libLLVMARMCodeGen.so.20.0git  lib/libLLVMARMAsmParser.so.20.0git  lib/libLLVMARMDisassembler.so.20.0git  lib/libLLVMAVRCodeGen.so.20.0git  lib/libLLVMAVRAsmParser.so.20.0git  lib/libLLVMAVRDesc.so.20.0git  lib/libLLVMAVRDisassembler.so.20.0git  lib/libLLVMAVRInfo.so.20.0git  lib/libLLVMBPFCodeGen.so.20.0git  lib/libLLVMBPFAsmParser.so.20.0git  lib/libLLVMBPFDesc.so.20.0git  lib/libLLVMBPFDisassembler.so.20.0git  lib/libLLVMBPFInfo.so.20.0git  lib/libLLVMHexagonCodeGen.so.20.0git  lib/libLLVMHexagonAsmParser.so.20.0git  lib/libLLVMHexagonDisassembler.so.20.0git  lib/libLLVMLanaiCodeGen.so.20.0git  lib/libLLVMLanaiAsmParser.so.20.0git  lib/libLLVMLanaiDisassembler.so.20.0git  lib/libLLVMLoongArchCodeGen.so.20.0git  lib/libLLVMLoongArchAsmParser.so.20.0git  lib/libLLVMLoongArchDisassembler.so.20.0git  lib/libLLVMMipsCodeGen.so.20.0git  lib/libLLVMMipsAsmParser.so.20.0git  lib/libLLVMMipsDesc.so.20.0git  lib/libLLVMMipsDisassembler.so.20.0git  lib/libLLVMMipsInfo.so.20.0git  lib/libLLVMMSP430CodeGen.so.20.0git  lib/libLLVMMSP430AsmParser.so.20.0git  lib/libLLVMMSP430Desc.so.20.0git  lib/libLLVMMSP430Disassembler.so.20.0git  lib/libLLVMMSP430Info.so.20.0git  lib/libLLVMNVPTXCodeGen.so.20.0git  lib/libLLVMNVPTXDesc.so.20.0git  lib/libLLVMNVPTXInfo.so.20.0git  lib/libLLVMPowerPCCodeGen.so.20.0git  lib/libLLVMPowerPCAsmParser.so.20.0git  lib/libLLVMPowerPCDesc.so.20.0git  lib/libLLVMPowerPCDisassembler.so.20.0git  lib/libLLVMPowerPCInfo.so.20.0git  lib/libLLVMRISCVCodeGen.so.20.0git  lib/libLLVMRISCVAsmParser.so.20.0git  lib/libLLVMRISCVDisassembler.so.20.0git  lib/libLLVMSparcCodeGen.so.20.0git  lib/libLLVMSparcAsmParser.so.20.0git  lib/libLLVMSparcDesc.so.20.0git  lib/libLLVMSparcDisassembler.so.20.0git  lib/libLLVMSparcInfo.so.20.0git  lib/libLLVMSystemZCodeGen.so.20.0git  lib/libLLVMSystemZAsmParser.so.20.0git  lib/libLLVMSystemZDisassembler.so.20.0git  lib/libLLVMVECodeGen.so.20.0git  lib/libLLVMVEAsmParser.so.20.0git  lib/libLLVMVEDesc.so.20.0git  lib/libLLVMVEDisassembler.so.20.0git  lib/libLLVMVEInfo.so.20.0git  lib/libLLVMWebAssemblyCodeGen.so.20.0git  lib/libLLVMWebAssemblyAsmParser.so.20.0git  lib/libLLVMWebAssemblyDisassembler.so.20.0git  lib/libLLVMWebAssemblyUtils.so.20.0git  lib/libLLVMX86CodeGen.so.20.0git  lib/libLLVMX86AsmParser.so.20.0git  lib/libLLVMX86Desc.so.20.0git  lib/libLLVMX86
CoreDisassembler.so.20.0git  lib/libLLVMXCoreInfo.so.20.0git  -lpthread  lib/libllvm_gtest_main.so.20.0git  lib/libllvm_gtest.so.20.0git  -lpthread  lib/libclangFrontend.so.20.0git  lib/libLLVMAArch64Desc.so.20.0git  lib/libLLVMAArch64Info.so.20.0git  lib/libLLVMAArch64Utils.so.20.0git  lib/libLLVMAMDGPUDesc.so.20.0git  lib/libLLVMAMDGPUInfo.so.20.0git  lib/libLLVMAMDGPUUtils.so.20.0git  lib/libLLVMARMDesc.so.20.0git  lib/libLLVMARMInfo.so.20.0git  lib/libLLVMARMUtils.so.20.0git  lib/libLLVMHexagonDesc.so.20.0git  lib/libLLVMHexagonInfo.so.20.0git  lib/libLLVMLanaiDesc.so.20.0git  lib/libLLVMLanaiInfo.so.20.0git  lib/libLLVMLoongArchDesc.so.20.0git  lib/libLLVMLoongArchInfo.so.20.0git  lib/libLLVMRISCVDesc.so.20.0git  lib/libLLVMRISCVInfo.so.20.0git  lib/libLLVMSystemZDesc.so.20.0git  lib/libLLVMSystemZInfo.so.20.0git  lib/libLLVMWebAssemblyDesc.so.20.0git  lib/libLLVMWebAssemblyInfo.so.20.0git  lib/libclangDriver.so.20.0git  lib/libLLVMOption.so.20.0git  lib/libclangBasic.so.20.0git  lib/libLLVMMC.so.20.0git  lib/libLLVMTargetParser.so.20.0git  lib/libLLVMSupport.so.20.0git  -Wl,-rpath-link,/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/lib && :
/usr/bin/ld: tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/ToolChainTest.cpp.o: undefined reference to symbol '_ZN5clang22PCHContainerOperationsC1Ev'
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1/lib/libclangSerialization.so.20.0git: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
[1160/1165] Linking CXX executable tools/clang/unittests/Tooling/ToolingTests
ninja: build stopped: subcommand failed.
Step 11 (ninja check 2) failure: stage 2 checked (failure)
...
2 warning(s) in tests

Testing Time: 181.18s

Total Discovered Tests: 4263
  Skipped          :    9 (0.21%)
  Unsupported      : 1158 (27.16%)
  Passed           : 3054 (71.64%)
  Expectedly Failed:   42 (0.99%)
[890/1165] Linking CXX executable tools/clang/unittests/Driver/ClangDriverTests
FAILED: tools/clang/unittests/Driver/ClangDriverTests 
: && /home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage1.install/bin/clang++ -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -fno-common -Woverloaded-virtual -Wno-nested-anon-types -O3 -DNDEBUG -Wl,--gc-sections tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/DistroTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/DXCModeTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/GCCVersionTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/ToolChainTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/ModuleCacheTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/MultilibBuilderTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/MultilibTest.cpp.o tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/SanitizerArgsTest.cpp.o -o tools/clang/unittests/Driver/ClangDriverTests  -Wl,-rpath,/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage2/lib  lib/libLLVMAArch64CodeGen.so.20.0git  lib/libLLVMAArch64AsmParser.so.20.0git  lib/libLLVMAArch64Disassembler.so.20.0git  lib/libLLVMAMDGPUCodeGen.so.20.0git  lib/libLLVMAMDGPUAsmParser.so.20.0git  lib/libLLVMAMDGPUDisassembler.so.20.0git  lib/libLLVMARMCodeGen.so.20.0git  lib/libLLVMARMAsmParser.so.20.0git  lib/libLLVMARMDisassembler.so.20.0git  lib/libLLVMAVRCodeGen.so.20.0git  lib/libLLVMAVRAsmParser.so.20.0git  lib/libLLVMAVRDesc.so.20.0git  lib/libLLVMAVRDisassembler.so.20.0git  lib/libLLVMAVRInfo.so.20.0git  lib/libLLVMBPFCodeGen.so.20.0git  lib/libLLVMBPFAsmParser.so.20.0git  lib/libLLVMBPFDesc.so.20.0git  lib/libLLVMBPFDisassembler.so.20.0git  lib/libLLVMBPFInfo.so.20.0git  lib/libLLVMHexagonCodeGen.so.20.0git  lib/libLLVMHexagonAsmParser.so.20.0git  lib/libLLVMHexagonDisassembler.so.20.0git  lib/libLLVMLanaiCodeGen.so.20.0git  lib/libLLVMLanaiAsmParser.so.20.0git  lib/libLLVMLanaiDisassembler.so.20.0git  lib/libLLVMLoongArchCodeGen.so.20.0git  lib/libLLVMLoongArchAsmParser.so.20.0git  lib/libLLVMLoongArchDisassembler.so.20.0git  lib/libLLVMMipsCodeGen.so.20.0git  lib/libLLVMMipsAsmParser.so.20.0git  lib/libLLVMMipsDesc.so.20.0git  lib/libLLVMMipsDisassembler.so.20.0git  lib/libLLVMMipsInfo.so.20.0git  lib/libLLVMMSP430CodeGen.so.20.0git  lib/libLLVMMSP430AsmParser.so.20.0git  lib/libLLVMMSP430Desc.so.20.0git  lib/libLLVMMSP430Disassembler.so.20.0git  lib/libLLVMMSP430Info.so.20.0git  lib/libLLVMNVPTXCodeGen.so.20.0git  lib/libLLVMNVPTXDesc.so.20.0git  lib/libLLVMNVPTXInfo.so.20.0git  lib/libLLVMPowerPCCodeGen.so.20.0git  lib/libLLVMPowerPCAsmParser.so.20.0git  lib/libLLVMPowerPCDesc.so.20.0git  lib/libLLVMPowerPCDisassembler.so.20.0git  lib/libLLVMPowerPCInfo.so.20.0git  lib/libLLVMRISCVCodeGen.so.20.0git  lib/libLLVMRISCVAsmParser.so.20.0git  lib/libLLVMRISCVDisassembler.so.20.0git  lib/libLLVMSparcCodeGen.so.20.0git  lib/libLLVMSparcAsmParser.so.20.0git  lib/libLLVMSparcDesc.so.20.0git  lib/libLLVMSparcDisassembler.so.20.0git  lib/libLLVMSparcInfo.so.20.0git  lib/libLLVMSystemZCodeGen.so.20.0git  lib/libLLVMSystemZAsmParser.so.20.0git  lib/libLLVMSystemZDisassembler.so.20.0git  lib/libLLVMVECodeGen.so.20.0git  lib/libLLVMVEAsmParser.so.20.0git  lib/libLLVMVEDesc.so.20.0git  lib/libLLVMVEDisassembler.so.20.0git  lib/libLLVMVEInfo.so.20.0git  lib/libLLVMWebAssemblyCodeGen.so.20.0git  lib/libLLVMWebAssemblyAsmParser.so.20.0git  lib/libLLVMWeb
.0git  lib/libLLVMX86Desc.so.20.0git  lib/libLLVMX86Disassembler.so.20.0git  lib/libLLVMX86Info.so.20.0git  lib/libLLVMXCoreCodeGen.so.20.0git  lib/libLLVMXCoreDesc.so.20.0git  lib/libLLVMXCoreDisassembler.so.20.0git  lib/libLLVMXCoreInfo.so.20.0git  -lpthread  lib/libllvm_gtest_main.so.20.0git  lib/libllvm_gtest.so.20.0git  -lpthread  lib/libclangFrontend.so.20.0git  lib/libLLVMAArch64Desc.so.20.0git  lib/libLLVMAArch64Info.so.20.0git  lib/libLLVMAArch64Utils.so.20.0git  lib/libLLVMAMDGPUDesc.so.20.0git  lib/libLLVMAMDGPUInfo.so.20.0git  lib/libLLVMAMDGPUUtils.so.20.0git  lib/libLLVMARMDesc.so.20.0git  lib/libLLVMARMInfo.so.20.0git  lib/libLLVMARMUtils.so.20.0git  lib/libLLVMHexagonDesc.so.20.0git  lib/libLLVMHexagonInfo.so.20.0git  lib/libLLVMLanaiDesc.so.20.0git  lib/libLLVMLanaiInfo.so.20.0git  lib/libLLVMLoongArchDesc.so.20.0git  lib/libLLVMLoongArchInfo.so.20.0git  lib/libLLVMRISCVDesc.so.20.0git  lib/libLLVMRISCVInfo.so.20.0git  lib/libLLVMSystemZDesc.so.20.0git  lib/libLLVMSystemZInfo.so.20.0git  lib/libLLVMWebAssemblyDesc.so.20.0git  lib/libLLVMWebAssemblyInfo.so.20.0git  lib/libclangDriver.so.20.0git  lib/libLLVMOption.so.20.0git  lib/libclangBasic.so.20.0git  lib/libLLVMMC.so.20.0git  lib/libLLVMTargetParser.so.20.0git  lib/libLLVMSupport.so.20.0git  -Wl,-rpath-link,/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage2/lib && :
/usr/bin/ld: tools/clang/unittests/Driver/CMakeFiles/ClangDriverTests.dir/ToolChainTest.cpp.o: undefined reference to symbol '_ZN5clang22PCHContainerOperationsC1Ev'
/home/buildbots/llvm-external-buildbots/workers/ppc64le-clang-multistage-test/clang-ppc64le-multistage/stage2/lib/libclangSerialization.so.20.0git: error adding symbols: DSO missing from command line
clang++: error: linker command failed with exit code 1 (use -v to see invocation)
[1136/1165] Building CXX object unittests/ADT/CMakeFiles/ADTTests.dir/SmallVectorTest.cpp.o
[1138/1165] Building CXX object tools/clang/unittests/ASTMatchers/CMakeFiles/ASTMatchersTests.dir/ASTMatchersTraversalTest.cpp.o
[1139/1165] Building CXX object tools/clang/unittests/Tooling/CMakeFiles/ToolingTests.dir/SourceCodeTest.cpp.o
ninja: build stopped: subcommand failed.

@nico
Copy link
Contributor

nico commented Sep 19, 2024

Looks like this breaks tests on Mac: http://45.33.8.238/macm1/92471/step_6.txt

Please take a look and revert for now if it takes a while to fix.

tmsri pushed a commit to tmsri/llvm-project that referenced this pull request Sep 19, 2024
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
@bhandarkar-pranav
Copy link
Contributor

bhandarkar-pranav commented Sep 19, 2024

Looks like this breaks tests on Mac: http://45.33.8.238/macm1/92471/step_6.txt

Please take a look and revert for now if it takes a while to fix.

@nico
I cannot access the link from my work VPN, but if this is the issue (#109328) then here is a fix (#109329)

bhandarkar-pranav added a commit that referenced this pull request Sep 19, 2024
This PR is a fix for issue
[#109328](#109328).
libclangSerializaton.so is needed for building clang driver unittests
after
#76838 was merged. Needed for
builds with `BUILD_SHARED_LIBS=ON`
@Prabhuk
Copy link
Contributor Author

Prabhuk commented Sep 19, 2024

I am going to revert this and check the failures after.

Prabhuk added a commit that referenced this pull request Sep 19, 2024
Prabhuk added a commit that referenced this pull request Sep 19, 2024
Reverts #76838

Appears to be causing failures in MAC builders. First reverting the
patch and will investigate after.
@Prabhuk Prabhuk restored the uefi_support branch September 20, 2024 02:17
Prabhuk added a commit that referenced this pull request Sep 20, 2024
e-kud pushed a commit to intel/llvm that referenced this pull request Sep 20, 2024
This PR is a fix for issue
[#109328](llvm/llvm-project#109328).
libclangSerializaton.so is needed for building clang driver unittests
after
llvm/llvm-project#76838 was merged. Needed for
builds with `BUILD_SHARED_LIBS=ON`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:X86 clang:driver 'clang' and 'clang++' user-facing binaries. Not 'clang-cl' clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants