@@ -576,41 +576,6 @@ static GcsPolicy getZGcs(Ctx &ctx, opt::InputArgList &args) {
576
576
return ret;
577
577
}
578
578
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
-
614
579
// Report a warning for an unknown -z option.
615
580
static void checkZOptions (Ctx &ctx, opt::InputArgList &args) {
616
581
// This function is called before getTarget(), when certain options are not
@@ -1585,7 +1550,6 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
1585
1550
ctx.arg .zForceBti = hasZOption (args, " force-bti" );
1586
1551
ctx.arg .zForceIbt = hasZOption (args, " force-ibt" );
1587
1552
ctx.arg .zGcs = getZGcs (ctx, args);
1588
- getZGcsReport (ctx, args);
1589
1553
ctx.arg .zGlobal = hasZOption (args, " global" );
1590
1554
ctx.arg .zGnustack = getZGnuStack (args);
1591
1555
ctx.arg .zHazardplt = hasZOption (args, " hazardplt" );
@@ -1662,7 +1626,10 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
1662
1626
std::make_pair (" bti-report" , &ctx.arg .zBtiReport ),
1663
1627
std::make_pair (" cet-report" , &ctx.arg .zCetReport ),
1664
1628
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 ),
1665
1631
std::make_pair (" pauth-report" , &ctx.arg .zPauthReport )};
1632
+ bool zGcsReportDynamicDefined = false ;
1666
1633
for (opt::Arg *arg : args.filtered (OPT_z)) {
1667
1634
std::pair<StringRef, StringRef> option =
1668
1635
StringRef (arg->getValue ()).split (' =' );
@@ -1672,18 +1639,31 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
1672
1639
arg->claim ();
1673
1640
if (option.second == " none" )
1674
1641
*reportArg.second = ReportPolicy::None;
1675
- else if (option.second == " warning" )
1642
+ else if (option.second == " warning" ) {
1676
1643
*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" ) {
1678
1650
*reportArg.second = ReportPolicy::Error;
1679
- else {
1651
+ if (option.first == " gcs-report-dynamic" )
1652
+ zGcsReportDynamicDefined = true ;
1653
+ } else {
1680
1654
ErrAlways (ctx) << " unknown -z " << reportArg.first
1681
1655
<< " = value: " << option.second ;
1682
1656
continue ;
1683
1657
}
1684
1658
}
1685
1659
}
1686
1660
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
+
1687
1667
for (opt::Arg *arg : args.filtered (OPT_compress_sections)) {
1688
1668
SmallVector<StringRef, 0 > fields;
1689
1669
StringRef (arg->getValue ()).split (fields, ' =' );
0 commit comments