@@ -688,73 +688,44 @@ handleAArch64BAAndGnuProperties(const ELFT &tPointer, Ctx &ctx, bool isBE,
688688 bool hasBA, bool hasGP,
689689 const AArch64BuildAttrSubsections &baInfo,
690690 const gnuPropertiesInfo &gpInfo) {
691+
692+ auto serializeUnsigned = [&](unsigned valueLow, unsigned valueHigh,
693+ bool isBE) -> std::array<uint8_t , 16 > {
694+ std::array<uint8_t , 16 > arr;
695+ for (size_t i = 0 ; i < 8 ; ++i) {
696+ arr[i] = static_cast <uint8_t >(
697+ (static_cast <uint64_t >(valueLow) >> (8 * (isBE ? (7 - i) : i))) &
698+ 0xFF );
699+ arr[i + 8 ] = static_cast <uint8_t >(
700+ (static_cast <uint64_t >(valueHigh) >> (8 * (isBE ? (7 - i) : i))) &
701+ 0xFF );
702+ };
703+ return arr;
704+ };
705+
691706 if (hasBA && hasGP) {
692707 if (!gpInfo.aarch64PauthAbiCoreInfo .empty ()) {
693- // check for a mismatch
694- auto deserializeArray = [&](size_t offset, bool isBE) {
695- unsigned value = 0 ;
696- for (size_t i = 0 ; i < 8 ; ++i) {
697- if (isBE)
698- value = (value << 8 ) | gpInfo.aarch64PauthAbiCoreInfo [i + offset];
699- else
700- value |= static_cast <uint64_t >(
701- gpInfo.aarch64PauthAbiCoreInfo [i + offset])
702- << (8 * i);
703- };
704- return value;
705- };
706- unsigned gnuPropPauthPlatform = deserializeArray (0 , isBE);
707- if (baInfo.pauth .tagPlatform != gnuPropPauthPlatform)
708- ErrAlways (ctx)
709- << tPointer
710- << " Pauth Platform mismatch: file contains both GNU properties and "
711- " AArch64 build attributes sections\n GNU properties: "
712- << gnuPropPauthPlatform
713- << " \n AArch64 build attributes: " << baInfo.pauth .tagPlatform ;
714- unsigned gnuPropPauthScheme = deserializeArray (8 , isBE);
715- if (baInfo.pauth .tagSchema != gnuPropPauthScheme)
708+ auto baPauth = serializeUnsigned (baInfo.pauth .tagPlatform ,
709+ baInfo.pauth .tagSchema , isBE);
710+ if (gpInfo.aarch64PauthAbiCoreInfo != ArrayRef<uint8_t >(baPauth))
716711 ErrAlways (ctx)
717712 << tPointer
718- << " Pauth Schema mismatch: file contains both GNU properties and "
719- " AArch64 build attributes sections\n GNU properties: "
720- << gnuPropPauthScheme
721- << " \n AArch64 build attributes: " << baInfo.pauth .tagSchema ;
713+ << " Pauth Data mismatch: file contains both GNU properties and "
714+ " AArch64 build attributes sections with different Pauth data" ;
722715 }
723- if (baInfo.fAndB .tagBTI != (gpInfo.andFeatures & 0x01 ))
724- ErrAlways (ctx)
725- << tPointer
726- << " Features BTI mismatch: file contains both GNU properties and "
727- " AArch64 build attributes sections\n GNU properties: "
728- << (gpInfo.andFeatures & 0x01 )
729- << " \n AArch64 build attributes: " << baInfo.fAndB .tagBTI ;
730- if (baInfo.fAndB .tagPAC != ((gpInfo.andFeatures >> 1 ) & 0x01 ))
731- ErrAlways (ctx)
732- << tPointer
733- << " Feature PAC mismatch: file contains both GNU properties and "
734- " AArch64 build attributes sections\n GNU properties: "
735- << ((gpInfo.andFeatures >> 1 ) & 0x01 )
736- << " \n AArch64 build attributes: " << baInfo.fAndB .tagPAC ;
737- if (baInfo.fAndB .tagGCS != ((gpInfo.andFeatures >> 2 ) & 0x01 ))
738- ErrAlways (ctx)
739- << tPointer
740- << " Feature GCS mismatch: file contains both GNU properties and "
741- " AArch64 build attributes sections\n GNU properties: "
742- << ((gpInfo.andFeatures >> 2 ) & 0x01 )
743- << " \n AArch64 build attributes: " << baInfo.fAndB .tagGCS ;
716+ if (baInfo.fAndB .tagBTI != (gpInfo.andFeatures & 0x01 ) ||
717+ baInfo.fAndB .tagPAC != ((gpInfo.andFeatures >> 1 ) & 0x01 ) ||
718+ baInfo.fAndB .tagGCS != ((gpInfo.andFeatures >> 2 ) & 0x01 ))
719+ ErrAlways (ctx) << tPointer
720+ << " Features Data mismatch: file contains both GNU "
721+ " properties and AArch64 build attributes sections with "
722+ " different And Features data" ;
744723 }
745724
746725 if (hasBA && !hasGP) {
747726 if (baInfo.pauth .tagPlatform || baInfo.pauth .tagSchema ) {
748- auto serializeUnsigned = [&](unsigned value, size_t offset, bool isBE) {
749- for (size_t i = 0 ; i < 8 ; ++i) {
750- tPointer->aarch64PauthAbiCoreInfoStorage [i + offset] =
751- static_cast <uint8_t >(
752- (static_cast <uint64_t >(value) >> (8 * (isBE ? (7 - i) : i))) &
753- 0xFF );
754- };
755- };
756- serializeUnsigned (baInfo.pauth .tagPlatform , 0 , isBE);
757- serializeUnsigned (baInfo.pauth .tagSchema , 8 , isBE);
727+ tPointer->aarch64PauthAbiCoreInfoStorage = serializeUnsigned (
728+ baInfo.pauth .tagPlatform , baInfo.pauth .tagSchema , isBE);
758729 tPointer->aarch64PauthAbiCoreInfo =
759730 tPointer->aarch64PauthAbiCoreInfoStorage ;
760731 }
0 commit comments