Skip to content

Commit 1754934

Browse files
authored
[Driver][SYCL] Imply -fPIC compilation for wrapped object when using -shared (#3707)
Imply -fPIC when generating the wrapped object when using -shared. This reduces confusion if -fPIC is not used when performing the 'link' step using -fsycl as the additional object is created by us, and not by a previous compilation done by the user with -fPIC.
1 parent 6bea703 commit 1754934

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

clang/lib/Driver/ToolChains/Clang.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8294,7 +8294,7 @@ void OffloadWrapper::ConstructJob(Compilation &C, const JobAction &JA,
82948294
bool IsPIE;
82958295
std::tie(RelocationModel, PICLevel, IsPIE) =
82968296
ParsePICArgs(getToolChain(), TCArgs);
8297-
if (PICLevel > 0) {
8297+
if (PICLevel > 0 || TCArgs.hasArg(options::OPT_shared)) {
82988298
LlcArgs.push_back("-relocation-model=pic");
82998299
}
83008300
if (IsPIE) {

clang/test/Driver/sycl-offload.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,10 @@
3131
// CHECK_COVERAGE_MAPPING: clang{{.*}} "-cc1" "-triple" "spir64-unknown-unknown-sycldevice"{{.*}} "-fsycl-is-device"{{.*}} "-fprofile-instrument=clang"
3232
// CHECK_COVERAGE_MAPPING-NOT: "-fcoverage-mapping"
3333
// CHECK_COVERAGE_MAPPING: clang{{.*}} "-cc1" "-triple" "x86_64-unknown-linux-gnu"{{.*}} "-fsycl-is-host"{{.*}} "-fprofile-instrument=clang"{{.*}} "-fcoverage-mapping"{{.*}}
34+
35+
/// check for PIC for device wrap compilation when using -shared or -fPIC
36+
// RUN: %clangxx -### -fsycl -target x86_64-unknown-linux-gnu -shared %s 2>&1 \
37+
// RUN: | FileCheck -check-prefix=CHECK_SHARED %s
38+
// RUN: %clangxx -### -fsycl -target x86_64-unknown-linux-gnu -fPIC %s 2>&1 \
39+
// RUN: | FileCheck -check-prefix=CHECK_SHARED %s
40+
// CHECK_SHARED: llc{{.*}} "-relocation-model=pic"

0 commit comments

Comments
 (0)