Skip to content

Commit 9d348eb

Browse files
author
Artem Gindinson
authored
[SYCL][Driver] Emit a warning when appending to an existing archive (#1250)
When llvm-ar is invoked by the driver and the designated output archive already exists, the behavior is to simply append the new objects. As such, this GCC-consistent behavior can be quite useful: e.g. in our SYCL FPGA flow, the user could look to store a host object file in an archive, then produce an AOT-compiled device object and append it to the archive via -fsycl-link. However, if the archive already contains an AOT-compiled device object, appending a new device object would imminently crash the further compilation stages. Therefore, a warning is now provided in case the existing device object-containing archive under the same name was accindentally left over by the developer. Signed-off-by: Artem Gindinson <[email protected]>
1 parent 38b321a commit 9d348eb

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

clang/include/clang/Basic/DiagnosticDriverKinds.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,8 @@ def warn_drv_treating_input_as_cxx : Warning<
324324
InGroup<Deprecated>;
325325
def warn_drv_pch_not_first_include : Warning<
326326
"precompiled header '%0' was ignored because '%1' is not first '-include'">;
327+
def warn_drv_existing_archive_append: Warning<
328+
"appending to an existing archive '%0'">, InGroup<DiagGroup<"archive-append">>;
327329
def warn_missing_sysroot : Warning<"no such sysroot directory: '%0'">,
328330
InGroup<DiagGroup<"missing-sysroot">>;
329331
def warn_incompatible_sysroot : Warning<"using sysroot for '%0' but targeting '%1'">,

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,12 @@ void tools::gnutools::Linker::constructLLVMARCommand(
348348
const InputInfoList &Input, const ArgList &Args) const {
349349
ArgStringList CmdArgs;
350350
CmdArgs.push_back("cr");
351-
CmdArgs.push_back(Output.getFilename());
351+
const char *OutputFilename = Output.getFilename();
352+
if (llvm::sys::fs::exists(OutputFilename)) {
353+
C.getDriver().Diag(clang::diag::warn_drv_existing_archive_append)
354+
<< OutputFilename;
355+
}
356+
CmdArgs.push_back(OutputFilename);
352357
for (const auto &II : Input) {
353358
if (II.getType() == types::TY_Tempfilelist) {
354359
// Take the list file and pass it in with '@'.

clang/test/Driver/sycl-offload-intelfpga.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,14 @@
7878
// CHK-FPGA-LINK-LIB: clang-offload-bundler{{.*}} "-type=aoo" "-targets=host-x86_64-unknown-linux-gnu" "-inputs=[[INPUT]]" "-outputs=[[OUTPUT1:.+\.txt]]" "-unbundle"
7979
// CHK-FPGA-LINK-LIB: llvm-ar{{.*}} "cr" {{.*}} "@[[OUTPUT1]]"
8080

81+
/// Check the warning's emission for -fsycl-link's appending behavior
82+
// RUN: touch dummy.a
83+
// RUN: %clangxx -fsycl -fintelfpga -fsycl-link=image %s -o dummy.a -### 2>&1 \
84+
// RUN: | FileCheck %s --check-prefix=CHK-FPGA-LINK-WARN
85+
// RUN: %clangxx -fsycl -fintelfpga -fsycl-link=early %s -o dummy.a -### 2>&1 \
86+
// RUN: | FileCheck %s --check-prefix=CHK-FPGA-LINK-WARN
87+
// CHK-FPGA-LINK-WARN: warning: appending to an existing archive 'dummy.a'
88+
8189
/// -fintelfpga with AOCR library and additional object
8290
// RUN: touch %t2.o
8391
// RUN: %clangxx -### -target x86_64-unknown-linux-gnu -fsycl -fintelfpga %t.a %t2.o 2>&1 \

0 commit comments

Comments
 (0)