diff --git a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp --- a/llvm/lib/Bitcode/Reader/BitcodeReader.cpp +++ b/llvm/lib/Bitcode/Reader/BitcodeReader.cpp @@ -2969,12 +2969,15 @@ } // 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(); diff --git a/llvm/test/Bitcode/Inputs/linker-options.bc b/llvm/test/Bitcode/Inputs/linker-options.bc new file mode 100644 index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@