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

Vy Nguyen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 9 11:04:40 PST 2021


oontvoo added a comment.

In D115416#3183365 <https://reviews.llvm.org/D115416#3183365>, @thevinster wrote:

> This was my initial thought. I abandoned this approach because 1/ I didn't quite know what the right syntax is to get this particular thing working and 2/ we aren't really trying to run writeMapFile in parallel with *only* `finalizeLinkEditSegment` or `writeOutputFile`. It's more about putting things off the critical path. Let's say `finalizeLinkEditSegment` is its own thread (for whatever reason) then things gets tricky since we would have a main thread, `writeMapFile` thread, and the `finalizeLinkEditSegment` thread. With async it's easy, but how does that look like with parallel?

(see suggested edit inline)

I'm not sure  understand how running writeMapFile() in its on thread (parallel with the other two functions) any different here ...  Either way, the "main" thread still have to block until all three are finished before it can return from this.

So the premise here is that writeMap is slow, hence we want to do something else in parallel with it rather than waiting for it , yes?



================
Comment at: lld/MachO/Writer.cpp:1150-1157
   finalizeAddresses();
+  std::future<void> writeMapAsync(std::async(writeMapFile));
   finalizeLinkEditSegment();
-  writeMapFile();
   writeOutputFile();
+
+  // Ensure writeMapFile completes before the main thread returns
+  // to prevent undefined behavior.
----------------
perhaps something like this ^ ?


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