Skip to content

Commit 84b665c

Browse files
committed
[AArch64][GCS] Convert -zgcs-report processing to use an Enum
To enable easier processing of inheritance for the -zgcs-report-dynamic option, the -zgcs-report option has been converted to use an Enum value to define its setting rather than a StringRef value. This adds the Enum class for defining the three options, None, Warning and Error, along with the appropirate methods for processing the users input. To enable the error messages, a new lambda function has been added. This processes the Enum value and passes the appropriate string into the `report` lambda function for the error message. Error messages have been updated where required.
1 parent 90c11ad commit 84b665c

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

lld/ELF/Driver.cpp

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,6 +574,27 @@ static GcsPolicy getZGcs(Ctx &ctx, opt::InputArgList &args) {
574574
return ret;
575575
}
576576

577+
static ReportPolicy getZGcsReport(Ctx &ctx, opt::InputArgList &args) {
578+
ReportPolicy ret = ReportPolicy::None;
579+
580+
for (auto *arg : args.filtered(OPT_z)) {
581+
std::pair<StringRef, StringRef> kv = StringRef(arg->getValue()).split('=');
582+
if (kv.first == "gcs-report") {
583+
arg->claim();
584+
if (kv.second == "none")
585+
ret = ReportPolicy::None;
586+
else if (kv.second == "warning")
587+
ret = ReportPolicy::Warning;
588+
else if (kv.second == "error")
589+
ret = ReportPolicy::Error;
590+
else
591+
ErrAlways(ctx) << "unknown -z gcs-report= value: " << kv.second;
592+
}
593+
}
594+
595+
return ret;
596+
}
597+
577598
// Report a warning for an unknown -z option.
578599
static void checkZOptions(Ctx &ctx, opt::InputArgList &args) {
579600
// This function is called before getTarget(), when certain options are not
@@ -1548,6 +1569,7 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
15481569
ctx.arg.zForceBti = hasZOption(args, "force-bti");
15491570
ctx.arg.zForceIbt = hasZOption(args, "force-ibt");
15501571
ctx.arg.zGcs = getZGcs(ctx, args);
1572+
ctx.arg.zGcsReport = getZGcsReport(ctx, args);
15511573
ctx.arg.zGlobal = hasZOption(args, "global");
15521574
ctx.arg.zGnustack = getZGnuStack(args);
15531575
ctx.arg.zHazardplt = hasZOption(args, "hazardplt");
@@ -1620,12 +1642,10 @@ static void readConfigs(Ctx &ctx, opt::InputArgList &args) {
16201642
ErrAlways(ctx) << errPrefix << pat.takeError() << ": " << kv.first;
16211643
}
16221644

1623-
auto reports = {
1624-
std::make_pair("bti-report", &ctx.arg.zBtiReport),
1625-
std::make_pair("cet-report", &ctx.arg.zCetReport),
1626-
std::make_pair("execute-only-report", &ctx.arg.zExecuteOnlyReport),
1627-
std::make_pair("gcs-report", &ctx.arg.zGcsReport),
1628-
std::make_pair("pauth-report", &ctx.arg.zPauthReport)};
1645+
auto reports = {std::make_pair("bti-report", &ctx.arg.zBtiReport),
1646+
std::make_pair("cet-report", &ctx.arg.zCetReport),
1647+
std::make_pair("execute-only-report", &ctx.arg.zExecuteOnlyReport),
1648+
std::make_pair("pauth-report", &ctx.arg.zPauthReport)};
16291649
for (opt::Arg *arg : args.filtered(OPT_z)) {
16301650
std::pair<StringRef, StringRef> option =
16311651
StringRef(arg->getValue()).split('=');

lld/test/ELF/aarch64-feature-gcs.s

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,11 @@
5454

5555
# INVALID: error: unknown -z gcs= value: nonsense
5656

57+
## An invalid gcs option should give an error
58+
# RUN: not ld.lld func1-gcs.o func2-gcs.o func3-gcs.o -z gcs-report=nonsense 2>&1 | FileCheck --check-prefix=INVALID-GCS-REPORT %s
59+
60+
# INVALID-GCS-REPORT: error: unknown -z gcs-report= value: nonsense
61+
5762
#--- func1-gcs.s
5863
.section ".note.gnu.property", "a"
5964
.long 4

0 commit comments

Comments
 (0)