[PATCH] D83688: [Bitcode] Avoid duplicating linker option when upgrading

Steven Wu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 13 09:58:46 PDT 2020


steven_wu created this revision.
steven_wu added reviewers: pcc, t.p.northover, dexonsmith.
Herald added subscribers: ributzka, jkorous, hiraditya.
Herald added a project: LLVM.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D83688

Files:
  llvm/lib/Bitcode/Reader/BitcodeReader.cpp
  llvm/test/Bitcode/Inputs/linker-options.bc
  llvm/test/Bitcode/upgrade-linker-options-2.ll


Index: llvm/test/Bitcode/upgrade-linker-options-2.ll
===================================================================
--- /dev/null
+++ llvm/test/Bitcode/upgrade-linker-options-2.ll
@@ -0,0 +1,3 @@
+;; Test upgrade linker option doesn't create duplicated linker options.
+; RUN: llvm-dis %S/Inputs/linker-options.bc -o - | FileCheck %s
+; CHECK: !llvm.linker.options = !{!2}
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
===================================================================
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -2965,12 +2965,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<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();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D83688.277469.patch
Type: text/x-patch
Size: 1524 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200713/3073b828/attachment.bin>


More information about the llvm-commits mailing list