Skip to content

Commit 866f7f5

Browse files
committed
[Driver][SYCL] Improve handling of linker inputs for static lib processing
When processing the command line for static archives, we go through the direct to linker values (-Wl, -Xlinker) to find any additional libraries and objects that should be included. The trigger options for that scanning was too broad, allowing too many options (including options with separate arguments) to be incorrectly processed as objects and/or libraries. Signed-off-by: Michael D Toguchi <[email protected]>
1 parent 538f652 commit 866f7f5

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2605,12 +2605,10 @@ static SmallVector<const char *, 16> getLinkerArgs(Compilation &C,
26052605
continue;
26062606
}
26072607
}
2608-
if (A->getOption().hasFlag(options::LinkerInput)) {
2609-
// Do not add any libraries that are not fully named static libs
2610-
if (A->getOption().matches(options::OPT_l) ||
2611-
A->getOption().matches(options::OPT_reserved_lib_Group) ||
2612-
A->getOption().hasFlag(options::NoArgumentUnused))
2613-
continue;
2608+
if (A->getOption().matches(options::OPT_Wl_COMMA) ||
2609+
A->getOption().matches(options::OPT_Xlinker)) {
2610+
// Parse through additional linker arguments that are meant to go
2611+
// directly to the linker.
26142612
std::string PrevArg;
26152613
for (const std::string &Value : A->getValues()) {
26162614
auto addKnownValues = [&](const StringRef &V) {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,11 +90,11 @@
9090
// WHOLE_STATIC_LIB_1: ld{{.*}} "[[INPUTO]]" "--whole-archive" "[[INPUTA]]" "[[INPUTB]]" "--no-whole-archive"
9191
// WHOLE_STATIC_LIB_2: ld{{.*}} "[[INPUTO]]" "@[[ARGFILE]]"
9292

93-
/// test -Wl,<arg> behaviors for special case handling of -z and -rpath
94-
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -L/dummy/dir %t.o -Wl,-rpath,nopass -Wl,-z,nopass %t.a %t_2.a -### 2>&1 \
93+
/// test behaviors for special case handling of -z and -rpath
94+
// 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{{(.exe)?}}" "-r" {{.*}} "{{.*}}crt1.o" "{{.*}}crti.o" "-L/dummy/dir" {{.*}} "nopass" {{.*}} "{{.*}}crtn.o"
97-
// WL_CHECK: ld{{.*}}" "-rpath" "nopass" "-z" "nopass"
96+
// WL_CHECK-NOT: ld{{(.exe)?}} "-r" {{.*}} "{{.*}}crt1.o" "{{.*}}crti.o" "-L/dummy/dir" {{.*}}"anystring" {{.*}}"nopass" {{.*}} "{{.*}}crtn.o"
97+
// WL_CHECK: ld{{.*}} "-z" "anystring" {{.*}} "-rpath" "nopass" "-z" "nopass"
9898

9999
/// ###########################################################################
100100

0 commit comments

Comments
 (0)