Skip to content

Commit d12bc14

Browse files
committed
Move -z execute-only-report checking into Writer.cpp
1 parent 41472ad commit d12bc14

File tree

2 files changed

+30
-32
lines changed

2 files changed

+30
-32
lines changed

lld/ELF/Driver.cpp

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2930,36 +2930,6 @@ static void readSecurityNotes(Ctx &ctx) {
29302930
ctx.arg.andFeatures &= ~GNU_PROPERTY_AARCH64_FEATURE_1_GCS;
29312931
}
29322932

2933-
static void checkExecuteOnly(Ctx &ctx) {
2934-
if (ctx.arg.emachine != EM_AARCH64)
2935-
return;
2936-
2937-
auto reportUnless = [&](StringRef config, bool cond) -> ELFSyncStream {
2938-
if (cond)
2939-
return {ctx, DiagLevel::None};
2940-
if (config == "error")
2941-
return {ctx, DiagLevel::Err};
2942-
if (config == "warning")
2943-
return {ctx, DiagLevel::Warn};
2944-
return {ctx, DiagLevel::None};
2945-
};
2946-
2947-
for (ELFFileBase *file : ctx.objectFiles) {
2948-
for (InputSectionBase *sec : file->getSections()) {
2949-
if (!(sec && sec->flags & SHF_EXECINSTR))
2950-
continue;
2951-
2952-
OutputSection *osec = sec->getOutputSection();
2953-
if (osec && osec->name == ".text") {
2954-
reportUnless(ctx.arg.zExecuteOnlyReport,
2955-
sec->flags & SHF_AARCH64_PURECODE)
2956-
<< "-z execute-only-report: " << sec
2957-
<< " does not have SHF_AARCH64_PURECODE flag set";
2958-
}
2959-
}
2960-
}
2961-
}
2962-
29632933
static void initSectionsAndLocalSyms(ELFFileBase *file, bool ignoreComdats) {
29642934
switch (file->ekind) {
29652935
case ELF32LEKind:
@@ -3325,8 +3295,6 @@ template <class ELFT> void LinkerDriver::link(opt::InputArgList &args) {
33253295
ctx.script->addOrphanSections();
33263296
}
33273297

3328-
checkExecuteOnly(ctx);
3329-
33303298
{
33313299
llvm::TimeTraceScope timeScope("Merge/finalize input sections");
33323300

lld/ELF/Writer.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ template <class ELFT> class Writer {
6464
void sortOrphanSections();
6565
void finalizeSections();
6666
void checkExecuteOnly();
67+
void checkExecuteOnlyReport();
6768
void setReservedSymbolSections();
6869

6970
SmallVector<std::unique_ptr<PhdrEntry>, 0> createPhdrs(Partition &part);
@@ -325,6 +326,7 @@ template <class ELFT> void Writer<ELFT>::run() {
325326
// finalizeSections does that.
326327
finalizeSections();
327328
checkExecuteOnly();
329+
checkExecuteOnlyReport();
328330

329331
// If --compressed-debug-sections is specified, compress .debug_* sections.
330332
// Do it right now because it changes the size of output sections.
@@ -2179,6 +2181,34 @@ template <class ELFT> void Writer<ELFT>::checkExecuteOnly() {
21792181
"data and code";
21802182
}
21812183

2184+
// Check that all input sections of .text have the SHF_AARCH64_PURECODE section
2185+
// flag set.
2186+
template <class ELFT> void Writer<ELFT>::checkExecuteOnlyReport() {
2187+
if (ctx.arg.emachine != EM_AARCH64 || ctx.arg.zExecuteOnlyReport == "none")
2188+
return;
2189+
2190+
auto reportUnless = [&](StringRef config, bool cond) -> ELFSyncStream {
2191+
if (cond)
2192+
return {ctx, DiagLevel::None};
2193+
if (config == "error")
2194+
return {ctx, DiagLevel::Err};
2195+
if (config == "warning")
2196+
return {ctx, DiagLevel::Warn};
2197+
return {ctx, DiagLevel::None};
2198+
};
2199+
2200+
SmallVector<InputSection *, 0> storage;
2201+
for (OutputSection *osec : ctx.outputSections) {
2202+
if (osec->name != ".text")
2203+
continue;
2204+
for (InputSection *sec : getInputSections(*osec, storage))
2205+
reportUnless(ctx.arg.zExecuteOnlyReport,
2206+
sec->flags & SHF_AARCH64_PURECODE)
2207+
<< "-z execute-only-report: " << sec
2208+
<< " does not have SHF_AARCH64_PURECODE flag set";
2209+
}
2210+
}
2211+
21822212
// The linker is expected to define SECNAME_start and SECNAME_end
21832213
// symbols for a few sections. This function defines them.
21842214
template <class ELFT> void Writer<ELFT>::addStartEndSymbols() {

0 commit comments

Comments
 (0)