From d133dc226f58d09d12b10c14b4241cc50f3d56f1 Mon Sep 17 00:00:00 2001 From: Saleem Abdulrasool Date: Mon, 26 Dec 2016 03:35:24 +0000 Subject: 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 --- clang/lib/Driver/Tools.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'clang/lib/Driver/Tools.cpp') 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()) { -- cgit v1.2.3