]> granicus.if.org Git - clang/commitdiff
New clang option -fno-plt which avoids the PLT and lazy binding while making external...
authorSriraman Tallam <tmsriram@google.com>
Tue, 7 Nov 2017 19:37:51 +0000 (19:37 +0000)
committerSriraman Tallam <tmsriram@google.com>
Tue, 7 Nov 2017 19:37:51 +0000 (19:37 +0000)
Differential Revision: https://reviews.llvm.org/D39079

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@317605 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Driver/Options.td
include/clang/Frontend/CodeGenOptions.def
lib/CodeGen/CGCall.cpp
lib/Driver/ToolChains/Clang.cpp
lib/Frontend/CompilerInvocation.cpp
test/CodeGen/noplt.c [new file with mode: 0644]

index e3476c721a7ecd75a2c5e2efdae80112391f853e..597e03b563dd80a1e3a86e8b81d06f21addf55c6 100644 (file)
@@ -1384,6 +1384,10 @@ def fpic : Flag<["-"], "fpic">, Group<f_Group>;
 def fno_pic : Flag<["-"], "fno-pic">, Group<f_Group>;
 def fpie : Flag<["-"], "fpie">, Group<f_Group>;
 def fno_pie : Flag<["-"], "fno-pie">, Group<f_Group>;
+def fplt : Flag<["-"], "fplt">, Group<f_Group>, Flags<[CC1Option]>,
+  HelpText<"Use the PLT to make function calls">;
+def fno_plt : Flag<["-"], "fno-plt">, Group<f_Group>, Flags<[CC1Option]>,
+  HelpText<"Do not use the PLT to make function calls">;
 def fropi : Flag<["-"], "fropi">, Group<f_Group>;
 def fno_ropi : Flag<["-"], "fno-ropi">, Group<f_Group>;
 def frwpi : Flag<["-"], "frwpi">, Group<f_Group>;
index 8f2aae2f140c580abff7a49dfb469bdce65a3f5e..b4c68a49bb662182b2fe0ca288a67a3bbb8a3cc6 100644 (file)
@@ -297,6 +297,8 @@ CODEGENOPT(PreserveVec3Type, 1, 0)
 /// Whether to emit .debug_gnu_pubnames section instead of .debug_pubnames.
 CODEGENOPT(GnuPubnames, 1, 0)
 
+CODEGENOPT(NoPLT, 1, 0)
+
 #undef CODEGENOPT
 #undef ENUM_CODEGENOPT
 #undef VALUE_CODEGENOPT
index 971455a8737c3c45dfbda6a8aa02947bc430967a..cefd73be276358606d00f8f5ed4c2598e7e3b28c 100644 (file)
@@ -1855,6 +1855,16 @@ void CodeGenModule::ConstructAttributeList(
       !(TargetDecl && TargetDecl->hasAttr<NoSplitStackAttr>()))
     FuncAttrs.addAttribute("split-stack");
 
+  // Add NonLazyBind attribute to function declarations when -fno-plt
+  // is used.
+  if (TargetDecl && CodeGenOpts.NoPLT) {
+    if (auto *Fn = dyn_cast<FunctionDecl>(TargetDecl)) {
+      if (!Fn->isDefined() && !AttrOnCallSite) {
+        FuncAttrs.addAttribute(llvm::Attribute::NonLazyBind);
+      }
+    }
+  }
+
   if (!AttrOnCallSite) {
     bool DisableTailCalls =
         CodeGenOpts.DisableTailCalls ||
index 6ba5d048a480102ffb9717c8d42cb0f049cd8592..758ece19e1edfeeb812d74908162b3d5e77dd256 100644 (file)
@@ -3423,6 +3423,10 @@ void Clang::ConstructJob(Compilation &C, const JobAction &JA,
     CmdArgs.push_back("-mpie-copy-relocations");
   }
 
+  if (Args.hasFlag(options::OPT_fno_plt, options::OPT_fplt, false)) {
+    CmdArgs.push_back("-fno-plt");
+  }
+
   // -fhosted is default.
   // TODO: Audit uses of KernelOrKext and see where it'd be more appropriate to
   // use Freestanding.
index 692b20bd3adbb7dfced656d538be5537c6ba9d92..ca1c65e95a40dbaf214725a88e49c07684e41607 100644 (file)
@@ -653,6 +653,7 @@ static bool ParseCodeGenArgs(CodeGenOptions &Opts, ArgList &Args, InputKind IK,
       Args.hasArg(OPT_mincremental_linker_compatible);
   Opts.PIECopyRelocations =
       Args.hasArg(OPT_mpie_copy_relocations);
+  Opts.NoPLT = Args.hasArg(OPT_fno_plt);
   Opts.OmitLeafFramePointer = Args.hasArg(OPT_momit_leaf_frame_pointer);
   Opts.SaveTempLabels = Args.hasArg(OPT_msave_temp_labels);
   Opts.NoDwarfDirectoryAsm = Args.hasArg(OPT_fno_dwarf_directory_asm);
diff --git a/test/CodeGen/noplt.c b/test/CodeGen/noplt.c
new file mode 100644 (file)
index 0000000..ce054e2
--- /dev/null
@@ -0,0 +1,9 @@
+// RUN: %clang_cc1 -emit-llvm -fno-plt %s -o - | FileCheck %s -check-prefix=CHECK-NOPLT
+
+// CHECK-NOPLT: Function Attrs: nonlazybind
+// CHECK-NOPLT-NEXT: declare i32 @foo
+int foo();
+
+int bar() {
+  return foo();
+}