|
28 | 28 | #include "llvm/Support/LEB128.h"
|
29 | 29 | #include "llvm/Support/Parallel.h"
|
30 | 30 | #include "llvm/Support/Path.h"
|
31 |
| -#include "llvm/Support/ThreadPool.h" |
32 | 31 | #include "llvm/Support/TimeProfiler.h"
|
| 32 | +#include "llvm/Support/thread.h" |
33 | 33 | #include "llvm/Support/xxhash.h"
|
34 | 34 |
|
35 | 35 | #include <algorithm>
|
@@ -66,7 +66,6 @@ class Writer {
|
66 | 66 |
|
67 | 67 | template <class LP> void run();
|
68 | 68 |
|
69 |
| - DefaultThreadPool threadPool; |
70 | 69 | std::unique_ptr<FileOutputBuffer> &buffer;
|
71 | 70 | uint64_t addr = 0;
|
72 | 71 | uint64_t fileOff = 0;
|
@@ -1121,14 +1120,12 @@ void Writer::finalizeLinkEditSegment() {
|
1121 | 1120 | symtabSection, indirectSymtabSection,
|
1122 | 1121 | dataInCodeSection, functionStartsSection,
|
1123 | 1122 | };
|
1124 |
| - SmallVector<std::shared_future<void>> threadFutures; |
1125 |
| - threadFutures.reserve(linkEditSections.size()); |
1126 |
| - for (LinkEditSection *osec : linkEditSections) |
1127 |
| - if (osec) |
1128 |
| - threadFutures.emplace_back(threadPool.async( |
1129 |
| - [](LinkEditSection *osec) { osec->finalizeContents(); }, osec)); |
1130 |
| - for (std::shared_future<void> &future : threadFutures) |
1131 |
| - future.wait(); |
| 1123 | + |
| 1124 | + parallelForEach(linkEditSections.begin(), linkEditSections.end(), |
| 1125 | + [](LinkEditSection *osec) { |
| 1126 | + if (osec) |
| 1127 | + osec->finalizeContents(); |
| 1128 | + }); |
1132 | 1129 |
|
1133 | 1130 | // Now that __LINKEDIT is filled out, do a proper calculation of its
|
1134 | 1131 | // addresses and offsets.
|
@@ -1170,6 +1167,8 @@ void Writer::openFile() {
|
1170 | 1167 | }
|
1171 | 1168 |
|
1172 | 1169 | void Writer::writeSections() {
|
| 1170 | + TimeTraceScope timeScope("Write output sections"); |
| 1171 | + |
1173 | 1172 | uint8_t *buf = buffer->getBufferStart();
|
1174 | 1173 | std::vector<const OutputSection *> osecs;
|
1175 | 1174 | for (const OutputSegment *seg : outputSegments)
|
@@ -1200,18 +1199,15 @@ void Writer::writeUuid() {
|
1200 | 1199 |
|
1201 | 1200 | ArrayRef<uint8_t> data{buffer->getBufferStart(), buffer->getBufferEnd()};
|
1202 | 1201 | std::vector<ArrayRef<uint8_t>> chunks = split(data, 1024 * 1024);
|
| 1202 | + |
1203 | 1203 | // Leave one slot for filename
|
1204 | 1204 | std::vector<uint64_t> hashes(chunks.size() + 1);
|
1205 |
| - SmallVector<std::shared_future<void>> threadFutures; |
1206 |
| - threadFutures.reserve(chunks.size()); |
1207 |
| - for (size_t i = 0; i < chunks.size(); ++i) |
1208 |
| - threadFutures.emplace_back(threadPool.async( |
1209 |
| - [&](size_t j) { hashes[j] = xxh3_64bits(chunks[j]); }, i)); |
1210 |
| - for (std::shared_future<void> &future : threadFutures) |
1211 |
| - future.wait(); |
| 1205 | + parallelFor(0, chunks.size(), |
| 1206 | + [&](size_t i) { hashes[i] = xxh3_64bits(chunks[i]); }); |
1212 | 1207 | // Append the output filename so that identical binaries with different names
|
1213 | 1208 | // don't get the same UUID.
|
1214 | 1209 | hashes[chunks.size()] = xxh3_64bits(sys::path::filename(config->finalOutput));
|
| 1210 | + |
1215 | 1211 | uint64_t digest = xxh3_64bits({reinterpret_cast<uint8_t *>(hashes.data()),
|
1216 | 1212 | hashes.size() * sizeof(uint64_t)});
|
1217 | 1213 | uuidCommand->writeUuid(digest);
|
@@ -1330,15 +1326,18 @@ template <class LP> void Writer::run() {
|
1330 | 1326 | sortSegmentsAndSections();
|
1331 | 1327 | createLoadCommands<LP>();
|
1332 | 1328 | finalizeAddresses();
|
1333 |
| - threadPool.async([&] { |
| 1329 | + |
| 1330 | + llvm::thread mapFileWriter([&] { |
1334 | 1331 | if (LLVM_ENABLE_THREADS && config->timeTraceEnabled)
|
1335 | 1332 | timeTraceProfilerInitialize(config->timeTraceGranularity, "writeMapFile");
|
1336 | 1333 | writeMapFile();
|
1337 | 1334 | if (LLVM_ENABLE_THREADS && config->timeTraceEnabled)
|
1338 | 1335 | timeTraceProfilerFinishThread();
|
1339 | 1336 | });
|
| 1337 | + |
1340 | 1338 | finalizeLinkEditSegment();
|
1341 | 1339 | writeOutputFile();
|
| 1340 | + mapFileWriter.join(); |
1342 | 1341 | }
|
1343 | 1342 |
|
1344 | 1343 | template <class LP> void macho::writeResult() { Writer().run<LP>(); }
|
|
0 commit comments