OSDN Git Service

[ThinLTO] Avoid archive member collisions with old API
authorJohan Engelen <jbc.engelen@gmail.com>
Sun, 17 Sep 2017 17:38:26 +0000 (17:38 +0000)
committerJohan Engelen <jbc.engelen@gmail.com>
Sun, 17 Sep 2017 17:38:26 +0000 (17:38 +0000)
Summary:
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

Reviewers: mehdi_amini, tejohnson

Reviewed By: mehdi_amini

Subscribers: inglorion, eraman, llvm-commits

Differential Revision: https://reviews.llvm.org/D37961

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@313488 91177308-0d34-0410-b5e6-96231b3b80d8

lib/LTO/ThinLTOCodeGenerator.cpp

index ffd78da..d6e5d4d 100644 (file)
@@ -535,7 +535,9 @@ static void initTMBuilder(TargetMachineBuilder &TMBuilder,
 } // 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(