diff options
author | Steven Wu <stevenwu@apple.com> | 2018-09-04 22:54:17 +0000 |
---|---|---|
committer | Steven Wu <stevenwu@apple.com> | 2018-09-04 22:54:17 +0000 |
commit | cf90203b0be9a7f5e96207ccc4d94791ceb4079f (patch) | |
tree | 08adb59576dfe24174ddc2f040e187c5c5d32def /llvm/lib/LTO/ThinLTOCodeGenerator.cpp | |
parent | 22ddc282b5df5b651bee678900788699dd70b95e (diff) | |
download | bcm5719-llvm-cf90203b0be9a7f5e96207ccc4d94791ceb4079f.tar.gz bcm5719-llvm-cf90203b0be9a7f5e96207ccc4d94791ceb4079f.zip |
[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
Diffstat (limited to 'llvm/lib/LTO/ThinLTOCodeGenerator.cpp')
-rw-r--r-- | llvm/lib/LTO/ThinLTOCodeGenerator.cpp | 10 |
1 files changed, 1 insertions, 9 deletions
diff --git a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp index 642e538ecf9..d111430052f 100644 --- a/llvm/lib/LTO/ThinLTOCodeGenerator.cpp +++ b/llvm/lib/LTO/ThinLTOCodeGenerator.cpp @@ -818,14 +818,6 @@ void ThinLTOCodeGenerator::optimize(Module &TheModule) { optimizeModule(TheModule, *TMBuilder.create(), OptLevel, Freestanding); } -/** - * Perform ThinLTO CodeGen. - */ -std::unique_ptr<MemoryBuffer> ThinLTOCodeGenerator::codegen(Module &TheModule) { - initTMBuilder(TMBuilder, Triple(TheModule.getTargetTriple())); - return codegenModule(TheModule, *TMBuilder.create()); -} - /// Write out the generated object file, either from CacheEntryPath or from /// OutputBuffer, preferring hard-link when possible. /// Returns the path to the generated file in SavedObjectsDirectoryPath. @@ -893,7 +885,7 @@ void ThinLTOCodeGenerator::run() { /*IsImporting*/ false); // CodeGen - auto OutputBuffer = codegen(*TheModule); + auto OutputBuffer = codegenModule(*TheModule, *TMBuilder.create()); if (SavedObjectsDirectoryPath.empty()) ProducedBinaries[count] = std::move(OutputBuffer); else |