[llvm] r311387 - [IR] AutoUpgrade ModuleFlagBehavior for PIC and PIE level
Hans Wennborg via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 22 11:20:53 PDT 2017
Merged in r311481. Thanks!
On Mon, Aug 21, 2017 at 3:54 PM, Hans Wennborg <hans at chromium.org> wrote:
> I will merge this to 5.0 once it has baked in the tree a little bit.
>
> On Mon, Aug 21, 2017 at 2:49 PM, Steven Wu via llvm-commits
> <llvm-commits at lists.llvm.org> wrote:
>> Author: steven_wu
>> Date: Mon Aug 21 14:49:13 2017
>> New Revision: 311387
>>
>> URL: http://llvm.org/viewvc/llvm-project?rev=311387&view=rev
>> Log:
>> [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/trunk/lib/IR/AutoUpgrade.cpp
>> llvm/trunk/test/Bitcode/upgrade-module-flag.ll
>> llvm/trunk/test/Linker/module-flags-pic-1-a.ll
>>
>> Modified: llvm/trunk/lib/IR/AutoUpgrade.cpp
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/AutoUpgrade.cpp?rev=311387&r1=311386&r2=311387&view=diff
>> ==============================================================================
>> --- llvm/trunk/lib/IR/AutoUpgrade.cpp (original)
>> +++ llvm/trunk/lib/IR/AutoUpgrade.cpp Mon Aug 21 14:49:13 2017
>> @@ -2284,14 +2284,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)
>> @@ -2300,7 +2300,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
>> @@ -2309,9 +2326,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/trunk/test/Bitcode/upgrade-module-flag.ll
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Bitcode/upgrade-module-flag.ll?rev=311387&r1=311386&r2=311387&view=diff
>> ==============================================================================
>> --- llvm/trunk/test/Bitcode/upgrade-module-flag.ll (original)
>> +++ llvm/trunk/test/Bitcode/upgrade-module-flag.ll Mon Aug 21 14:49:13 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/trunk/test/Linker/module-flags-pic-1-a.ll
>> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Linker/module-flags-pic-1-a.ll?rev=311387&r1=311386&r2=311387&view=diff
>> ==============================================================================
>> --- llvm/trunk/test/Linker/module-flags-pic-1-a.ll (original)
>> +++ llvm/trunk/test/Linker/module-flags-pic-1-a.ll Mon Aug 21 14:49:13 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}
>>
>>
>> _______________________________________________
>> 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