[clang] [clang-linker-wrapper] Add error handling for missing linker path (PR #113613)
Arvind Sudarsanam via cfe-commits
cfe-commits at lists.llvm.org
Thu Oct 24 14:13:33 PDT 2024
https://github.com/asudarsa updated https://github.com/llvm/llvm-project/pull/113613
>From aaaa5b890e60ad8c349254d687e96452a8f575e5 Mon Sep 17 00:00:00 2001
From: Arvind Sudarsanam <arvind.sudarsanam at intel.com>
Date: Thu, 24 Oct 2024 12:46:18 -0700
Subject: [PATCH 1/2] [clang-linker-wrapper] Add error handling for missing
linker path
Signed-off-by: Arvind Sudarsanam <arvind.sudarsanam at intel.com>
---
clang/test/Driver/linker-wrapper.c | 4 ++++
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp | 2 ++
2 files changed, 6 insertions(+)
diff --git a/clang/test/Driver/linker-wrapper.c b/clang/test/Driver/linker-wrapper.c
index 068ea2d7d3c663..4ab4051f37553e 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -250,3 +250,7 @@ __attribute__((visibility("protected"), used)) int x;
// MLLVM-SAME: -Xlinker -mllvm=-pass-remarks=foo,bar
// OFFLOAD-OPT-NOT: -Xlinker -mllvm=-pass-remarks=foo,bar
// OFFLOAD-OPT-SAME: {{$}}
+
+// Error handling when --linker-path is not provided for clang-linker-wrapper
+// RUN: not clang-linker-wrapper 2>&1 | FileCheck --check-prefix=LINKER-PATH-NOT-PROVIDED %s
+// LINKER-PATH-NOT-PROVIDED: Host linker is not available
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 9fea1fdcd5fb46..8000d0e1f48dad 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -370,6 +370,8 @@ Error runLinker(ArrayRef<StringRef> Files, const ArgList &Args) {
// Render the linker arguments and add the newly created image. We add it
// after the output file to ensure it is linked with the correct libraries.
StringRef LinkerPath = Args.getLastArgValue(OPT_linker_path_EQ);
+ if (LinkerPath.empty())
+ return createStringError("Host linker is not available");
ArgStringList NewLinkerArgs;
for (const opt::Arg *Arg : Args) {
// Do not forward arguments only intended for the linker wrapper.
>From e85288b65bd804b28dc3eb5f6b0500873db112a7 Mon Sep 17 00:00:00 2001
From: Arvind Sudarsanam <arvind.sudarsanam at intel.com>
Date: Thu, 24 Oct 2024 14:13:11 -0700
Subject: [PATCH 2/2] Modify error message
Signed-off-by: Arvind Sudarsanam <arvind.sudarsanam at intel.com>
---
clang/test/Driver/linker-wrapper.c | 2 +-
clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/test/Driver/linker-wrapper.c b/clang/test/Driver/linker-wrapper.c
index 4ab4051f37553e..470af4d5d70cac 100644
--- a/clang/test/Driver/linker-wrapper.c
+++ b/clang/test/Driver/linker-wrapper.c
@@ -253,4 +253,4 @@ __attribute__((visibility("protected"), used)) int x;
// Error handling when --linker-path is not provided for clang-linker-wrapper
// RUN: not clang-linker-wrapper 2>&1 | FileCheck --check-prefix=LINKER-PATH-NOT-PROVIDED %s
-// LINKER-PATH-NOT-PROVIDED: Host linker is not available
+// LINKER-PATH-NOT-PROVIDED: linker path missing, must pass 'linker-path'
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index 8000d0e1f48dad..9fcecaee318a79 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -371,7 +371,7 @@ Error runLinker(ArrayRef<StringRef> Files, const ArgList &Args) {
// after the output file to ensure it is linked with the correct libraries.
StringRef LinkerPath = Args.getLastArgValue(OPT_linker_path_EQ);
if (LinkerPath.empty())
- return createStringError("Host linker is not available");
+ return createStringError("linker path missing, must pass 'linker-path'");
ArgStringList NewLinkerArgs;
for (const opt::Arg *Arg : Args) {
// Do not forward arguments only intended for the linker wrapper.
More information about the cfe-commits
mailing list