summaryrefslogtreecommitdiffstats
path: root/clang/lib
diff options
context:
space:
mode:
authorSaleem Abdulrasool <compnerd@compnerd.org>2016-12-26 03:35:24 +0000
committerSaleem Abdulrasool <compnerd@compnerd.org>2016-12-26 03:35:24 +0000
commitd133dc226f58d09d12b10c14b4241cc50f3d56f1 (patch)
tree312bf052aaa77fa0c373cf915e8ea206f0fe1687 /clang/lib
parentf56d985f77d7eba92898a31e3ff11c1e383ea338 (diff)
downloadbcm5719-llvm-d133dc226f58d09d12b10c14b4241cc50f3d56f1.tar.gz
bcm5719-llvm-d133dc226f58d09d12b10c14b4241cc50f3d56f1.zip
Driver: warn on -fPIC/-fpic/-fPIE/-fpie on Windows
Use of these flags would result in the use of ELF-style PIE/PIC code which is incorrect on Windows. Windows is inherently PIC by means of the DLL slide that occurs at load. This also mirrors the behaviour on GCC for MinGW. Currently, the Windows x86_64 forces the relocation model to PIC (Level 2). This is unchanged for now, though we should remove any assumptions on that and change it to a static relocation model. llvm-svn: 290533
Diffstat (limited to 'clang/lib')
-rw-r--r--clang/lib/Driver/Tools.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp
index 5bab0ef4a8e..8ed12d72b40 100644
--- a/clang/lib/Driver/Tools.cpp
+++ b/clang/lib/Driver/Tools.cpp
@@ -3859,6 +3859,17 @@ ParsePICArgs(const ToolChain &ToolChain, const ArgList &Args) {
options::OPT_fpic, options::OPT_fno_pic,
options::OPT_fPIE, options::OPT_fno_PIE,
options::OPT_fpie, options::OPT_fno_pie);
+ if (Triple.isOSWindows() && LastPICArg &&
+ LastPICArg ==
+ Args.getLastArg(options::OPT_fPIC, options::OPT_fpic,
+ options::OPT_fPIE, options::OPT_fpie)) {
+ ToolChain.getDriver().Diag(diag::err_drv_unsupported_opt_for_target)
+ << LastPICArg->getSpelling() << Triple.str();
+ if (Triple.getArch() == llvm::Triple::x86_64)
+ return std::make_tuple(llvm::Reloc::PIC_, 2U, false);
+ return std::make_tuple(llvm::Reloc::Static, 0U, false);
+ }
+
// Check whether the tool chain trumps the PIC-ness decision. If the PIC-ness
// is forced, then neither PIC nor PIE flags will have no effect.
if (!ToolChain.isPICDefaultForced()) {
OpenPOWER on IntegriCloud