@@ -576,41 +576,6 @@ static GcsPolicy getZGcs(Ctx &ctx, opt::InputArgList &args) {
576576 return ret;
577577}
578578
579- static void getZGcsReport (Ctx &ctx, opt::InputArgList &args) {
580- bool reportDynamicDefined = false ;
581- for (auto *arg : args.filtered (OPT_z)) {
582- std::pair<StringRef, StringRef> kv = StringRef (arg->getValue ()).split (' =' );
583- if (kv.first != " gcs-report" && kv.first != " gcs-report-dynamic" )
584- continue ;
585- arg->claim ();
586- ReportPolicy value;
587- if (kv.second == " none" )
588- value = ReportPolicy::None;
589- else if (kv.second == " warning" )
590- value = ReportPolicy::Warning;
591- else if (kv.second == " error" )
592- value = ReportPolicy::Error;
593- else {
594- ErrAlways (ctx) << " unknown -z " << kv.first << " = value: " << kv.second ;
595- continue ;
596- }
597- if (kv.first == " gcs-report" ) {
598- ctx.arg .zGcsReport = value;
599- } else if (kv.first == " gcs-report-dynamic" ) {
600- ctx.arg .zGcsReportDynamic = value;
601- reportDynamicDefined = true ;
602- }
603- }
604-
605- // When -zgcs-report is set to `warning` or `error`, -zgcs-report-dynamic will
606- // inherit this value if unspecified, matching GNU ld. This detects shared
607- // libraries without the GCS property but does not the shared-libraries to be
608- // rebuilt for successful linking
609- if (!reportDynamicDefined && ctx.arg .zGcsReport != ReportPolicy::None &&
610- ctx.arg .zGcsReportDynamic == ReportPolicy::None)
611- ctx.arg .zGcsReportDynamic = ReportPolicy::Warning;
612- }
613-
614579// Report a warning for an unknown -z option.
615580static void checkZOptions (Ctx &ctx, opt::InputArgList &args) {
616581 // This function is called before getTarget(), when certain options are not
@@ -1585,7 +1550,6 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
15851550 ctx.arg .zForceBti = hasZOption (args, " force-bti" );
15861551 ctx.arg .zForceIbt = hasZOption (args, " force-ibt" );
15871552 ctx.arg .zGcs = getZGcs (ctx, args);
1588- getZGcsReport (ctx, args);
15891553 ctx.arg .zGlobal = hasZOption (args, " global" );
15901554 ctx.arg .zGnustack = getZGnuStack (args);
15911555 ctx.arg .zHazardplt = hasZOption (args, " hazardplt" );
@@ -1662,7 +1626,10 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
16621626 std::make_pair (" bti-report" , &ctx.arg .zBtiReport ),
16631627 std::make_pair (" cet-report" , &ctx.arg .zCetReport ),
16641628 std::make_pair (" execute-only-report" , &ctx.arg .zExecuteOnlyReport ),
1629+ std::make_pair (" gcs-report" , &ctx.arg .zGcsReport ),
1630+ std::make_pair (" gcs-report-dynamic" , &ctx.arg .zGcsReportDynamic ),
16651631 std::make_pair (" pauth-report" , &ctx.arg .zPauthReport )};
1632+ bool zGcsReportDynamicDefined = false ;
16661633 for (opt::Arg *arg : args.filtered (OPT_z)) {
16671634 std::pair<StringRef, StringRef> option =
16681635 StringRef (arg->getValue ()).split (' =' );
@@ -1672,18 +1639,31 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
16721639 arg->claim ();
16731640 if (option.second == " none" )
16741641 *reportArg.second = ReportPolicy::None;
1675- else if (option.second == " warning" )
1642+ else if (option.second == " warning" ) {
16761643 *reportArg.second = ReportPolicy::Warning;
1677- else if (option.second == " error" )
1644+ // To be able to match the GNU ld inheritance rules for -zgcs-report
1645+ // and -zgcs-report-dynamic, we need to know if -zgcs-report-dynamic
1646+ // has been defined by the user.
1647+ if (option.first == " gcs-report-dynamic" )
1648+ zGcsReportDynamicDefined = true ;
1649+ } else if (option.second == " error" ) {
16781650 *reportArg.second = ReportPolicy::Error;
1679- else {
1651+ if (option.first == " gcs-report-dynamic" )
1652+ zGcsReportDynamicDefined = true ;
1653+ } else {
16801654 ErrAlways (ctx) << " unknown -z " << reportArg.first
16811655 << " = value: " << option.second ;
16821656 continue ;
16831657 }
16841658 }
16851659 }
16861660
1661+ if (!zGcsReportDynamicDefined && ctx.arg .zGcsReport != ReportPolicy::None &&
1662+ ctx.arg .zGcsReportDynamic == ReportPolicy::None)
1663+ // When inheriting the -zgcs-report option, it is capped at a `warning` to
1664+ // avoid needing to rebuild the shared library with GCS enabled.
1665+ ctx.arg .zGcsReportDynamic = ReportPolicy::Warning;
1666+
16871667 for (opt::Arg *arg : args.filtered (OPT_compress_sections)) {
16881668 SmallVector<StringRef, 0 > fields;
16891669 StringRef (arg->getValue ()).split (fields, ' =' );
0 commit comments