[PATCH] D16901: [Clang driver, ARM] Do not add +long-calls in PIC mode

Oleg Ranevskyy via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 4 14:13:34 PST 2016


iid_iunknown created this revision.
iid_iunknown added reviewers: asl, rengolin, t.p.northover.
iid_iunknown added a subscriber: cfe-commits.
iid_iunknown set the repository for this revision to rL LLVM.
Herald added subscribers: rengolin, aemerson.

The driver resets the PIC / PIE flags to false if compiling for kernel/kext considering the OS and its version. From ParsePICArgs():
```
if (KernelOrKext && ((!Triple.isiOS() || Triple.isOSVersionLT(6)) && !Triple.isWatchOS()))
    PIC = PIE = false;
```
The condition for adding the +long-calls ARM feature in getARMTargetFeatures() is exactly the same.
Since +long-calls is not applicable for PIC, both conditions should be kept synchronized, otherwise one can get not working binaries.

This patch suggests to control the +long-calls option based on whether the code is PIC or not, which is a more natural way of doing this.

Repository:
  rL LLVM

http://reviews.llvm.org/D16901

Files:
  lib/Driver/Tools.cpp

Index: lib/Driver/Tools.cpp
===================================================================
--- lib/Driver/Tools.cpp
+++ lib/Driver/Tools.cpp
@@ -755,7 +755,7 @@
                                  const llvm::Triple &Triple,
                                  const ArgList &Args,
                                  std::vector<const char *> &Features,
-                                 bool ForAS) {
+                                 bool IsPIC, bool ForAS) {
   const Driver &D = TC.getDriver();
 
   bool KernelOrKext =
@@ -891,8 +891,7 @@
                                options::OPT_mno_long_calls)) {
     if (A->getOption().matches(options::OPT_mlong_calls))
       Features.push_back("+long-calls");
-  } else if (KernelOrKext && (!Triple.isiOS() || Triple.isOSVersionLT(6)) &&
-             !Triple.isWatchOS()) {
+  } else if (KernelOrKext && !IsPIC) {
       Features.push_back("+long-calls");
   }
 
@@ -2291,7 +2290,7 @@
 
 static void getTargetFeatures(const ToolChain &TC, const llvm::Triple &Triple,
                               const ArgList &Args, ArgStringList &CmdArgs,
-                              bool ForAS) {
+                              bool IsPIC, bool ForAS) {
   const Driver &D = TC.getDriver();
   std::vector<const char *> Features;
   switch (Triple.getArch()) {
@@ -2308,7 +2307,7 @@
   case llvm::Triple::armeb:
   case llvm::Triple::thumb:
   case llvm::Triple::thumbeb:
-    getARMTargetFeatures(TC, Triple, Args, Features, ForAS);
+    getARMTargetFeatures(TC, Triple, Args, Features, IsPIC, ForAS);
     break;
 
   case llvm::Triple::ppc:
@@ -4047,7 +4046,7 @@
   }
 
   // Add the target features
-  getTargetFeatures(getToolChain(), Triple, Args, CmdArgs, false);
+  getTargetFeatures(getToolChain(), Triple, Args, CmdArgs, PICLevel > 0, false);
 
   // Add target specific flags.
   switch (getToolChain().getArch()) {
@@ -6025,7 +6024,7 @@
   }
 
   // Add the target features
-  getTargetFeatures(getToolChain(), Triple, Args, CmdArgs, true);
+  getTargetFeatures(getToolChain(), Triple, Args, CmdArgs, /*IsPIC*/ false, true);
 
   // Ignore explicit -force_cpusubtype_ALL option.
   (void)Args.hasArg(options::OPT_force__cpusubtype__ALL);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D16901.46951.patch
Type: text/x-patch
Size: 2240 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160204/69d14adc/attachment-0001.bin>


More information about the cfe-commits mailing list