summaryrefslogtreecommitdiffstats
path: root/clang/lib/Driver/Tools.cpp
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2012-11-13 15:32:35 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2012-11-13 15:32:35 +0000
commit76db2907b0d01913823db7de4653eb9db84b3013 (patch)
tree3c931463b4236750c2287a12cbc3f0d150937315 /clang/lib/Driver/Tools.cpp
parent4fa2bd8c7ac0b283c233baa81c202a0bc5fca451 (diff)
downloadbcm5719-llvm-76db2907b0d01913823db7de4653eb9db84b3013.tar.gz
bcm5719-llvm-76db2907b0d01913823db7de4653eb9db84b3013.zip
This patch makes the behavior of clang consistent with the behavior of gcc 4.6 in cases where both -fPIC and -fPIE is used.
- Separately check if -fPIE was specified in the command line and define both __PIC__ and __PIE__ when -fPIE is used. We need to check this separately because -fPIE will infer -fPIC even if its not explicitly used. - Fixed existing tests. - Added new tests for cases where both -fPIC and -fPIE is used. Author: Tareq A. Siraj <tareq.a.siraj@intel.com> Fixes: PR13221 Review: http://llvm-reviews.chandlerc.com/D94 llvm-svn: 167846
Diffstat (limited to 'clang/lib/Driver/Tools.cpp')
-rw-r--r--clang/lib/Driver/Tools.cpp26
1 files changed, 19 insertions, 7 deletions
diff --git a/clang/lib/Driver/Tools.cpp b/clang/lib/Driver/Tools.cpp
index 6b113bc1c98..9ab35ff83c2 100644
--- a/clang/lib/Driver/Tools.cpp
+++ b/clang/lib/Driver/Tools.cpp
@@ -1779,18 +1779,26 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// would do to enable flag_pic.
Arg *LastPICArg = Args.getLastArg(options::OPT_fPIC, options::OPT_fno_PIC,
- options::OPT_fpic, options::OPT_fno_pic,
- options::OPT_fPIE, options::OPT_fno_PIE,
+ options::OPT_fpic, options::OPT_fno_pic);
+ // We need to check for PIE flags separately because they can override the
+ // PIC flags.
+ Arg *LastPIEArg = Args.getLastArg(options::OPT_fPIE, options::OPT_fno_PIE,
options::OPT_fpie, options::OPT_fno_pie);
bool PICDisabled = false;
bool PICEnabled = false;
bool PICForPIE = false;
- if (LastPICArg) {
- PICForPIE = (LastPICArg->getOption().matches(options::OPT_fPIE) ||
- LastPICArg->getOption().matches(options::OPT_fpie));
+ if (LastPIEArg) {
+ PICForPIE = (LastPIEArg->getOption().matches(options::OPT_fPIE) ||
+ LastPIEArg->getOption().matches(options::OPT_fpie));
+ }
+ if (LastPICArg || PICForPIE) {
+ // The last PIE enabled argument can infer that PIC is enabled.
PICEnabled = (PICForPIE ||
LastPICArg->getOption().matches(options::OPT_fPIC) ||
LastPICArg->getOption().matches(options::OPT_fpic));
+ // We need to have PICDisabled inside the if statement because on darwin
+ // PIC is enabled by default even if PIC arguments are not in the command
+ // line (in this case causes PICDisabled to be true).
PICDisabled = !PICEnabled;
}
// Note that these flags are trump-cards. Regardless of the order w.r.t. the
@@ -1825,9 +1833,13 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
// Infer the __PIC__ and __PIE__ values.
if (ModelStr == "pic" && PICForPIE) {
+ CmdArgs.push_back("-pic-level");
+ CmdArgs.push_back((LastPIEArg &&
+ LastPIEArg->getOption().matches(options::OPT_fPIE)) ?
+ "2" : "1");
CmdArgs.push_back("-pie-level");
- CmdArgs.push_back((LastPICArg &&
- LastPICArg->getOption().matches(options::OPT_fPIE)) ?
+ CmdArgs.push_back((LastPIEArg &&
+ LastPIEArg->getOption().matches(options::OPT_fPIE)) ?
"2" : "1");
} else if (ModelStr == "pic" || ModelStr == "dynamic-no-pic") {
CmdArgs.push_back("-pic-level");
OpenPOWER on IntegriCloud