[PATCH] D115416: [lld-macho] Prevent writing map files on the critical path

Jez Ng via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 8 20:38:01 PST 2021


int3 added a comment.

> Isn't line 1151, writeMapAsync a variable? :) (not a func call)

d'oh, yes, brain fart there...



================
Comment at: lld/MachO/Writer.cpp:1151-1152
   finalizeAddresses();
+  std::future<void> writeMapAsync(std::async(writeMapFile));
   finalizeLinkEditSegment();
   writeOutputFile();
----------------
oontvoo wrote:
> int3 wrote:
> > oontvoo wrote:
> > > 
> > yeah, I don't think the map file contains anything from LinkEdit, but just to be safe I would move it after everything's finalized. I'm assuming `writeOutputFile` takes longer than `writeMapAsync` anyway
> PS: actually, dont you want  `std::future<void> writeMapAsync (std::async(std::launch::async, []{ writeMapFile(); })); `  ?
> 
yup, based on https://en.cppreference.com/w/cpp/thread/async I think @oontvoo 's right.

Also, that page says

> If the std::future obtained from std::async is not moved from or bound to a reference, the destructor of the std::future will block at the end of the full expression until the asynchronous operation completes

so I don't think the `get()` call below is necessary?


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D115416/new/

https://reviews.llvm.org/D115416



More information about the llvm-commits mailing list