Skip to content

Commit 829fa35

Browse files
committed
[LLD] Add force enable Zicfiss/Zicfilip(CFI extension) option
1 parent 3354b7a commit 829fa35

File tree

2 files changed

+46
-2
lines changed

2 files changed

+46
-2
lines changed

lld/ELF/Config.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ struct Config {
187187
llvm::StringRef cmseOutputLib;
188188
StringRef zBtiReport = "none";
189189
StringRef zCetReport = "none";
190+
llvm::StringRef zZicfilpReport = "none";
191+
llvm::StringRef zZicfissReport = "none";
190192
llvm::StringRef ltoBasicBlockSections;
191193
std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
192194
llvm::StringRef thinLTOPrefixReplaceOld;
@@ -323,6 +325,8 @@ struct Config {
323325
bool zText;
324326
bool zRetpolineplt;
325327
bool zWxneeded;
328+
bool zForceZicfilp;
329+
bool zForceZicfiss;
326330
DiscardPolicy discard;
327331
GnuStackKind zGnustack;
328332
ICFLevel icf;

lld/ELF/Driver.cpp

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,13 @@ static void checkOptions() {
461461
error("-z bti-report only supported on AArch64");
462462
}
463463

464+
if (config->emachine != EM_RISCV) {
465+
if (config->zZicfilpReport != "none")
466+
error("-z zicfilip-report only support on RISCV32/RISCV64");
467+
if (config->zZicfissReport != "none")
468+
error("-z zicfiss-report only support on RISCV32/RISCV64");
469+
}
470+
464471
if (config->emachine != EM_386 && config->emachine != EM_X86_64 &&
465472
config->zCetReport != "none")
466473
error("-z cet-report only supported on X86 and X86_64");
@@ -586,7 +593,8 @@ static bool isKnownZFlag(StringRef s) {
586593
s.starts_with("cet-report=") ||
587594
s.starts_with("dead-reloc-in-nonalloc=") ||
588595
s.starts_with("max-page-size=") || s.starts_with("stack-size=") ||
589-
s.starts_with("start-stop-visibility=");
596+
s.starts_with("start-stop-visibility=") ||
597+
s.starts_with("zicfilp-report=") || s.starts_with("zicfiss-report=");
590598
}
591599

592600
// Report a warning for an unknown -z option.
@@ -1472,6 +1480,8 @@ static void readConfigs(opt::InputArgList &args) {
14721480
config->zWxneeded = hasZOption(args, "wxneeded");
14731481
setUnresolvedSymbolPolicy(args);
14741482
config->power10Stubs = args.getLastArgValue(OPT_power10_stubs_eq) != "no";
1483+
config->zForceZicfilp = hasZOption(args, "force-zicfilp");
1484+
config->zForceZicfiss = hasZOption(args, "force-zicfiss");
14751485

14761486
if (opt::Arg *arg = args.getLastArg(OPT_eb, OPT_el)) {
14771487
if (arg->getOption().matches(OPT_eb))
@@ -1514,7 +1524,9 @@ static void readConfigs(opt::InputArgList &args) {
15141524
}
15151525

15161526
auto reports = {std::make_pair("bti-report", &config->zBtiReport),
1517-
std::make_pair("cet-report", &config->zCetReport)};
1527+
std::make_pair("cet-report", &config->zCetReport),
1528+
std::make_pair("zicfilp-report", &config->zZicfilpReport),
1529+
std::make_pair("zicfiss-report", &config->zZicfissReport)};
15181530
for (opt::Arg *arg : args.filtered(OPT_z)) {
15191531
std::pair<StringRef, StringRef> option =
15201532
StringRef(arg->getValue()).split('=');
@@ -2593,6 +2605,7 @@ static uint32_t getAndFeatures() {
25932605
config->emachine != EM_AARCH64 && config->emachine != EM_RISCV)
25942606
return 0;
25952607

2608+
// TODO For RISCV need force optoin and report option
25962609
uint32_t ret = -1;
25972610
for (ELFFileBase *f : ctx.objectFiles) {
25982611
uint32_t features = f->andFeatures;
@@ -2612,6 +2625,16 @@ static uint32_t getAndFeatures() {
26122625
toString(f) + ": -z cet-report: file does not have "
26132626
"GNU_PROPERTY_X86_FEATURE_1_SHSTK property");
26142627

2628+
checkAndReportMissingFeature(
2629+
config->zZicfilpReport, features, GNU_PROPERTY_RISCV_FEATURE_1_ZICFILP,
2630+
toString(f) + ": -z zicfilp-report: file does not have "
2631+
"GNU_PROPERTY_RISCV_FEATURE_1_ZICFILP property");
2632+
2633+
checkAndReportMissingFeature(
2634+
config->zZicfissReport, features, GNU_PROPERTY_RISCV_FEATURE_1_ZICFISS,
2635+
toString(f) + ": -z zicfiss-report: file does not have "
2636+
"GNU_PROPERTY_RISCV_FEATURE_1_ZICFISS property");
2637+
26152638
if (config->zForceBti && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) {
26162639
features |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI;
26172640
if (config->zBtiReport == "none")
@@ -2624,6 +2647,23 @@ static uint32_t getAndFeatures() {
26242647
"GNU_PROPERTY_X86_FEATURE_1_IBT property");
26252648
features |= GNU_PROPERTY_X86_FEATURE_1_IBT;
26262649
}
2650+
2651+
if (config->zForceZicfilp &&
2652+
!(features & GNU_PROPERTY_RISCV_FEATURE_1_ZICFILP)) {
2653+
features |= GNU_PROPERTY_RISCV_FEATURE_1_ZICFILP;
2654+
if (config->zZicfilpReport == "none")
2655+
warn(toString(f) + ": -z force-zicfilp: file does not have "
2656+
"GNU_PROPERTY_RISCV_FEATURE_1_ZICFILP property");
2657+
}
2658+
2659+
if (config->zForceZicfiss &&
2660+
!(features & GNU_PROPERTY_RISCV_FEATURE_1_ZICFISS)) {
2661+
features |= GNU_PROPERTY_RISCV_FEATURE_1_ZICFISS;
2662+
if (config->zZicfissReport == "none")
2663+
warn(toString(f) + ": -z force-zicfiss: file does not have "
2664+
"GNU_PROPERTY_RISCV_FEATURE_1_ZICFISS property");
2665+
}
2666+
26272667
if (config->zPacPlt && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_PAC)) {
26282668
warn(toString(f) + ": -z pac-plt: file does not have "
26292669
"GNU_PROPERTY_AARCH64_FEATURE_1_PAC property");

0 commit comments

Comments
 (0)