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

Rafael EspĂ­ndola via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 28 11:53:52 PDT 2016


Out of curiosity. What is the relationship of this and

enum Model { Default, Static, PIC_, DynamicNoPIC };

Is the enum something we should deprecate and eventually remove? The
medata is used only on The powerpc backend right now.

Cheers,
Rafael


On 28 April 2016 at 13:18, Sriraman Tallam via llvm-commits
<llvm-commits at lists.llvm.org> wrote:
> 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
>    /// @{
>
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>


More information about the llvm-commits mailing list