[llvm-branch-commits] [llvm-branch] r311481 - Merging r311387:
Hans Wennborg via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Tue Aug 22 11:19:41 PDT 2017
Author: hans
Date: Tue Aug 22 11:19:41 2017
New Revision: 311481
URL: http://llvm.org/viewvc/llvm-project?rev=311481&view=rev
Log:
Merging r311387:
------------------------------------------------------------------------
r311387 | steven_wu | 2017-08-21 14:49:13 -0700 (Mon, 21 Aug 2017) | 16 lines
[IR] AutoUpgrade ModuleFlagBehavior for PIC and PIE level
Summary:
>From r303590, ModuleFlagBehavior for PIC and PIE level is changed from
Error to Max. This will cause bitcode compatibility issue when linking
against a bitcode static archive built with old compiler.
Add an auto-ugprade path to upgrade the the ModuleFlagBehavior in the
old bitcode to match the new one so IRLinker can link them.
Reviewers: tejohnson, mehdi_amini, dexonsmith
Reviewed By: dexonsmith
Subscribers: hans, llvm-commits
Differential Revision: https://reviews.llvm.org/D36556
------------------------------------------------------------------------
Modified:
llvm/branches/release_50/ (props changed)
llvm/branches/release_50/lib/IR/AutoUpgrade.cpp
llvm/branches/release_50/test/Bitcode/upgrade-module-flag.ll
llvm/branches/release_50/test/Linker/module-flags-pic-1-a.ll
Propchange: llvm/branches/release_50/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug 22 11:19:41 2017
@@ -1,3 +1,3 @@
/llvm/branches/Apple/Pertwee:110850,110961
/llvm/branches/type-system-rewrite:133420-134817
-/llvm/trunk:155241,308483-308484,308503,308808,308813,308847,308891,308906,308950,308963,308978,308986,309044,309071,309113,309120,309122,309140,309227,309302,309321,309323,309325,309330,309343,309353,309355,309422,309481,309483,309495,309555,309561,309594,309614,309651,309744,309758,309849,309928,309930,309945,310066,310071,310190,310240-310242,310250,310253,310262,310267,310481,310492,310498,310510,310534,310552,310604,310712,310779,310784,310796,310842,310906,310926,310939,310979,310988,310990-310991,311061,311068,311071,311087,311229,311258,311263,311429
+/llvm/trunk:155241,308483-308484,308503,308808,308813,308847,308891,308906,308950,308963,308978,308986,309044,309071,309113,309120,309122,309140,309227,309302,309321,309323,309325,309330,309343,309353,309355,309422,309481,309483,309495,309555,309561,309594,309614,309651,309744,309758,309849,309928,309930,309945,310066,310071,310190,310240-310242,310250,310253,310262,310267,310481,310492,310498,310510,310534,310552,310604,310712,310779,310784,310796,310842,310906,310926,310939,310979,310988,310990-310991,311061,311068,311071,311087,311229,311258,311263,311387,311429
Modified: llvm/branches/release_50/lib/IR/AutoUpgrade.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_50/lib/IR/AutoUpgrade.cpp?rev=311481&r1=311480&r2=311481&view=diff
==============================================================================
--- llvm/branches/release_50/lib/IR/AutoUpgrade.cpp (original)
+++ llvm/branches/release_50/lib/IR/AutoUpgrade.cpp Tue Aug 22 11:19:41 2017
@@ -2239,14 +2239,14 @@ bool llvm::UpgradeDebugInfo(Module &M) {
}
bool llvm::UpgradeModuleFlags(Module &M) {
- const NamedMDNode *ModFlags = M.getModuleFlagsMetadata();
+ NamedMDNode *ModFlags = M.getModuleFlagsMetadata();
if (!ModFlags)
return false;
- bool HasObjCFlag = false, HasClassProperties = false;
+ bool HasObjCFlag = false, HasClassProperties = false, Changed = false;
for (unsigned I = 0, E = ModFlags->getNumOperands(); I != E; ++I) {
MDNode *Op = ModFlags->getOperand(I);
- if (Op->getNumOperands() < 2)
+ if (Op->getNumOperands() != 3)
continue;
MDString *ID = dyn_cast_or_null<MDString>(Op->getOperand(1));
if (!ID)
@@ -2255,7 +2255,24 @@ bool llvm::UpgradeModuleFlags(Module &M)
HasObjCFlag = true;
if (ID->getString() == "Objective-C Class Properties")
HasClassProperties = true;
+ // Upgrade PIC/PIE Module Flags. The module flag behavior for these two
+ // field was Error and now they are Max.
+ if (ID->getString() == "PIC Level" || ID->getString() == "PIE Level") {
+ if (auto *Behavior =
+ mdconst::dyn_extract_or_null<ConstantInt>(Op->getOperand(0))) {
+ if (Behavior->getLimitedValue() == Module::Error) {
+ Type *Int32Ty = Type::getInt32Ty(M.getContext());
+ Metadata *Ops[3] = {
+ ConstantAsMetadata::get(ConstantInt::get(Int32Ty, Module::Max)),
+ MDString::get(M.getContext(), ID->getString()),
+ Op->getOperand(2)};
+ ModFlags->setOperand(I, MDNode::get(M.getContext(), Ops));
+ Changed = true;
+ }
+ }
+ }
}
+
// "Objective-C Class Properties" is recently added for Objective-C. We
// upgrade ObjC bitcodes to contain a "Objective-C Class Properties" module
// flag of value 0, so we can correclty downgrade this flag when trying to
@@ -2264,9 +2281,10 @@ bool llvm::UpgradeModuleFlags(Module &M)
if (HasObjCFlag && !HasClassProperties) {
M.addModuleFlag(llvm::Module::Override, "Objective-C Class Properties",
(uint32_t)0);
- return true;
+ Changed = true;
}
- return false;
+
+ return Changed;
}
static bool isOldLoopArgument(Metadata *MD) {
Modified: llvm/branches/release_50/test/Bitcode/upgrade-module-flag.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_50/test/Bitcode/upgrade-module-flag.ll?rev=311481&r1=311480&r2=311481&view=diff
==============================================================================
--- llvm/branches/release_50/test/Bitcode/upgrade-module-flag.ll (original)
+++ llvm/branches/release_50/test/Bitcode/upgrade-module-flag.ll Tue Aug 22 11:19:41 2017
@@ -1,9 +1,13 @@
; RUN: llvm-as < %s | llvm-dis | FileCheck %s
; RUN: verify-uselistorder < %s
-!llvm.module.flags = !{!0}
+!llvm.module.flags = !{!0, !1, !2}
-!0 = !{i32 1, !"Objective-C Image Info Version", i32 0}
+!0 = !{i32 1, !"PIC Level", i32 1}
+!1 = !{i32 1, !"PIE Level", i32 1}
+!2 = !{i32 1, !"Objective-C Image Info Version", i32 0}
-; CHECK: !0 = !{i32 1, !"Objective-C Image Info Version", i32 0}
-; CHECK: !1 = !{i32 4, !"Objective-C Class Properties", i32 0}
+; CHECK: !0 = !{i32 7, !"PIC Level", i32 1}
+; CHECK: !1 = !{i32 7, !"PIE Level", i32 1}
+; CHECK: !2 = !{i32 1, !"Objective-C Image Info Version", i32 0}
+; CHECK: !3 = !{i32 4, !"Objective-C Class Properties", i32 0}
Modified: llvm/branches/release_50/test/Linker/module-flags-pic-1-a.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/release_50/test/Linker/module-flags-pic-1-a.ll?rev=311481&r1=311480&r2=311481&view=diff
==============================================================================
--- llvm/branches/release_50/test/Linker/module-flags-pic-1-a.ll (original)
+++ llvm/branches/release_50/test/Linker/module-flags-pic-1-a.ll Tue Aug 22 11:19:41 2017
@@ -2,8 +2,8 @@
; test linking modules with specified and default PIC levels
-!0 = !{ i32 1, !"PIC Level", i32 1 }
+!0 = !{ i32 7, !"PIC Level", i32 1 }
!llvm.module.flags = !{!0}
; CHECK: !llvm.module.flags = !{!0}
-; CHECK: !0 = !{i32 1, !"PIC Level", i32 1}
+; CHECK: !0 = !{i32 7, !"PIC Level", i32 1}
More information about the llvm-branch-commits
mailing list