diff --git a/clang/lib/Driver/ToolChains/Gnu.cpp b/clang/lib/Driver/ToolChains/Gnu.cpp index 9ca674511dabab..d423a71b5cca62 100644 --- a/clang/lib/Driver/ToolChains/Gnu.cpp +++ b/clang/lib/Driver/ToolChains/Gnu.cpp @@ -341,12 +341,17 @@ void tools::gnutools::StaticLibTool::ConstructJob( // Silence warnings when linking C code with a C++ '-stdlib' argument. Args.ClaimAllArgs(options::OPT_stdlib_EQ); - // GNU ar tool command "ar ". + // ar tool command "llvm-ar ". ArgStringList CmdArgs; // Create and insert file members with a deterministic index. CmdArgs.push_back("rcsD"); CmdArgs.push_back(Output.getFilename()); - AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA); + + for (const auto &II : Inputs) { + if (II.isFilename()) { + CmdArgs.push_back(II.getFilename()); + } + } // Delete old output archive file if it already exists before generating a new // archive file. diff --git a/clang/test/Driver/hip-link-static-library.hip b/clang/test/Driver/hip-link-static-library.hip index 55c5a5acc5ca69..e670980fa486d1 100644 --- a/clang/test/Driver/hip-link-static-library.hip +++ b/clang/test/Driver/hip-link-static-library.hip @@ -25,3 +25,14 @@ // NORDC-NOT: offload bundler // NORDC: # "x86_64-unknown-linux-gnu" - "GNU::StaticLibTool", inputs: ["{{.*o}}"], output: "a.out" + +// RUN: %clang --hip-link -### -target x86_64-linux-gnu \ +// RUN: --emit-static-lib -lgcc \ +// RUN: -Wl,--enable-new-dtags -Wl,--rpath=/opt \ +// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 -fgpu-rdc %t.o\ +// RUN: 2>&1 | FileCheck -check-prefix=NOFLAG %s + +// NOFLAG-NOT: .*lgcc +// NOFLAG-NOT: .*enable-new-dtags +// NOFLAG-NOT: .*rpath=/opt +// NOFLAG: "{{.*}}llvm-ar{{.*}}" "rcsD" "{{.*}}.out" "{{.*o}}" "{{.*o}}"