From 6d26ed92cc557ea68bb51647e92f56ea91cb2334 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 24 Oct 2018 14:24:01 +0000 Subject: [PATCH] Split a function. NFC. llvm-svn: 345143 --- lld/ELF/Writer.cpp | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/lld/ELF/Writer.cpp b/lld/ELF/Writer.cpp index 0c33b439e5f0..fe5c7e6fd457 100644 --- a/lld/ELF/Writer.cpp +++ b/lld/ELF/Writer.cpp @@ -56,6 +56,7 @@ private: void maybeAddThunks(); void sortInputSections(); void finalizeSections(); + void checkExecuteOnly(); void setReservedSymbolSections(); std::vector createPhdrs(); @@ -458,6 +459,7 @@ template void Writer::run() { // to the string table, and add entries to .got and .plt. // finalizeSections does that. finalizeSections(); + checkExecuteOnly(); if (errorCount()) return; @@ -483,10 +485,9 @@ template void Writer::run() { setPhdrs(); - if (Config->Relocatable) { + if (Config->Relocatable) for (OutputSection *Sec : OutputSections) Sec->Addr = 0; - } if (Config->CheckSections) checkSections(); @@ -1654,15 +1655,6 @@ template void Writer::finalizeSections() { if (auto *Sec = dyn_cast(Base)) OutputSections.push_back(Sec); - // Ensure data sections are not mixed with executable sections when - // -execute-only is used. - if (Config->ExecuteOnly) - for (OutputSection *OS : OutputSections) - if (OS->Flags & SHF_EXECINSTR) - for (InputSection *IS : getInputSections(OS)) - if (!(IS->Flags & SHF_EXECINSTR)) - error("-execute-only does not support intermingling data and code"); - // Prefer command line supplied address over other constraints. for (OutputSection *Sec : OutputSections) { auto I = Config->SectionStartMap.find(Sec->Name); @@ -1756,6 +1748,20 @@ template void Writer::finalizeSections() { Sec->finalize(); } +// Ensure data sections are not mixed with executable sections when +// -execute-only is used. -execute-only is a feature to make pages executable +// but not readable, and the feature is currently supported only on AArch64. +template void Writer::checkExecuteOnly() { + if (!Config->ExecuteOnly) + return; + + for (OutputSection *OS : OutputSections) + if (OS->Flags & SHF_EXECINSTR) + for (InputSection *IS : getInputSections(OS)) + if (!(IS->Flags & SHF_EXECINSTR)) + error("-execute-only does not support intermingling data and code"); +} + // The linker is expected to define SECNAME_start and SECNAME_end // symbols for a few sections. This function defines them. template void Writer::addStartEndSymbols() {