Skip to content

Commit 519a8e2

Browse files
authored
[Driver][SYCL] Allow undefined symbols when doing host deps generation (#8743)
When processing archives when performing offload, the driver will perform a host link which generates a file that is used to determine any offload dependencies. This additional link step is just for gathering the dependency information and shouldn't require the full ability to link. Under some circumstances, for example generating an early or final image archive for FPGA, the symbol resolution is not important. Add a general case of -z undefs during this internal link step and allow the final host link to determine any unresolved symbols at that time.
1 parent 130466e commit 519a8e2

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

clang/lib/Driver/ToolChains/Gnu.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,13 @@ void tools::gnutools::Linker::ConstructJob(Compilation &C, const JobAction &JA,
591591
ToolChain.addFastMathRuntimeIfAvailable(Args, CmdArgs);
592592
}
593593

594+
// Performing link for dependency file information, undefined symbols are OK.
595+
// True link time errors for symbols will be captured at host link.
596+
if (JA.getType() == types::TY_Host_Dependencies_Image) {
597+
CmdArgs.push_back("-z");
598+
CmdArgs.push_back("undefs");
599+
}
600+
594601
Args.AddAllArgs(CmdArgs, options::OPT_L);
595602
Args.AddAllArgs(CmdArgs, options::OPT_u);
596603

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@
105105
// RUN: | FileCheck %s --check-prefix=CHK-FPGA-LINK-WARN-AOCR
106106
// CHK-FPGA-LINK-WARN-AOCR: warning: FPGA archive '{{.*}}-aocr.a' does not contain matching emulation/hardware expectancy
107107

108+
/// Check deps behaviors with input fat archive and creating aocx archive
109+
// RUN: %clangxx -fsycl -fintelfpga -fsycl-link=image \
110+
// RUN: -target x86_64-unknown-linux-gnu %S/Inputs/SYCL/liblin64.a \
111+
// RUN: %s -### 2>&1 \
112+
// RUN: | FileCheck %s --check-prefix=CHK-FPGA-LINK-UNDEFS
113+
// CHK-FPGA-LINK-UNDEFS: ld{{.*}} "-z" "undefs"
114+
// CHK-FPGA-LINK-UNDEFS: clang-offload-deps{{.*}}
115+
108116
/// -fintelfpga -fsycl-link from source
109117
// RUN: touch %t.cpp
110118
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fno-sycl-instrument-device-code -fno-sycl-device-lib=all -fintelfpga -fsycl-link=early %t.cpp -ccc-print-phases 2>&1 \

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@
150150
// RUN: %clangxx -target x86_64-unknown-linux-gnu -fsycl -fsycl-targets=nvptx64-nvidia-cuda %t_lib.a -o output_name -lOpenCL -### %s 2>&1 \
151151
// RUN: | FileCheck %s -check-prefix=STATIC_LIB_SRC2 -DBUNDLE_TRIPLE=sycl-nvptx64-nvidia-cuda-sm_50 -DDEPS_TRIPLE=sycl-nvptx64-nvidia-cuda-sm_50
152152
// STATIC_LIB_SRC2: clang{{.*}} "-emit-obj" {{.*}} "-o" "[[HOSTOBJ:.+\.o]]"
153-
// STATIC_LIB_SRC2: ld{{(.exe)?}}" {{.*}} "-o" "[[HOSTEXE:.+\.out]]"
153+
// STATIC_LIB_SRC2: ld{{(.exe)?}}" {{.*}} "-o" "[[HOSTEXE:.+\.out]]" {{.*}}"-z" "undefs"
154154
// STATIC_LIB_SRC2: clang-offload-deps{{.*}} "-targets=[[DEPS_TRIPLE]]" "-outputs=[[OUTDEPS:.+\.bc]]" "[[HOSTEXE]]"
155155
// STATIC_LIB_SRC2_DEF: clang-offload-bundler{{.*}} "-type=aoo" "-targets=[[BUNDLE_TRIPLE]]" {{.*}} "-output=[[OUTLIB:.+\.txt]]"
156156
// STATIC_LIB_SRC2_NVPTX: clang-offload-bundler{{.*}} "-type=a" "-targets=[[BUNDLE_TRIPLE]]" {{.*}} "-output=[[OUTLIB:.+\.a]]"

0 commit comments

Comments
 (0)