Skip to content

Commit 82b93be

Browse files
authored
[Driver][SYCL] Consider .lo files as static archives (#1500)
In certain build situations, *.lo files are created that are static archives. Adjust the detection of static archives to include these, and also perform a more strict check against known file extensions for archives. Signed-off-by: Michael D Toguchi <[email protected]>
1 parent 91b597b commit 82b93be

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

clang/lib/Driver/Driver.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,11 @@
4141
#include "ToolChains/PPCLinux.h"
4242
#include "ToolChains/PS4CPU.h"
4343
#include "ToolChains/RISCVToolchain.h"
44+
#include "ToolChains/SYCL.h"
4445
#include "ToolChains/Solaris.h"
4546
#include "ToolChains/TCE.h"
4647
#include "ToolChains/WebAssembly.h"
4748
#include "ToolChains/XCore.h"
48-
#include "ToolChains/SYCL.h"
4949
#include "clang/Basic/Version.h"
5050
#include "clang/Config/config.h"
5151
#include "clang/Driver/Action.h"
@@ -62,6 +62,7 @@
6262
#include "llvm/ADT/StringExtras.h"
6363
#include "llvm/ADT/StringSet.h"
6464
#include "llvm/ADT/StringSwitch.h"
65+
#include "llvm/BinaryFormat/Magic.h"
6566
#include "llvm/Config/llvm-config.h"
6667
#include "llvm/Option/Arg.h"
6768
#include "llvm/Option/ArgList.h"
@@ -6594,8 +6595,10 @@ bool clang::driver::isStaticArchiveFile(const StringRef &FileName) {
65946595
// Any file with no extension should not be considered an Archive.
65956596
return false;
65966597
StringRef Ext(llvm::sys::path::extension(FileName).drop_front());
6597-
// Only .lib and .a files are to be considered.
6598-
return (Ext == "lib" || Ext == "a");
6598+
llvm::file_magic Magic;
6599+
llvm::identify_magic(FileName, Magic);
6600+
// Only .lib and archive files are to be considered.
6601+
return (Ext == "lib" || Magic == llvm::file_magic::archive);
65996602
}
66006603

66016604
bool clang::driver::willEmitRemarks(const ArgList &Args) {

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

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,21 @@
1010
// Build a fat static lib that will be used for all tests
1111
// RUN: echo "void foo(void) {}" > %t1.cpp
1212
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl %t1.cpp -c -o %t1_bundle.o
13-
// RUN: llvm-ar crv %t.a %t1_bundle.o
13+
// RUN: llvm-ar cr %t.a %t1_bundle.o
14+
// RUN: llvm-ar cr %t.lo %t1_bundle.o
15+
// RUN: llvm-ar cr %t_2.a %t1_bundle.o
1416
//
1517
// RUN: touch %t.a
18+
// RUN: touch %t.lo
1619
// RUN: touch %t.o
1720
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -L/dummy/dir %t.a -### %t.o 2>&1 \
18-
// RUN: | FileCheck %s -check-prefix=STATIC_LIB
19-
// STATIC_LIB: ld{{(.exe)?}}" "-r" "-o" {{.*}} "[[INPUT:.+\.o]]" "-L/dummy/dir"{{.*}} "[[INPUT:.+\.a]]"
20-
// STATIC_LIB: clang-offload-bundler{{.*}} "-type=oo"
21-
// STATIC_LIB: llvm-link{{.*}} "@{{.*}}"
21+
// RUN: | FileCheck %s -check-prefix=STATIC_LIB -DINPUTA=%t.a -DINPUTO=%t.o
22+
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -L/dummy/dir %t.lo -### %t.o 2>&1 \
23+
// RUN: | FileCheck %s -check-prefix=STATIC_LIB -DINPUTA=%t.lo -DINPUTO=%t.o
24+
// STATIC_LIB: ld{{(.exe)?}}" "-r" "-o" "[[INPUTLD:[^ ]+\.o]]" {{.*}} "-L/dummy/dir"{{.*}} "[[INPUTO]]" "[[INPUTA]]"
25+
// STATIC_LIB: clang-offload-bundler{{.*}} "-type=oo" {{.*}} "-inputs=[[INPUTLD]]" "-outputs=[[LISTFILE:.+\.txt]]"
26+
// STATIC_LIB: llvm-link{{.*}} "@[[LISTFILE]]"
27+
// STATIC_LIB: ld{{.*}} "[[INPUTA]]" "[[INPUTO]]"
2228

2329
/// ###########################################################################
2430

@@ -94,8 +100,10 @@
94100

95101
/// test behaviors of static lib with no source/object
96102
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -L/dummy/dir %t.a -### 2>&1 \
97-
// RUN: | FileCheck %s -check-prefixes=STATIC_LIB_NOSRC
98-
// STATIC_LIB_NOSRC: clang-offload-bundler{{.*}} "-type=ao" "-targets=host-x86_64-unknown-linux-gnu" "-inputs=[[INPUTLIB:.+\.a]]" "-check-section"
103+
// RUN: | FileCheck %s -check-prefix=STATIC_LIB_NOSRC -DINPUTLIB=%t.a
104+
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -L/dummy/dir %t.lo -### 2>&1 \
105+
// RUN: | FileCheck %s -check-prefix=STATIC_LIB_NOSRC -DINPUTLIB=%t.lo
106+
// STATIC_LIB_NOSRC: clang-offload-bundler{{.*}} "-type=ao" "-targets=host-x86_64-unknown-linux-gnu" "-inputs=[[INPUTLIB]]" "-check-section"
99107
// STATIC_LIB_NOSRC: ld{{.*}} "-r" "-o" "[[PARTIALOBJ:.+\.o]]" "{{.*}}crt1.o" {{.*}} "-L/dummy/dir" {{.*}} "[[INPUTLIB]]"
100108
// STATIC_LIB_NOSRC: clang-offload-bundler{{.*}} "-type=oo" "-targets=sycl-spir64-unknown-unknown-sycldevice" "-inputs=[[PARTIALOBJ]]" "-outputs=[[DEVICELIST:.+\.txt]]" "-unbundle"
101109
// STATIC_LIB_NOSRC: llvm-link{{.*}} "@[[DEVICELIST]]" "-o" "[[BCFILE:.+\.bc]]"

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
// REQUIRES: clang-driver
55
// REQUIRES: x86-registered-target
66

7+
/// test behaviors of passing a fat static lib
8+
// Build a fat static lib that will be used for all tests
9+
// RUN: echo "void foo(void) {}" > %t1.cpp
10+
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl %t1.cpp -c -o %t1_bundle.o
11+
// RUN: llvm-ar cr %t.a %t1_bundle.o
12+
// RUN: llvm-ar cr %t_2.a %t1_bundle.o
13+
714
/// ###########################################################################
815

916
/// test behaviors of -foffload-static-lib=<lib>

0 commit comments

Comments
 (0)