Skip to content

Commit 1f34c92

Browse files
aaronenyeshimemfrob
authored andcommitted
[HIP] Ignore invalid ar linker options
Instead of accepting the same arguments as regular linker, the static linker will only accept input files. Reviewed By: yaxunl Differential Revision: https://reviews.llvm.org/D85442
1 parent 39e80a1 commit 1f34c92

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,17 @@ void tools::gnutools::StaticLibTool::ConstructJob(
341341
// Silence warnings when linking C code with a C++ '-stdlib' argument.
342342
Args.ClaimAllArgs(options::OPT_stdlib_EQ);
343343

344-
// GNU ar tool command "ar <options> <output_file> <input_files>".
344+
// ar tool command "llvm-ar <options> <output_file> <input_files>".
345345
ArgStringList CmdArgs;
346346
// Create and insert file members with a deterministic index.
347347
CmdArgs.push_back("rcsD");
348348
CmdArgs.push_back(Output.getFilename());
349-
AddLinkerInputs(getToolChain(), Inputs, Args, CmdArgs, JA);
349+
350+
for (const auto &II : Inputs) {
351+
if (II.isFilename()) {
352+
CmdArgs.push_back(II.getFilename());
353+
}
354+
}
350355

351356
// Delete old output archive file if it already exists before generating a new
352357
// archive file.

clang/test/Driver/hip-link-static-library.hip

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,14 @@
2525

2626
// NORDC-NOT: offload bundler
2727
// NORDC: # "x86_64-unknown-linux-gnu" - "GNU::StaticLibTool", inputs: ["{{.*o}}"], output: "a.out"
28+
29+
// RUN: %clang --hip-link -### -target x86_64-linux-gnu \
30+
// RUN: --emit-static-lib -lgcc \
31+
// RUN: -Wl,--enable-new-dtags -Wl,--rpath=/opt \
32+
// RUN: --cuda-gpu-arch=gfx803 --cuda-gpu-arch=gfx900 -fgpu-rdc %t.o\
33+
// RUN: 2>&1 | FileCheck -check-prefix=NOFLAG %s
34+
35+
// NOFLAG-NOT: .*lgcc
36+
// NOFLAG-NOT: .*enable-new-dtags
37+
// NOFLAG-NOT: .*rpath=/opt
38+
// NOFLAG: "{{.*}}llvm-ar{{.*}}" "rcsD" "{{.*}}.out" "{{.*o}}" "{{.*o}}"

0 commit comments

Comments
 (0)