Skip to content

Commit 3ab8cc8

Browse files
authored
[Driver][SYCL] Fix processing for partial link step with static archives (#2661)
When encountering specific linker specific arguments (-rpath) we do not pass them along to the partial link step. Improve the processing for these options for cases where -Xlinker <arg1> -Xlinker <arg2> is used.
1 parent 51d3c20 commit 3ab8cc8

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2679,7 +2679,11 @@ static SmallVector<const char *, 16> getLinkerArgs(Compilation &C,
26792679
A->getOption().matches(options::OPT_Xlinker)) {
26802680
// Parse through additional linker arguments that are meant to go
26812681
// directly to the linker.
2682-
std::string PrevArg;
2682+
// Keep the previous arg even if it is a new argument, for example:
2683+
// -Xlinker -rpath -Xlinker <dir>.
2684+
// Without this history, we do not know that <dir> was assocated with
2685+
// -rpath and is processed incorrectly.
2686+
static std::string PrevArg;
26832687
for (const std::string &Value : A->getValues()) {
26842688
auto addKnownValues = [&](const StringRef &V) {
26852689
// Only add named static libs objects and --whole-archive options.

clang/test/Driver/sycl-offload-static-lib-2.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@
9393
/// test behaviors for special case handling of -z and -rpath
9494
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -z anystring -L/dummy/dir %t.o -Wl,-rpath,nopass -Wl,-z,nopass %t.a %t_2.a -### 2>&1 \
9595
// RUN: | FileCheck %s -check-prefixes=WL_CHECK
96-
// WL_CHECK-NOT: ld{{.*}} "-r" {{.*}} "anystring"
96+
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -z anystring -L/dummy/dir %t.o -Wl,-rpath -Wl,nopass -Xlinker -z -Xlinker nopass %t.a %t_2.a -### 2>&1 \
97+
// WL_CHECK-NOT: ld{{.*}} "-r" {{.*}} "anystring" {{.*}} "nopass"
9798
// WL_CHECK: ld{{.*}} "-z" "anystring" {{.*}} "-rpath" "nopass" "-z" "nopass"
9899

99100
/// ###########################################################################

0 commit comments

Comments
 (0)