[PATCH] D19671: Add "PIE Level" metadata to module flags

Sriraman Tallam via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 28 10:18:38 PDT 2016


tmsriram created this revision.
tmsriram added reviewers: rnk, davidxl.
tmsriram added a subscriber: llvm-commits.

Currently, with -fPIC, 

We see this:

!llvm.module.flags = !{!0}
!0 = !{i32 1, !"PIC Level", i32 2}

and module.getPICLevel() is used to query PIC.  I am doing the same for PIE.

I will follow this up with patches to:

* Set PIE Level in LLVM in Clang and delete llvm::TargetOptions::PositionIndependentExecutable target member.
* Use Module::getPIELevel to check for PIE.


http://reviews.llvm.org/D19671

Files:
  include/llvm/IR/Module.h
  include/llvm/Support/CodeGen.h
  lib/IR/Module.cpp

Index: lib/IR/Module.cpp
===================================================================
--- lib/IR/Module.cpp
+++ lib/IR/Module.cpp
@@ -497,6 +497,20 @@
   addModuleFlag(ModFlagBehavior::Error, "PIC Level", PL);
 }
 
+PIELevel::Level Module::getPIELevel() const {
+  auto *Val = cast_or_null<ConstantAsMetadata>(getModuleFlag("PIE Level"));
+
+  if (!Val)
+    return PIELevel::Default;
+
+  return static_cast<PIELevel::Level>(
+      cast<ConstantInt>(Val->getValue())->getZExtValue());
+}
+
+void Module::setPIELevel(PIELevel::Level PL) {
+  addModuleFlag(ModFlagBehavior::Error, "PIE Level", PL);
+}
+
 void Module::setMaximumFunctionCount(uint64_t Count) {
   addModuleFlag(ModFlagBehavior::Error, "MaxFunctionCount", Count);
 }
Index: include/llvm/Support/CodeGen.h
===================================================================
--- include/llvm/Support/CodeGen.h
+++ include/llvm/Support/CodeGen.h
@@ -32,6 +32,10 @@
     enum Level { Default=0, Small=1, Large=2 };
   }
 
+  namespace PIELevel {
+    enum Level { Default=0, Small=1, Large=2 };
+  }
+
   // TLS models.
   namespace TLSModel {
     enum Model {
Index: include/llvm/IR/Module.h
===================================================================
--- include/llvm/IR/Module.h
+++ include/llvm/IR/Module.h
@@ -732,6 +732,17 @@
   void setPICLevel(PICLevel::Level PL);
 /// @}
 
+/// @}
+/// @name Utility functions for querying and setting PIE level
+/// @{
+
+  /// \brief Returns the PIE level (small or large model)
+  PIELevel::Level getPIELevel() const;
+
+  /// \brief Set the PIE level (small or large model)
+  void setPIELevel(PIELevel::Level PL);
+/// @}
+
   /// @name Utility functions for querying and setting PGO summary
   /// @{
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D19671.55435.patch
Type: text/x-patch
Size: 1729 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160428/34c3b7fd/attachment.bin>


More information about the llvm-commits mailing list