@@ -2702,21 +2702,6 @@ static void redirectSymbols(Ctx &ctx, ArrayRef<WrappedSymbol> wrapped) {
2702
2702
ctx.symtab ->wrap (w.sym , w.real , w.wrap );
2703
2703
}
2704
2704
2705
- static void reportMissingFeature (Ctx &ctx, StringRef config,
2706
- const Twine &report) {
2707
- if (config == " error" )
2708
- ErrAlways (ctx) << report;
2709
- else if (config == " warning" )
2710
- Warn (ctx) << report;
2711
- }
2712
-
2713
- static void checkAndReportMissingFeature (Ctx &ctx, StringRef config,
2714
- uint32_t features, uint32_t mask,
2715
- const Twine &report) {
2716
- if (!(features & mask))
2717
- reportMissingFeature (ctx, config, report);
2718
- }
2719
-
2720
2705
// To enable CET (x86's hardware-assisted control flow enforcement), each
2721
2706
// source file must be compiled with -fcf-protection. Object files compiled
2722
2707
// with the flag contain feature flags indicating that they are compatible
@@ -2749,28 +2734,43 @@ static void readSecurityNotes(Ctx &ctx) {
2749
2734
bool hasValidPauthAbiCoreInfo = llvm::any_of (
2750
2735
ctx.aarch64PauthAbiCoreInfo , [](uint8_t c) { return c != 0 ; });
2751
2736
2737
+ auto report = [&](StringRef config) -> ELFSyncStream {
2738
+ if (config == " error" )
2739
+ return {ctx, DiagLevel::Err};
2740
+ else if (config == " warning" )
2741
+ return {ctx, DiagLevel::Warn};
2742
+ return {ctx, DiagLevel::None};
2743
+ };
2744
+ auto reportUnless = [&](StringRef config, bool cond) -> ELFSyncStream {
2745
+ if (cond)
2746
+ return {ctx, DiagLevel::None};
2747
+ return report (config);
2748
+ };
2752
2749
for (ELFFileBase *f : ctx.objectFiles ) {
2753
2750
uint32_t features = f->andFeatures ;
2754
2751
2755
- checkAndReportMissingFeature (
2756
- ctx, ctx.arg .zBtiReport , features, GNU_PROPERTY_AARCH64_FEATURE_1_BTI,
2757
- toStr (ctx, f) + " : -z bti-report: file does not have "
2758
- " GNU_PROPERTY_AARCH64_FEATURE_1_BTI property" );
2759
-
2760
- checkAndReportMissingFeature (
2761
- ctx, ctx.arg .zGcsReport , features, GNU_PROPERTY_AARCH64_FEATURE_1_GCS,
2762
- toStr (ctx, f) + " : -z gcs-report: file does not have "
2763
- " GNU_PROPERTY_AARCH64_FEATURE_1_GCS property" );
2764
-
2765
- checkAndReportMissingFeature (
2766
- ctx, ctx.arg .zCetReport , features, GNU_PROPERTY_X86_FEATURE_1_IBT,
2767
- toStr (ctx, f) + " : -z cet-report: file does not have "
2768
- " GNU_PROPERTY_X86_FEATURE_1_IBT property" );
2769
-
2770
- checkAndReportMissingFeature (
2771
- ctx, ctx.arg .zCetReport , features, GNU_PROPERTY_X86_FEATURE_1_SHSTK,
2772
- toStr (ctx, f) + " : -z cet-report: file does not have "
2773
- " GNU_PROPERTY_X86_FEATURE_1_SHSTK property" );
2752
+ reportUnless (ctx.arg .zBtiReport ,
2753
+ features & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)
2754
+ << f
2755
+ << " : -z bti-report: file does not have "
2756
+ " GNU_PROPERTY_AARCH64_FEATURE_1_BTI property" ;
2757
+
2758
+ reportUnless (ctx.arg .zGcsReport ,
2759
+ features & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)
2760
+ << f
2761
+ << " : -z gcs-report: file does not have "
2762
+ " GNU_PROPERTY_AARCH64_FEATURE_1_GCS property" ;
2763
+
2764
+ reportUnless (ctx.arg .zCetReport , features & GNU_PROPERTY_X86_FEATURE_1_IBT)
2765
+ << f
2766
+ << " : -z cet-report: file does not have "
2767
+ " GNU_PROPERTY_X86_FEATURE_1_IBT property" ;
2768
+
2769
+ reportUnless (ctx.arg .zCetReport ,
2770
+ features & GNU_PROPERTY_X86_FEATURE_1_SHSTK)
2771
+ << f
2772
+ << " : -z cet-report: file does not have "
2773
+ " GNU_PROPERTY_X86_FEATURE_1_SHSTK property" ;
2774
2774
2775
2775
if (ctx.arg .zForceBti && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) {
2776
2776
features |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI;
@@ -2800,11 +2800,11 @@ static void readSecurityNotes(Ctx &ctx) {
2800
2800
continue ;
2801
2801
2802
2802
if (f->aarch64PauthAbiCoreInfo .empty ()) {
2803
- reportMissingFeature (ctx, ctx .arg .zPauthReport ,
2804
- toStr (ctx, f) +
2805
- " : -z pauth-report: file does not have AArch64 "
2806
- " PAuth core info while '" +
2807
- referenceFileName + " ' has one" ) ;
2803
+ report (ctx.arg .zPauthReport )
2804
+ << f
2805
+ << " : -z pauth-report: file does not have AArch64 "
2806
+ " PAuth core info while '"
2807
+ << referenceFileName << " ' has one" ;
2808
2808
continue ;
2809
2809
}
2810
2810
0 commit comments