1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00
llvm-mirror/lib/LTO
Steven Wu 60afa177aa [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
..
Caching.cpp
CMakeLists.txt
LLVMBuild.txt
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
LTOModule.cpp
ThinLTOCodeGenerator.cpp [ThinLTO] Fix memory corruption in ThinLTOCodeGenerator when CodeGenOnly was specified 2018-09-04 22:54:17 +00:00
UpdateCompilerUsed.cpp