Skip to content

Commit eb4d2f2

Browse files
committed
[ELF] Simplify reportMissingFeature. NFC
1 parent 68a48ec commit eb4d2f2

File tree

3 files changed

+42
-40
lines changed

3 files changed

+42
-40
lines changed

lld/Common/ErrorHandler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,8 @@ void ErrorHandler::fatal(const Twine &msg) {
339339
SyncStream::~SyncStream() {
340340
os.flush();
341341
switch (level) {
342+
case DiagLevel::None:
343+
break;
342344
case DiagLevel::Log:
343345
e.log(buf);
344346
break;

lld/ELF/Driver.cpp

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2702,21 +2702,6 @@ static void redirectSymbols(Ctx &ctx, ArrayRef<WrappedSymbol> wrapped) {
27022702
ctx.symtab->wrap(w.sym, w.real, w.wrap);
27032703
}
27042704

2705-
static void reportMissingFeature(Ctx &ctx, StringRef config,
2706-
const Twine &report) {
2707-
if (config == "error")
2708-
ErrAlways(ctx) << report;
2709-
else if (config == "warning")
2710-
Warn(ctx) << report;
2711-
}
2712-
2713-
static void checkAndReportMissingFeature(Ctx &ctx, StringRef config,
2714-
uint32_t features, uint32_t mask,
2715-
const Twine &report) {
2716-
if (!(features & mask))
2717-
reportMissingFeature(ctx, config, report);
2718-
}
2719-
27202705
// To enable CET (x86's hardware-assisted control flow enforcement), each
27212706
// source file must be compiled with -fcf-protection. Object files compiled
27222707
// with the flag contain feature flags indicating that they are compatible
@@ -2749,28 +2734,43 @@ static void readSecurityNotes(Ctx &ctx) {
27492734
bool hasValidPauthAbiCoreInfo = llvm::any_of(
27502735
ctx.aarch64PauthAbiCoreInfo, [](uint8_t c) { return c != 0; });
27512736

2737+
auto report = [&](StringRef config) -> ELFSyncStream {
2738+
if (config == "error")
2739+
return {ctx, DiagLevel::Err};
2740+
else if (config == "warning")
2741+
return {ctx, DiagLevel::Warn};
2742+
return {ctx, DiagLevel::None};
2743+
};
2744+
auto reportUnless = [&](StringRef config, bool cond) -> ELFSyncStream {
2745+
if (cond)
2746+
return {ctx, DiagLevel::None};
2747+
return report(config);
2748+
};
27522749
for (ELFFileBase *f : ctx.objectFiles) {
27532750
uint32_t features = f->andFeatures;
27542751

2755-
checkAndReportMissingFeature(
2756-
ctx, ctx.arg.zBtiReport, features, GNU_PROPERTY_AARCH64_FEATURE_1_BTI,
2757-
toStr(ctx, f) + ": -z bti-report: file does not have "
2758-
"GNU_PROPERTY_AARCH64_FEATURE_1_BTI property");
2759-
2760-
checkAndReportMissingFeature(
2761-
ctx, ctx.arg.zGcsReport, features, GNU_PROPERTY_AARCH64_FEATURE_1_GCS,
2762-
toStr(ctx, f) + ": -z gcs-report: file does not have "
2763-
"GNU_PROPERTY_AARCH64_FEATURE_1_GCS property");
2764-
2765-
checkAndReportMissingFeature(
2766-
ctx, ctx.arg.zCetReport, features, GNU_PROPERTY_X86_FEATURE_1_IBT,
2767-
toStr(ctx, f) + ": -z cet-report: file does not have "
2768-
"GNU_PROPERTY_X86_FEATURE_1_IBT property");
2769-
2770-
checkAndReportMissingFeature(
2771-
ctx, ctx.arg.zCetReport, features, GNU_PROPERTY_X86_FEATURE_1_SHSTK,
2772-
toStr(ctx, f) + ": -z cet-report: file does not have "
2773-
"GNU_PROPERTY_X86_FEATURE_1_SHSTK property");
2752+
reportUnless(ctx.arg.zBtiReport,
2753+
features & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)
2754+
<< f
2755+
<< ": -z bti-report: file does not have "
2756+
"GNU_PROPERTY_AARCH64_FEATURE_1_BTI property";
2757+
2758+
reportUnless(ctx.arg.zGcsReport,
2759+
features & GNU_PROPERTY_AARCH64_FEATURE_1_GCS)
2760+
<< f
2761+
<< ": -z gcs-report: file does not have "
2762+
"GNU_PROPERTY_AARCH64_FEATURE_1_GCS property";
2763+
2764+
reportUnless(ctx.arg.zCetReport, features & GNU_PROPERTY_X86_FEATURE_1_IBT)
2765+
<< f
2766+
<< ": -z cet-report: file does not have "
2767+
"GNU_PROPERTY_X86_FEATURE_1_IBT property";
2768+
2769+
reportUnless(ctx.arg.zCetReport,
2770+
features & GNU_PROPERTY_X86_FEATURE_1_SHSTK)
2771+
<< f
2772+
<< ": -z cet-report: file does not have "
2773+
"GNU_PROPERTY_X86_FEATURE_1_SHSTK property";
27742774

27752775
if (ctx.arg.zForceBti && !(features & GNU_PROPERTY_AARCH64_FEATURE_1_BTI)) {
27762776
features |= GNU_PROPERTY_AARCH64_FEATURE_1_BTI;
@@ -2800,11 +2800,11 @@ static void readSecurityNotes(Ctx &ctx) {
28002800
continue;
28012801

28022802
if (f->aarch64PauthAbiCoreInfo.empty()) {
2803-
reportMissingFeature(ctx, ctx.arg.zPauthReport,
2804-
toStr(ctx, f) +
2805-
": -z pauth-report: file does not have AArch64 "
2806-
"PAuth core info while '" +
2807-
referenceFileName + "' has one");
2803+
report(ctx.arg.zPauthReport)
2804+
<< f
2805+
<< ": -z pauth-report: file does not have AArch64 "
2806+
"PAuth core info while '"
2807+
<< referenceFileName << "' has one";
28082808
continue;
28092809
}
28102810

lld/include/lld/Common/ErrorHandler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void message(const Twine &msg, llvm::raw_ostream &s = outs());
151151
void warn(const Twine &msg);
152152
uint64_t errorCount();
153153

154-
enum class DiagLevel { Log, Msg, Warn, Err, Fatal };
154+
enum class DiagLevel { None, Log, Msg, Warn, Err, Fatal };
155155

156156
// A class that synchronizes thread writing to the same stream similar
157157
// std::osyncstream.

0 commit comments

Comments
 (0)