zmodem wrote: > > What does the code that reads these files look like, could we leverage that > > somehow? > > You can call `clang::ObjectFilePCHContainerReader::ExtractPCH()` and then > check the magic. This lives in the CodeGen library which I don't think the > driver currently (or should) links against, but this is the best way to know > if something is valid.
Agreed we probably don't want that. Maybe a compromise would be to call `llvm::object::ObjectFile::createObjectFile` just to check that it's at least an object file? It looks like Driver is linking against Object already. > > > An alternative would be turn the logic around, and only ignore GCC PCH > > files (I believe they all start with the file magic `gpch`). However I do > > think that the current approach of "whitelisting" the kind of file we're > > looking for is better. > > I would be fine with this approach, but agree that it's best if we can be > more selective. My concern is that > `clang::ObjectFilePCHContainerReader::ExtractPCH()` and this detection may > get out of sync, as support for `-gmodules` is automatic anytime someone adds > a new object format. Speaking of keeping things in sync, I see we also have `printRawClangAST` in `llvm-objdump.cpp` duplicating some of `ExtractPCH`'s logic :) https://github.com/llvm/llvm-project/pull/77711 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits