================ @@ -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, ---------------- bd1976bris wrote:
I have simplified the code as we discussed. I also record which archives are thin when files are added to the link in `LinkerDriver::addFile` and then pass this information into the `BitcodeFile` constructor. This removes the hack where I was reopening the archive files and checking the magic bytes to determine if they were thin. The implementation is much improved now. Thanks. https://github.com/llvm/llvm-project/pull/126654 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits