https://github.com/jhuber6 updated https://github.com/llvm/llvm-project/pull/229075
>From cde1f2004cd50563abc92e7f8aa5721f4c58d4f8 Mon Sep 17 00:00:00 2001 From: "Kornev, Nikita" <[email protected]> Date: Mon, 5 Oct 2026 14:56:07 +0200 Subject: [PATCH 1/2] [offload-arch] Fix clangOffloadArch link with BUILD_SHARED_LIBS=ON add_llvm_library ignores STATIC, so with BUILD_SHARED_LIBS=ON the library was built as a shared object and failed to link because Verbose is defined in the tool. Build it with llvm_add_library STATIC and move Verbose and OffloadArchCategory into the library. Fixes build failures after #226552. Co-Authored-By: Claude Opus 5.5 <[email protected]> --- clang/tools/offload-arch/OffloadArch.cpp | 7 ++---- clang/tools/offload-arch/lib/CMakeLists.txt | 9 ++++---- .../offload-arch/lib/OffloadArchOptions.cpp | 22 +++++++++++++++++++ .../tools/offload-arch/OffloadArchTest.cpp | 3 --- 4 files changed, 29 insertions(+), 12 deletions(-) create mode 100644 clang/tools/offload-arch/lib/OffloadArchOptions.cpp diff --git a/clang/tools/offload-arch/OffloadArch.cpp b/clang/tools/offload-arch/OffloadArch.cpp index 934d20fd95f72..68404c0da1aba 100644 --- a/clang/tools/offload-arch/OffloadArch.cpp +++ b/clang/tools/offload-arch/OffloadArch.cpp @@ -12,8 +12,8 @@ using namespace llvm; -// Mark all our options with this category. -static cl::OptionCategory OffloadArchCategory("offload-arch options"); +// Defined in lib/OffloadArchOptions.cpp. +extern cl::OptionCategory OffloadArchCategory; extern cl::OptionCategory AMDGPUArchByHIPCategory; @@ -32,9 +32,6 @@ static cl::opt<VendorName> clEnumVal(nvptx, "Only print NVIDIA GPUs"), clEnumVal(intel, "Only print Intel GPUs"))); -cl::opt<bool> Verbose("verbose", cl::desc("Enable verbose output"), - cl::init(false), cl::cat(OffloadArchCategory)); - static void PrintVersion(raw_ostream &OS) { OS << clang::getClangToolFullVersion("offload-arch") << '\n'; } diff --git a/clang/tools/offload-arch/lib/CMakeLists.txt b/clang/tools/offload-arch/lib/CMakeLists.txt index 2692229dc675b..26c88ad701001 100644 --- a/clang/tools/offload-arch/lib/CMakeLists.txt +++ b/clang/tools/offload-arch/lib/CMakeLists.txt @@ -1,12 +1,13 @@ # Not add_clang_library: this is not part of clang's public library interface, -# the sources are shared between offload-arch and its unit tests. -add_llvm_library(clangOffloadArch STATIC +# the sources are shared between offload-arch and its unit tests. Use +# llvm_add_library directly, because add_llvm_library ignores STATIC and builds +# a shared library with BUILD_SHARED_LIBS=ON, which is never installed. +llvm_add_library(clangOffloadArch STATIC AMDGPUArchByHIP.cpp AMDGPUArchByKFD.cpp LevelZeroArch.cpp NVPTXArch.cpp - - BUILDTREE_ONLY + OffloadArchOptions.cpp LINK_COMPONENTS Support diff --git a/clang/tools/offload-arch/lib/OffloadArchOptions.cpp b/clang/tools/offload-arch/lib/OffloadArchOptions.cpp new file mode 100644 index 0000000000000..5f6d334d7ddfe --- /dev/null +++ b/clang/tools/offload-arch/lib/OffloadArchOptions.cpp @@ -0,0 +1,22 @@ +//===- OffloadArchOptions.cpp - options shared by offload-arch -*- 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 +// +//===----------------------------------------------------------------------===// +// +// This file defines the command line options used by both the offload-arch +// tool and the vendor-specific GPU detection code. +// +//===----------------------------------------------------------------------===// + +#include "llvm/Support/CommandLine.h" + +using namespace llvm; + +// Mark all our options with this category. +cl::OptionCategory OffloadArchCategory("offload-arch options"); + +cl::opt<bool> Verbose("verbose", cl::desc("Enable verbose output"), + cl::init(false), cl::cat(OffloadArchCategory)); diff --git a/clang/unittests/tools/offload-arch/OffloadArchTest.cpp b/clang/unittests/tools/offload-arch/OffloadArchTest.cpp index 7de00610bd189..1c14209a537e5 100644 --- a/clang/unittests/tools/offload-arch/OffloadArchTest.cpp +++ b/clang/unittests/tools/offload-arch/OffloadArchTest.cpp @@ -8,7 +8,6 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/ADT/StringRef.h" -#include "llvm/Support/CommandLine.h" #include "llvm/Support/FileSystem.h" #include "llvm/Support/Path.h" #include "llvm/Support/Process.h" @@ -35,8 +34,6 @@ std::string getIntelGPUArchName(uint32_t IPVersion); using namespace llvm; -cl::opt<bool> Verbose("offload-arch-test-verbose", cl::Hidden, cl::init(false)); - #ifdef _WIN32 // --- compareVersions --- >From 8c2a7851a12297a7b8f6edd3ddc5475d862ec956 Mon Sep 17 00:00:00 2001 From: Joseph Huber <[email protected]> Date: Mon, 5 Oct 2026 08:48:55 -0500 Subject: [PATCH 2/2] Remove unnecessary CMakeLists.txt comments --- clang/tools/offload-arch/lib/CMakeLists.txt | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/clang/tools/offload-arch/lib/CMakeLists.txt b/clang/tools/offload-arch/lib/CMakeLists.txt index 26c88ad701001..218a5ff734de9 100644 --- a/clang/tools/offload-arch/lib/CMakeLists.txt +++ b/clang/tools/offload-arch/lib/CMakeLists.txt @@ -1,7 +1,5 @@ # Not add_clang_library: this is not part of clang's public library interface, -# the sources are shared between offload-arch and its unit tests. Use -# llvm_add_library directly, because add_llvm_library ignores STATIC and builds -# a shared library with BUILD_SHARED_LIBS=ON, which is never installed. +# the sources are shared between offload-arch and its unit tests. llvm_add_library(clangOffloadArch STATIC AMDGPUArchByHIP.cpp AMDGPUArchByKFD.cpp _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
