[PATCH] D37961: [ThinLTO] Avoid archive member collisions with old API

Johan Engelen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 17 09:31:02 PDT 2017


johanengelen created this revision.
Herald added subscribers: eraman, inglorion.

ld64 on OSX uses the old ThinLTOCodegenerator API. When two modules have the same name in an archive (valid archive), a name collision happens for the modules' buffer identifiers.
This PR resolves this, by suffixing the module name with an increasing number such that the identifiers are guaranteed to be unique.

For a similar fix in LLD, see https://reviews.llvm.org/D25495


https://reviews.llvm.org/D37961

Files:
  lib/LTO/ThinLTOCodeGenerator.cpp


Index: lib/LTO/ThinLTOCodeGenerator.cpp
===================================================================
--- lib/LTO/ThinLTOCodeGenerator.cpp
+++ lib/LTO/ThinLTOCodeGenerator.cpp
@@ -535,7 +535,9 @@
 } // end anonymous namespace
 
 void ThinLTOCodeGenerator::addModule(StringRef Identifier, StringRef Data) {
-  ThinLTOBuffer Buffer(Data, Identifier);
+  std::string Id =
+      (Twine(Identifier) + "_" + std::to_string(Modules.size())).str();
+  ThinLTOBuffer Buffer(Data, std::move(Id));
   LLVMContext Context;
   StringRef TripleStr;
   ErrorOr<std::string> TripleOrErr = expectedToErrorOrAndEmitErrors(


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D37961.115579.patch
Type: text/x-patch
Size: 612 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170917/3ba91953/attachment.bin>


More information about the llvm-commits mailing list