Index: include/llvm/IR/Module.h =================================================================== --- include/llvm/IR/Module.h +++ include/llvm/IR/Module.h @@ -23,6 +23,7 @@ #include "llvm/IR/GlobalVariable.h" #include "llvm/IR/Metadata.h" #include "llvm/Support/CBindingWrapping.h" +#include "llvm/Support/CodeGen.h" #include "llvm/Support/DataTypes.h" #include @@ -637,6 +638,14 @@ unsigned getDwarfVersion() const; /// @} +/// @name Utility functions for querying and setting PIC level +/// @{ + + /// \brief Returns the PIC level (small or large model) + PICLevel::Level getPICLevel() const; + + /// \brief Set the PIC level (small or large model) + void setPICLevel(PICLevel::Level PL); }; /// An raw_ostream inserter for modules. Index: include/llvm/Support/CodeGen.h =================================================================== --- include/llvm/Support/CodeGen.h +++ include/llvm/Support/CodeGen.h @@ -30,6 +30,10 @@ enum Model { Default, JITDefault, Small, Kernel, Medium, Large }; } + namespace PICLevel { + enum Level { Default=0, Small=1, Large=2 }; + } + // TLS models. namespace TLSModel { enum Model { Index: lib/IR/Module.cpp =================================================================== --- lib/IR/Module.cpp +++ lib/IR/Module.cpp @@ -469,3 +469,16 @@ Entry.second.Name = &Entry; return &Entry.second; } + +PICLevel::Level Module::getPICLevel() const { + Value *Val = getModuleFlag("flag_pic"); + + if (Val == NULL) + return PICLevel::Default; + + return static_cast(cast(Val)->getZExtValue()); +} + +void Module::setPICLevel(PICLevel::Level PL) { + addModuleFlag(ModFlagBehavior::Error, "flag_pic", PL); +} Index: test/Linker/module-flags-pic-1-a.ll =================================================================== --- /dev/null +++ test/Linker/module-flags-pic-1-a.ll @@ -0,0 +1,7 @@ +; RUN: llvm-link %s %p/module-flags-pic-1-b.ll -S -o - | FileCheck + +; test linking modules with specified and default PIC levels + +!0 = metadata !{ i32 1, metadata !"flag_pic", i32 1 } + +!llvm.module.flags = !{!0} Index: test/Linker/module-flags-pic-1-b.ll =================================================================== --- /dev/null +++ test/Linker/module-flags-pic-1-b.ll @@ -0,0 +1 @@ +; RUN: true Index: test/Linker/module-flags-pic-2-a.ll =================================================================== --- /dev/null +++ test/Linker/module-flags-pic-2-a.ll @@ -0,0 +1,8 @@ +; RUN: llvm-link %s %p/module-flags-pic-2-b.ll -S -o - | FileCheck +; XFAIL: * + +; test linking modules with two different PIC levels + +!0 = metadata !{ i32 1, metadata !"flag_pic", i32 1 } + +!llvm.module.flags = !{!0} Index: test/Linker/module-flags-pic-2-b.ll =================================================================== --- /dev/null +++ test/Linker/module-flags-pic-2-b.ll @@ -0,0 +1,5 @@ +; RUN: true + +!0 = metadata !{ i32 1, metadata !"flag_pic", i32 2 } + +!llvm.module.flags = !{!0}