@@ -400,9 +400,9 @@ static void checkOptions(Ctx &ctx) {
400
400
ErrAlways (ctx) << " -z bti-report only supported on AArch64" ;
401
401
if (ctx.arg .zPauthReport != " none" )
402
402
ErrAlways (ctx) << " -z pauth-report only supported on AArch64" ;
403
- if (ctx.arg .zGcsReport . getValue () != GcsReportPolicy::None)
403
+ if (ctx.arg .zGcsReport != GcsReportPolicy::None)
404
404
ErrAlways (ctx) << " -z gcs-report only supported on AArch64" ;
405
- if (ctx.arg .zGcsReportDynamic . getValue () != GcsReportPolicy::None)
405
+ if (ctx.arg .zGcsReportDynamic != GcsReportPolicy::None)
406
406
ErrAlways (ctx) << " -z gcs-report-dynamic only supported on AArch64" ;
407
407
if (ctx.arg .zGcs != GcsPolicy::Implicit)
408
408
ErrAlways (ctx) << " -z gcs only supported on AArch64" ;
@@ -576,23 +576,27 @@ static GcsPolicy getZGcs(Ctx &ctx, opt::InputArgList &args) {
576
576
return ret;
577
577
}
578
578
579
- static GcsReportPolicy
580
- getZGcsReport (Ctx &ctx, opt::InputArgList &args, bool isReportDynamic,
581
- GcsReportPolicy gcsReportValue = GcsReportPolicy::None) {
582
- GcsReportPolicy ret = GcsReportPolicy::None;
579
+ static void getZGcsReport (Ctx &ctx, opt::InputArgList &args) {
580
+ bool reportDynamicDefined = false ;
583
581
584
582
for (auto *arg : args.filtered (OPT_z)) {
585
583
std::pair<StringRef, StringRef> kv = StringRef (arg->getValue ()).split (' =' );
586
- if ((!isReportDynamic && kv.first == " gcs-report" ) ||
587
- (isReportDynamic && kv.first == " gcs-report-dynamic" )) {
584
+ if ((kv.first == " gcs-report" ) || kv.first == " gcs-report-dynamic" ) {
588
585
arg->claim ();
589
- ret = StringSwitch<GcsReportPolicy>(kv.second )
590
- .Case (" none" , GcsReportPolicy::None)
591
- .Case (" warning" , GcsReportPolicy::Warning)
592
- .Case (" error" , GcsReportPolicy::Error)
593
- .Default (GcsReportPolicy::Unknown);
594
- if (ret. getValue () == GcsReportPolicy::Unknown)
586
+ GcsReportPolicy value = StringSwitch<GcsReportPolicy>(kv.second )
587
+ .Case (" none" , GcsReportPolicy::None)
588
+ .Case (" warning" , GcsReportPolicy::Warning)
589
+ .Case (" error" , GcsReportPolicy::Error)
590
+ .Default (GcsReportPolicy::Unknown);
591
+ if (value == GcsReportPolicy::Unknown)
595
592
ErrAlways (ctx) << " unknown -z " << kv.first << " = value: " << kv.second ;
593
+
594
+ if (kv.first == " gcs-report" )
595
+ ctx.arg .zGcsReport = value;
596
+ else if (kv.first == " gcs-report-dynamic" ) {
597
+ ctx.arg .zGcsReportDynamic = value;
598
+ reportDynamicDefined = true ;
599
+ }
596
600
}
597
601
}
598
602
@@ -601,11 +605,9 @@ getZGcsReport(Ctx &ctx, opt::InputArgList &args, bool isReportDynamic,
601
605
// inherit this value if there is no user set value. This detects shared
602
606
// libraries without the GCS property but does not the shared-libraries to be
603
607
// rebuilt for successful linking
604
- if (isReportDynamic && gcsReportValue.getValue () != GcsReportPolicy::None &&
605
- ret.getValue () == GcsReportPolicy::None)
606
- ret = GcsReportPolicy::Warning;
607
-
608
- return ret;
608
+ if (!reportDynamicDefined && ctx.arg .zGcsReport != GcsReportPolicy::None &&
609
+ ctx.arg .zGcsReportDynamic == GcsReportPolicy::None)
610
+ ctx.arg .zGcsReportDynamic = GcsReportPolicy::Warning;
609
611
}
610
612
611
613
// Report a warning for an unknown -z option.
@@ -1587,9 +1589,10 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
1587
1589
ctx.arg .zForceBti = hasZOption (args, " force-bti" );
1588
1590
ctx.arg .zForceIbt = hasZOption (args, " force-ibt" );
1589
1591
ctx.arg .zGcs = getZGcs (ctx, args);
1590
- ctx.arg .zGcsReport = getZGcsReport (ctx, args, /* isReportDynamic */ false );
1591
- ctx.arg .zGcsReportDynamic =
1592
- getZGcsReport (ctx, args, /* isReportDynamic */ true , ctx.arg .zGcsReport );
1592
+ // getZGcsReport assings the values for `ctx.arg.zGcsReport` and
1593
+ // `ctx.arg.zGcsReportDynamic within the function. By doing this, it saves
1594
+ // calling the function twice, as both values can be parsed at once.
1595
+ getZGcsReport (ctx, args);
1593
1596
ctx.arg .zGlobal = hasZOption (args, " global" );
1594
1597
ctx.arg .zGnustack = getZGnuStack (args);
1595
1598
ctx.arg .zHazardplt = hasZOption (args, " hazardplt" );
@@ -2877,7 +2880,7 @@ static void readSecurityNotes(Ctx &ctx) {
2877
2880
<< " : -z bti-report: file does not have "
2878
2881
" GNU_PROPERTY_AARCH64_FEATURE_1_BTI property" ;
2879
2882
2880
- reportUnless (ctx.arg .zGcsReport . toString ( ),
2883
+ reportUnless (gcsReportPolicytoString ( ctx.arg .zGcsReport ),
2881
2884
features & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)
2882
2885
<< f
2883
2886
<< " : -z gcs-report: file does not have "
@@ -2955,7 +2958,7 @@ static void readSecurityNotes(Ctx &ctx) {
2955
2958
// either `warning` or `error`.
2956
2959
if (ctx.arg .andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)
2957
2960
for (SharedFile *f : ctx.sharedFiles )
2958
- reportUnless (ctx.arg .zGcsReportDynamic . toString ( ),
2961
+ reportUnless (gcsReportPolicytoString ( ctx.arg .zGcsReportDynamic ),
2959
2962
f->andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)
2960
2963
<< f
2961
2964
<< " : GCS is required by -z gcs, but this shared library lacks the "
0 commit comments