[PATCH] D71219: Fix conflict value for metadata "Objective-C Garbage Collection" in the mix of swift and Objective-C bitcode
Jin Lin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Dec 9 11:29:56 PST 2019
jinlin created this revision.
jinlin added a reviewer: rjmccall.
Herald added subscribers: llvm-commits, dexonsmith, hiraditya, mehdi_amini.
Herald added a project: LLVM.
The change is to fix conflict value for metadata "Objective-C Garbage Collection" in the mix of swift and Objective-C bitcode.
The purpose is to provide the support of LTO for swift and Objective-C mixed project.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D71219
Files:
llvm/lib/Linker/IRMover.cpp
Index: llvm/lib/Linker/IRMover.cpp
===================================================================
--- llvm/lib/Linker/IRMover.cpp
+++ llvm/lib/Linker/IRMover.cpp
@@ -1260,15 +1260,52 @@
Flags[ID].first = SrcOp;
};
+ // Check the input bitcode is swift generated bitcode.
+ auto isSwiftBitCode = [&](Module &M) {
+ SmallVector<Module::ModuleFlagEntry, 8> ModuleFlags;
+ M.getModuleFlagsMetadata(ModuleFlags);
+ for (const auto &MFE: ModuleFlags) {
+ if (MFE.Behavior == Module::Require)
+ continue;
+ StringRef Key = MFE.Key->getString();
+ if (Key == "Swift Version")
+ return true;
+ }
+ return false;
+ };
+
// If either flag has override behavior, handle it first.
if (DstBehaviorValue == Module::Override) {
// Diagnose inconsistent flags which both have override behavior.
if (SrcBehaviorValue == Module::Override &&
- SrcOp->getOperand(2) != DstOp->getOperand(2))
+ SrcOp->getOperand(2) != DstOp->getOperand(2)) {
+ if (ID->getString().equals("Objective-C Garbage Collection")) {
+
+ // Merge the value of metadata "Objective-C Garbage Collection"
+ // into one value by shifting. The purpose of this change is
+ // to support LTO in Swift and Objective-C mixed project.
+
+ auto Int32Ty = Type::getInt32Ty(DstM.getContext());
+ auto SrcMD = dyn_cast<ConstantAsMetadata>(SrcOp->getOperand(2));
+ auto DstMD = dyn_cast<ConstantAsMetadata>(DstOp->getOperand(2));
+ assert(!SrcMD && !DstMD);
+ unsigned SrcVal = SrcMD->getValue()->getUniqueInteger().getZExtValue();
+ unsigned DstVal = DstMD->getValue()->getUniqueInteger().getZExtValue();
+ if ((isSwiftBitCode(*SrcM) && DstVal < 64) ||
+ (isSwiftBitCode(DstM) && SrcVal < 64)) {
+ unsigned resVal = SrcVal | DstVal;
+ SrcOp->replaceOperandWith(2,
+ ConstantAsMetadata::get(ConstantInt::get(Int32Ty,resVal)));
+ DstOp->replaceOperandWith(2,
+ ConstantAsMetadata::get(ConstantInt::get(Int32Ty,resVal)));
+ continue;
+ }
+ }
return stringErr("linking module flags '" + ID->getString() +
"': IDs have conflicting override values in '" +
SrcM->getModuleIdentifier() + "' and '" +
DstM.getModuleIdentifier() + "'");
+ }
continue;
} else if (SrcBehaviorValue == Module::Override) {
// Update the destination flag to that of the source.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71219.232903.patch
Type: text/x-patch
Size: 2625 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191209/efa5ff9c/attachment.bin>
More information about the llvm-commits
mailing list