@@ -677,15 +677,42 @@ bool embeddedUavcanCatalogIntegrityOk()
677677 uavcan_embedded_mlir::kEmbeddedUavcanMlirSha256 );
678678}
679679
680+ llvm::StringRef embeddedUavcanCatalogRecordedSha256 ()
681+ {
682+ return uavcan_embedded_mlir::kEmbeddedUavcanMlirSha256 ;
683+ }
684+
685+ std::string embeddedUavcanCatalogComputedSha256 ()
686+ {
687+ const llvm::StringRef text = uavcan_embedded_mlir::kEmbeddedUavcanMlirText ;
688+ const std::array<uint8_t , 32 > digest =
689+ llvm::SHA256::hash (llvm::ArrayRef<uint8_t >(reinterpret_cast <const uint8_t *>(text.data ()), text.size ()));
690+ return llvm::toHex (digest, /* LowerCase=*/ true );
691+ }
692+
680693llvm::Expected<UavcanEmbeddedCatalog> loadUavcanEmbeddedCatalog (mlir::MLIRContext& context,
681694 DiagnosticEngine& diagnostics)
682695{
683696 // Integrity gate: refuse to parse a blob that does not match its recorded SHA-256 (corruption,
684697 // tampering, or a text/hash mismatch introduced during the build).
685698 if (!embeddedUavcanCatalogIntegrityOk ())
686699 {
687- diagnostics.error ({" <embedded-uavcan>" , 1 , 1 },
688- " embedded UAVCAN catalog failed SHA-256 integrity verification" );
700+ const SourceLocation here{" <embedded-uavcan>" , 1 , 1 };
701+ diagnostics.error (here, " embedded UAVCAN catalog failed SHA-256 integrity verification" );
702+ diagnostics.note (here,
703+ " recorded " + embeddedUavcanCatalogRecordedSha256 ().str () + " , computed " +
704+ embeddedUavcanCatalogComputedSha256 ());
705+ diagnostics.note (here,
706+ std::string (" both values are generated into " ) + kEmbeddedUavcanCatalogSourceFile +
707+ " , so they disagree only when that file was hand-edited, partially regenerated, "
708+ " or merged badly" );
709+ diagnostics.note (here,
710+ std::string (" restore it with 'git checkout -- " ) + kEmbeddedUavcanCatalogSourceFile +
711+ " ', or regenerate it with 'python3 tools/dsdlc/generate_embedded_uavcan_mlir.py "
712+ " --dsdlc <path-to-dsdlc>', then rebuild" );
713+ diagnostics.note (here,
714+ " to build without the compiled-in catalog, pass --no-embedded-uavcan and add "
715+ " --lookup-dir <checkout>/public_regulated_data_types/uavcan" );
689716 return llvm::createStringError (llvm::inconvertibleErrorCode (),
690717 " embedded UAVCAN catalog failed SHA-256 integrity verification" );
691718 }
0 commit comments