llvm-project/llvm/lib/LTO
Steven Wu cf90203b0b [ThinLTO] Fix memory corruption in ThinLTOCodeGenerator when CodeGenOnly was specified
Summary:
Issue occurs when doing ThinLTO with CodeGenOnly flag.
TMBuilder.TheTriple is assigned to by multiple threads in an unsafe way resulting in double-free of std::string memory.

Pseudocode:
if (CodeGenOnly) {
  // Perform only parallel codegen and return.
  ThreadPool Pool;
  int count = 0;
  for (auto &ModuleBuffer : Modules) {
    Pool.async([&](int count) {
    ...
      /// Now call OutputBuffer = codegen(*TheModule);
      /// Which turns into initTMBuilder(moduleTMBuilder, Triple(TheModule.getTargetTriple()));
      /// Which turns into

      TMBuilder.TheTriple = std::move(TheTriple);   // std::string = "....."
      /// So, basically std::string assignment to same string on multiple threads = memory corruption

  }

  return;
}

Patch by Alex Borcan

Reviewers: llvm-commits, steven_wu

Reviewed By: steven_wu

Subscribers: mehdi_amini, inglorion, eraman, steven_wu, dexonsmith, llvm-commits

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

llvm-svn: 341422
2018-09-04 22:54:17 +00:00
..
CMakeLists.txt Support: Add a VCSRevision.h header file. 2017-04-13 01:26:12 +00:00
Caching.cpp [ThinLTO] Update ThinLTO cache file atimes when on Windows 2018-07-04 14:17:10 +00:00
LLVMBuild.txt NFC: Move ObjectMemoryBuffer to support 2018-04-15 05:17:14 +00:00
LTO.cpp [LTO] Don't internalize declarations 2018-07-27 05:40:29 +00:00
LTOBackend.cpp [ThinLTO] Enable ThinLTO WholeProgramDevirt and LowerTypeTests in new PM 2018-07-19 14:51:32 +00:00
LTOCodeGenerator.cpp Revert "[LTO] Support filtering by hotness threshold" 2018-03-08 01:13:10 +00:00
LTOModule.cpp Move TargetLoweringObjectFile from CodeGen to Target to fix layering 2018-03-23 23:58:19 +00:00
ThinLTOCodeGenerator.cpp [ThinLTO] Fix memory corruption in ThinLTOCodeGenerator when CodeGenOnly was specified 2018-09-04 22:54:17 +00:00
UpdateCompilerUsed.cpp Remove redundant includes from lib/LTO. 2017-12-13 21:30:53 +00:00