From ac375c2fe316dae6eb770b38f90d6b67fadd22ec Mon Sep 17 00:00:00 2001 From: Steven Wu Date: Thu, 23 Jul 2020 13:04:57 -0700 Subject: [Bitcode] Avoid duplicating linker option when upgrading Summary: The upgrading path from old ModuleFlag based linker options to the new NamedMetadata based linker option in in materializeMetadata() which gets called once for the module and once for every GV. The linker options are getting dup'ed every time and it can create massive amount of the linker options in the object file that gets created from old bitcode. Fix the problem by checking if the new option exists or not before upgrade again. rdar://64543389 Reviewers: pcc, t.p.northover, dexonsmith, arphaman Reviewed By: arphaman Subscribers: hiraditya, jkorous, ributzka, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D83688 --- llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp') diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp index 2c7882b..9632b57 100644 --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2969,12 +2969,15 @@ Error BitcodeReader::materializeMetadata() { } // Upgrade "Linker Options" module flag to "llvm.linker.options" module-level - // metadata. - if (Metadata *Val = TheModule->getModuleFlag("Linker Options")) { - NamedMDNode *LinkerOpts = - TheModule->getOrInsertNamedMetadata("llvm.linker.options"); - for (const MDOperand &MDOptions : cast(Val)->operands()) - LinkerOpts->addOperand(cast(MDOptions)); + // metadata. Only upgrade if the new option doesn't exist to avoid upgrade + // multiple times. + if (!TheModule->getNamedMetadata("llvm.linker.options")) { + if (Metadata *Val = TheModule->getModuleFlag("Linker Options")) { + NamedMDNode *LinkerOpts = + TheModule->getOrInsertNamedMetadata("llvm.linker.options"); + for (const MDOperand &MDOptions : cast(Val)->operands()) + LinkerOpts->addOperand(cast(MDOptions)); + } } DeferredMetadataInfo.clear(); -- cgit v1.1