[clang] 10eb3bf - Skip -fPIE for AMDGPU and HIP toolchain
Yaxun Liu via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 28 19:25:15 PDT 2020
Author: Yaxun (Sam) Liu
Date: 2020-09-28T22:03:18-04:00
New Revision: 10eb3bf2d430825195bf092d3a75c4745d463826
URL: https://github.com/llvm/llvm-project/commit/10eb3bf2d430825195bf092d3a75c4745d463826
DIFF: https://github.com/llvm/llvm-project/commit/10eb3bf2d430825195bf092d3a75c4745d463826.diff
LOG: 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
Added:
clang/test/Driver/hip-fpie-option.hip
Modified:
clang/lib/Driver/ToolChains/AMDGPU.cpp
clang/lib/Driver/ToolChains/AMDGPU.h
clang/lib/Driver/ToolChains/HIP.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.cpp b/clang/lib/Driver/ToolChains/AMDGPU.cpp
index 3616310c37bf..61254e3eeaef 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.cpp
+++ b/clang/lib/Driver/ToolChains/AMDGPU.cpp
@@ -427,8 +427,11 @@ AMDGPUToolChain::TranslateArgs(const DerivedArgList &Args, StringRef BoundArch,
if (!DAL)
DAL = new DerivedArgList(Args.getBaseArgs());
- for (auto *A : Args)
- DAL->append(A);
+
+ for (Arg *A : Args) {
+ if (!shouldSkipArgument(A))
+ DAL->append(A);
+ }
if (!Args.getLastArgValue(options::OPT_x).equals("cl"))
return DAL;
@@ -644,3 +647,10 @@ void RocmInstallationDetector::addCommonBitcodeLibCC1Args(
CC1Args.push_back(LinkBitcodeFlag);
CC1Args.push_back(DriverArgs.MakeArgString(LibDeviceFile));
}
+
+bool AMDGPUToolChain::shouldSkipArgument(const llvm::opt::Arg *A) const {
+ Option O = A->getOption();
+ if (O.matches(options::OPT_fPIE) || O.matches(options::OPT_fpie))
+ return true;
+ return false;
+}
diff --git a/clang/lib/Driver/ToolChains/AMDGPU.h b/clang/lib/Driver/ToolChains/AMDGPU.h
index 751116f2471f..0a91499c0cbf 100644
--- a/clang/lib/Driver/ToolChains/AMDGPU.h
+++ b/clang/lib/Driver/ToolChains/AMDGPU.h
@@ -90,6 +90,9 @@ class LLVM_LIBRARY_VISIBILITY AMDGPUToolChain : public Generic_ELF {
/// Needed for translating LTO options.
const char *getDefaultLinker() const override { return "ld.lld"; }
+ /// Should skip argument.
+ bool shouldSkipArgument(const llvm::opt::Arg *Arg) const;
+
protected:
/// Translate -mcpu option containing target ID to cc1 options.
/// Returns the GPU name.
diff --git a/clang/lib/Driver/ToolChains/HIP.cpp b/clang/lib/Driver/ToolChains/HIP.cpp
index 43e557c98050..78f53204bd8c 100644
--- a/clang/lib/Driver/ToolChains/HIP.cpp
+++ b/clang/lib/Driver/ToolChains/HIP.cpp
@@ -341,7 +341,8 @@ HIPToolChain::TranslateArgs(const llvm::opt::DerivedArgList &Args,
const OptTable &Opts = getDriver().getOpts();
for (Arg *A : Args) {
- DAL->append(A);
+ if (!shouldSkipArgument(A))
+ DAL->append(A);
}
if (!BoundArch.empty()) {
diff --git a/clang/test/Driver/hip-fpie-option.hip b/clang/test/Driver/hip-fpie-option.hip
new file mode 100644
index 000000000000..2b433cd5a2c2
--- /dev/null
+++ b/clang/test/Driver/hip-fpie-option.hip
@@ -0,0 +1,38 @@
+// REQUIRES: clang-driver, amdgpu-registered-target
+
+// -fPIC and -fPIE only affects host relocation model.
+// device compilation always uses PIC.
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu \
+// RUN: --offload-arch=gfx906 %s -nogpulib -nogpuinc \
+// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-STATIC %s
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu \
+// RUN: -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \
+// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-STATIC %s
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu \
+// RUN: --offload-arch=gfx906 %s -nogpulib -nogpuinc \
+// RUN: -fPIC \
+// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-PIC %s
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu \
+// RUN: -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \
+// RUN: -fPIC \
+// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-PIC %s
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu \
+// RUN: --offload-arch=gfx906 %s -nogpulib -nogpuinc \
+// RUN: -fPIE \
+// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE %s
+
+// RUN: %clang -### -target x86_64-unknown-linux-gnu \
+// RUN: -fgpu-rdc --offload-arch=gfx906 %s -nogpulib -nogpuinc \
+// RUN: -fPIE \
+// RUN: 2>&1 | FileCheck -check-prefixes=DEV,HOST-PIE %s
+
+// DEV-DAG: {{".*clang.*".* "-triple" "amdgcn-amd-amdhsa".* "-mrelocation-model" "pic" "-pic-level" "[1|2]" "-mframe-pointer=all"}}
+// HOST-STATIC-DAG: {{".*clang.*".* "-triple" "x86_64-unknown-linux-gnu".* "-mrelocation-model" "static"}}
+// HOST-PIC-DAG: {{".*clang.*".* "-triple" "x86_64-unknown-linux-gnu".* "-mrelocation-model" "pic" "-pic-level" "2" "-mframe-pointer=all"}}
+// HOST-PIE-DAG: {{".*clang.*".* "-triple" "x86_64-unknown-linux-gnu".* "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie"}}
+// DEV-NOT: {{".*clang.*".* "-triple" "amdgcn-amd-amdhsa".* "-pic-is-pie"}}
More information about the cfe-commits
mailing list