[clang] [lld] [llvm] Integrated Distributed ThinLTO (DTLTO): Initial support (PR #126654)

Fangrui Song via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 25 21:47:24 PST 2025


================
@@ -1702,6 +1703,37 @@ static uint8_t getOsAbi(const Triple &t) {
   }
 }
 
+// Check if an archive file is a thin archive.
+static bool isThinArchive(Ctx &ctx, StringRef archiveFilePath) {
+  const size_t thinArchiveMagicLen = sizeof(ThinArchiveMagic) - 1;
+
+  ErrorOr<std::unique_ptr<MemoryBuffer>> memBufferOrError =
+      MemoryBuffer::getFileSlice(archiveFilePath, thinArchiveMagicLen, 0);
+  if (std::error_code ec = memBufferOrError.getError()) {
+    ErrAlways(ctx) << "cannot open " << archiveFilePath << ": " << ec.message();
+    return false;
+  }
+
+  MemoryBufferRef memBufRef = *memBufferOrError.get();
+  return memBufRef.getBuffer().starts_with(ThinArchiveMagic);
+}
+
+// Compute a thin archive member full file path.
+static std::string
+computeThinArchiveMemberFullPath(const StringRef modulePath,
----------------
MaskRay wrote:

Now there are quite a few changes to  Driver and InputFiles, which actually made me more nervous. Non-dtlto use cases now incur the overhead (not that they can't, but it's not necessary to introduce these changes for the linker option feature).

These changes might turn out to be unneeded when non-thin archives are supported.

Would be nice to restore the previous version but just improve the local code and check the thin magic only when --thinlto-distributor= is specified.

https://github.com/llvm/llvm-project/pull/126654


More information about the llvm-commits mailing list