diff options
author | Steven Wu <stevenwu@apple.com> | 2020-07-23 13:04:57 -0700 |
---|---|---|
committer | Steven Wu <stevenwu@apple.com> | 2020-07-23 13:07:28 -0700 |
commit | ac375c2fe316dae6eb770b38f90d6b67fadd22ec (patch) | |
tree | a4bc36e78eb295993df534812ae7f4a0b2bda981 /llvm/lib/Bitcode/Reader/BitcodeReader.cpp | |
parent | 183342c0a9850e60dd7a004b651c83dfb3a7d25e (diff) | |
download | llvm-ac375c2fe316dae6eb770b38f90d6b67fadd22ec.zip llvm-ac375c2fe316dae6eb770b38f90d6b67fadd22ec.tar.gz llvm-ac375c2fe316dae6eb770b38f90d6b67fadd22ec.tar.bz2 |
[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
Diffstat (limited to 'llvm/lib/Bitcode/Reader/BitcodeReader.cpp')
-rw-r--r-- | llvm/lib/Bitcode/Reader/BitcodeReader.cpp | 15 |
1 files changed, 9 insertions, 6 deletions
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<MDNode>(Val)->operands()) - LinkerOpts->addOperand(cast<MDNode>(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<MDNode>(Val)->operands()) + LinkerOpts->addOperand(cast<MDNode>(MDOptions)); + } } DeferredMetadataInfo.clear(); |