@@ -64,6 +64,7 @@ template <class ELFT> class Writer {
64
64
void sortOrphanSections ();
65
65
void finalizeSections ();
66
66
void checkExecuteOnly ();
67
+ void checkExecuteOnlyReport ();
67
68
void setReservedSymbolSections ();
68
69
69
70
SmallVector<std::unique_ptr<PhdrEntry>, 0 > createPhdrs (Partition &part);
@@ -325,6 +326,7 @@ template <class ELFT> void Writer<ELFT>::run() {
325
326
// finalizeSections does that.
326
327
finalizeSections ();
327
328
checkExecuteOnly ();
329
+ checkExecuteOnlyReport ();
328
330
329
331
// If --compressed-debug-sections is specified, compress .debug_* sections.
330
332
// Do it right now because it changes the size of output sections.
@@ -2179,6 +2181,34 @@ template <class ELFT> void Writer<ELFT>::checkExecuteOnly() {
2179
2181
" data and code" ;
2180
2182
}
2181
2183
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
+
2182
2212
// The linker is expected to define SECNAME_start and SECNAME_end
2183
2213
// symbols for a few sections. This function defines them.
2184
2214
template <class ELFT > void Writer<ELFT>::addStartEndSymbols() {
0 commit comments