Skip to content

Commit 10eb3bf

Browse files
committed
Skip -fPIE for AMDGPU and HIP toolchain
AMDGPU toolchain does not support -fPIE, therefore skip it if specified by driver. Differential Revision: https://reviews.llvm.org/D88425
1 parent bbb5dc4 commit 10eb3bf

File tree

4 files changed

+55
-3
lines changed

4 files changed

+55
-3
lines changed

clang/lib/Driver/ToolChains/AMDGPU.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,8 +427,11 @@ AMDGPUToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
427427

428428
if (!DAL)
429429
DAL = new DerivedArgList(Args.getBaseArgs());
430-
for (auto *A : Args)
431-
DAL->append(A);
430+
431+
for (Arg *A : Args) {
432+
if (!shouldSkipArgument(A))
433+
DAL->append(A);
434+
}
432435

433436
if (!Args.getLastArgValue(options::OPT_x).equals("cl"))
434437
return DAL;
@@ -644,3 +647,10 @@ void RocmInstallationDetector::addCommonBitcodeLibCC1Args(
644647
CC1Args.push_back(LinkBitcodeFlag);
645648
CC1Args.push_back(DriverArgs.MakeArgString(LibDeviceFile));
646649
}
650+
651+
bool AMDGPUToolChain::shouldSkipArgument(const llvm::opt::Arg *A) const {
652+
Option O = A->getOption();
653+
if (O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie))
654+
return true;
655+
return false;
656+
}

clang/lib/Driver/ToolChains/AMDGPU.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
9090
/// Needed for translating LTO options.
9191
const char *getDefaultLinker() const override { return "ld.lld"; }
9292

93+
/// Should skip argument.
94+
bool shouldSkipArgument(const llvm::opt::Arg *Arg) const;
95+
9396
protected:
9497
/// Translate -mcpu option containing target ID to cc1 options.
9598
/// Returns the GPU name.

clang/lib/Driver/ToolChains/HIP.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,8 @@ HIPToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
341341
const OptTable &Opts = getDriver().getOpts();
342342

343343
for (Arg *A : Args) {
344-
DAL->append(A);
344+
if (!shouldSkipArgument(A))
345+
DAL->append(A);
345346
}
346347

347348
if (!BoundArch.empty()) {

clang/test/Driver/hip-fpie-option.hip

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// REQUIRES: clang-driver, amdgpu-registered-target
2+
3+
// -fPIC and -fPIE only affects host relocation model.
4+
// device compilation always uses PIC.
5+
6+
// RUN: %clang -### -target x86_64-unknown-linux-gnu \
7+
// RUN: --offload-arch=gfx906 %s -nogpulib -nogpuinc \
8+
// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-STATIC %s
9+
10+
// RUN: %clang -### -target x86_64-unknown-linux-gnu \
11+
// RUN: -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \
12+
// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-STATIC %s
13+
14+
// RUN: %clang -### -target x86_64-unknown-linux-gnu \
15+
// RUN: --offload-arch=gfx906 %s -nogpulib -nogpuinc \
16+
// RUN: -fPIC \
17+
// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-PIC %s
18+
19+
// RUN: %clang -### -target x86_64-unknown-linux-gnu \
20+
// RUN: -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \
21+
// RUN: -fPIC \
22+
// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-PIC %s
23+
24+
// RUN: %clang -### -target x86_64-unknown-linux-gnu \
25+
// RUN: --offload-arch=gfx906 %s -nogpulib -nogpuinc \
26+
// RUN: -fPIE \
27+
// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE %s
28+
29+
// RUN: %clang -### -target x86_64-unknown-linux-gnu \
30+
// RUN: -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \
31+
// RUN: -fPIE \
32+
// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE %s
33+
34+
// DEV-DAG: {{".*clang.*".* "-triple" "amdgcn-amd-amdhsa".* "-mrelocation-model" "pic" "-pic-level" "[1|2]" "-mframe-pointer=all"}}
35+
// HOST-STATIC-DAG: {{".*clang.*".* "-triple" "x86_64-unknown-linux-gnu".* "-mrelocation-model" "static"}}
36+
// HOST-PIC-DAG: {{".*clang.*".* "-triple" "x86_64-unknown-linux-gnu".* "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=all"}}
37+
// HOST-PIE-DAG: {{".*clang.*".* "-triple" "x86_64-unknown-linux-gnu".* "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie"}}
38+
// DEV-NOT: {{".*clang.*".* "-triple" "amdgcn-amd-amdhsa".* "-pic-is-pie"}}

0 commit comments

Comments
 (0)