@@ -400,9 +400,9 @@ static void checkOptions(Ctx &ctx) {
400400 ErrAlways (ctx) << " -z bti-report only supported on AArch64" ;
401401 if (ctx.arg .zPauthReport != " none" )
402402 ErrAlways (ctx) << " -z pauth-report only supported on AArch64" ;
403- if (ctx.arg .zGcsReport . getValue () != GcsReportPolicy::None)
403+ if (ctx.arg .zGcsReport != GcsReportPolicy::None)
404404 ErrAlways (ctx) << " -z gcs-report only supported on AArch64" ;
405- if (ctx.arg .zGcsReportDynamic . getValue () != GcsReportPolicy::None)
405+ if (ctx.arg .zGcsReportDynamic != GcsReportPolicy::None)
406406 ErrAlways (ctx) << " -z gcs-report-dynamic only supported on AArch64" ;
407407 if (ctx.arg .zGcs != GcsPolicy::Implicit)
408408 ErrAlways (ctx) << " -z gcs only supported on AArch64" ;
@@ -576,23 +576,27 @@ static GcsPolicy getZGcs(Ctx &ctx, opt::InputArgList &args) {
576576 return ret;
577577}
578578
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 ;
583581
584582 for (auto *arg : args.filtered (OPT_z)) {
585583 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" ) {
588585 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)
595592 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+ }
596600 }
597601 }
598602
@@ -601,11 +605,9 @@ getZGcsReport(Ctx &ctx, opt::InputArgList &args, bool isReportDynamic,
601605 // inherit this value if there is no user set value. This detects shared
602606 // libraries without the GCS property but does not the shared-libraries to be
603607 // 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;
609611}
610612
611613// Report a warning for an unknown -z option.
@@ -1587,9 +1589,10 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
15871589 ctx.arg .zForceBti = hasZOption (args, " force-bti" );
15881590 ctx.arg .zForceIbt = hasZOption (args, " force-ibt" );
15891591 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);
15931596 ctx.arg .zGlobal = hasZOption (args, " global" );
15941597 ctx.arg .zGnustack = getZGnuStack (args);
15951598 ctx.arg .zHazardplt = hasZOption (args, " hazardplt" );
@@ -2877,7 +2880,7 @@ static void readSecurityNotes(Ctx &ctx) {
28772880 << " : -z bti-report: file does not have "
28782881 " GNU_PROPERTY_AARCH64_FEATURE_1_BTI property" ;
28792882
2880- reportUnless (ctx.arg .zGcsReport . toString ( ),
2883+ reportUnless (gcsReportPolicytoString ( ctx.arg .zGcsReport ),
28812884 features & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)
28822885 << f
28832886 << " : -z gcs-report: file does not have "
@@ -2955,7 +2958,7 @@ static void readSecurityNotes(Ctx &ctx) {
29552958 // either `warning` or `error`.
29562959 if (ctx.arg .andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)
29572960 for (SharedFile *f : ctx.sharedFiles )
2958- reportUnless (ctx.arg .zGcsReportDynamic . toString ( ),
2961+ reportUnless (gcsReportPolicytoString ( ctx.arg .zGcsReportDynamic ),
29592962 f->andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)
29602963 << f
29612964 << " : GCS is required by -z gcs, but this shared library lacks the "
0 commit comments