Skip to content

Commit 1d2db0b

Browse files
committed
Update parsing of gcs-report and gcs-report-dynamic options
This removes the new function that was originally added, and reinstates the parsing of the gcs-report option in its original location. This also enables the use of gcs-report-dynamic in the reports, with the GNU inheritance implemented.
1 parent 64e6544 commit 1d2db0b

File tree

2 files changed

+21
-42
lines changed

2 files changed

+21
-42
lines changed

lld/ELF/Driver.cpp

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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.
615580
static 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, '=');

lld/ELF/InputFiles.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1458,9 +1458,8 @@ void SharedFile::parseGnuAndFeatures(const uint8_t *base,
14581458

14591459
// Read a body of a NOTE record, which consists of type-length-value fields.
14601460
ArrayRef<uint8_t> desc = note.getDesc(headers[i].p_align);
1461-
parseGnuPropertyNote<ELFT>(
1462-
ctx, *this, /*featureAndType*/ GNU_PROPERTY_AARCH64_FEATURE_1_AND, desc,
1463-
base);
1461+
parseGnuPropertyNote<ELFT>(ctx, *this, GNU_PROPERTY_AARCH64_FEATURE_1_AND,
1462+
desc, base);
14641463
}
14651464
}
14661465

0 commit comments

Comments
 (0)