From 9a451d724b2906a74aff2723c25f17ab73e1cc78 Mon Sep 17 00:00:00 2001 From: Andrew Gozillon Date: Tue, 5 Nov 2019 19:31:40 +0000 Subject: [PATCH] [SYCL][Driver] Push linker input to the linker and not bundler when -foffload-static-lib is supplied MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes a problem that occurs when linker input like '-z relro' (and some libraries that are translated to options internally e.g. -lstdc++) are passed to the compiler alongside the -foffload-static-lib option. Previously linker arguments were being pushed to the OffloadBundler's ConstructJobMultipleOutputs call, which then got pushed into the linkers job construction as a string. As they're not considered strings but an Input (llvm::Opt) it will result in some garbage data as an argument to the linker. This will cause the linker job before the OffloadBundler job to fail as it can't find the garbage argument and then kills the rest of the compilation e.g: /usr/bin/ld: cannot find �H�: No such file or directory clang-10: error: clang-offload-bundler command failed with exit code 1 (use -v to see invocation) Signed-off-by: Andrew Gozillon andrew.gozillon@yahoo.com --- clang/lib/Driver/Driver.cpp | 4 ++-- clang/test/Driver/sycl-offload.c | 10 ++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp index 487aef881456d..ab551005b5b8a 100644 --- a/clang/lib/Driver/Driver.cpp +++ b/clang/lib/Driver/Driver.cpp @@ -4289,8 +4289,8 @@ void Driver::BuildActions(Compilation &C, DerivedArgList &Args, // Unbundler only handles objects. if (auto *IA = dyn_cast(LI)) { std::string FileName = IA->getInputArg().getAsString(Args); - if (IA->getType() == types::TY_Object && - !isObjectFile(FileName)) + if ((IA->getType() == types::TY_Object && !isObjectFile(FileName)) || + IA->getInputArg().getOption().hasFlag(options::LinkerInput)) // Pass the Input along to linker. TempLinkerInputs.push_back(LI); else diff --git a/clang/test/Driver/sycl-offload.c b/clang/test/Driver/sycl-offload.c index 702495667600a..7063027c58d6d 100644 --- a/clang/test/Driver/sycl-offload.c +++ b/clang/test/Driver/sycl-offload.c @@ -585,6 +585,16 @@ /// ########################################################################### +// RUN: touch %t.a +// RUN: %clang -fsycl -foffload-static-lib=%t.a -o output_name -lstdc++ -z relro -### %s 2>&1 \ +// RUN: | FileCheck %s -check-prefix=FOFFLOAD_STATIC_LIB_SRC4 +// FOFFLOAD_STATIC_LIB_SRC4: ld{{(.exe)?}}" "-r" "-o" {{.*}} "[[INPUT:.+\.a]]" +// FOFFLOAD_STATIC_LIB_SRC4: clang-offload-bundler{{.*}} "-type=oo" +// FOFFLOAD_STATIC_LIB_SRC4: llvm-link{{.*}} "@{{.*}}" +// FOFFLOAD_STATIC_LIB_SRC4: ld{{(.exe)?}}" {{.*}} "-o" "output_name" {{.*}} "-lstdc++" "-z" "relro" + +/// ########################################################################### + /// Check -Xsycl-target-backend triggers error when multiple triples are used. // RUN: %clang -### -fsycl -fsycl-targets=spir64_fpga-unknown-linux-sycldevice,spir_fpga-unknown-linux-sycldevice -Xsycl-target-backend -DFOO %s 2>&1 \ // RUN: | FileCheck -check-prefix=CHK-FSYCL-TARGET-AMBIGUOUS-ERROR %s