Skip to content

Commit 1099a59

Browse files
authored
[clang-linker-wrapper] Add error handling for missing linker path (#15862)
In clang-linker-wrapper, we do not explicitly check if --linker-path is not provided. This PR adds a check to capture this. Thanks --------- Signed-off-by: Arvind Sudarsanam <[email protected]>
1 parent 6852573 commit 1099a59

File tree

4 files changed

+14
-0
lines changed

4 files changed

+14
-0
lines changed

clang/test/Driver/linker-wrapper-sycl-win.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,7 @@
112112
// CHK-CMDS-AOT-AMD-NEXT: offload-wrapper: input: [[BUNDLEROUT]], output: [[WRAPPEROUT:.*]].bc
113113
// CHK-CMDS-AOT-AMD-NEXT: "{{.*}}clang.exe"{{.*}} -c -o [[LLCOUT:.*]].o [[WRAPPEROUT]].bc
114114
// CHK-CMDS-AOT-AMD-NEXT: "{{.*}}ld" -- HOST_LINKER_FLAGS -dynamic-linker HOST_DYN_LIB -o a.out [[LLCOUT]].o HOST_LIB_PATH HOST_STAT_LIB {{.*}}.o
115+
116+
// Error handling when --linker-path is not provided for clang-linker-wrapper
117+
// RUN: not clang-linker-wrapper 2>&1 | FileCheck --check-prefix=LINKER-PATH-NOT-PROVIDED %s
118+
// LINKER-PATH-NOT-PROVIDED: linker path missing, must pass 'linker-path'

clang/test/Driver/linker-wrapper-sycl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,7 @@
190190
// CHK-CMDS-AOT-AMD-EMBED-IR-NEXT: offload-wrapper: input: [[BUNDLEROUT]], output: [[WRAPPEROUT2:.*]]
191191
// CHK-CMDS-AOT-AMD-EMBED-IR-NEXT: "{{.*}}clang"{{.*}} -c -o [[LLCOUT2:.*]] [[WRAPPEROUT2]]
192192
// CHK-CMDS-AOT-AMD-EMBED-IR-NEXT: "{{.*}}ld" -- HOST_LINKER_FLAGS -dynamic-linker HOST_DYN_LIB -o a.out [[LLCOUT1]] [[LLCOUT2]] HOST_LIB_PATH HOST_STAT_LIB {{.*}}.o
193+
194+
// Error handling when --linker-path is not provided for clang-linker-wrapper
195+
// RUN: not clang-linker-wrapper 2>&1 | FileCheck --check-prefix=LINKER-PATH-NOT-PROVIDED %s
196+
// LINKER-PATH-NOT-PROVIDED: linker path missing, must pass 'linker-path'

clang/test/Driver/linker-wrapper.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,3 +250,7 @@ __attribute__((visibility("protected"), used)) int x;
250250
// MLLVM-SAME: -Xlinker -mllvm=-pass-remarks=foo,bar
251251
// OFFLOAD-OPT-NOT: -Xlinker -mllvm=-pass-remarks=foo,bar
252252
// OFFLOAD-OPT-SAME: {{$}}
253+
254+
// Error handling when --linker-path is not provided for clang-linker-wrapper
255+
// RUN: not clang-linker-wrapper 2>&1 | FileCheck --check-prefix=LINKER-PATH-NOT-PROVIDED %s
256+
// LINKER-PATH-NOT-PROVIDED: linker path missing, must pass 'linker-path'

clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,8 @@ Error runLinker(ArrayRef<StringRef> Files, const ArgList &Args) {
411411
// Render the linker arguments and add the newly created image. We add it
412412
// after the output file to ensure it is linked with the correct libraries.
413413
StringRef LinkerPath = Args.getLastArgValue(OPT_linker_path_EQ);
414+
if (LinkerPath.empty())
415+
return createStringError("linker path missing, must pass 'linker-path'");
414416
ArgStringList NewLinkerArgs;
415417
for (const opt::Arg *Arg : Args) {
416418
// Do not forward arguments only intended for the linker wrapper.

0 commit comments

Comments
 (0)