From f6f944e77f741861e641e1dd46c30dcbaf8c83b7 Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Mon, 16 Oct 2023 21:00:13 +0200 Subject: [PATCH] [lld][NFC] Factor out isCodeSection helper. (#69193) --- lld/COFF/Writer.cpp | 6 +----- lld/COFF/Writer.h | 6 ++++++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lld/COFF/Writer.cpp b/lld/COFF/Writer.cpp index 4f6c2a57f533..d4f6ee6fde49 100644 --- a/lld/COFF/Writer.cpp +++ b/lld/COFF/Writer.cpp @@ -1403,11 +1403,7 @@ void Writer::assignAddresses() { // If /FUNCTIONPADMIN is used, functions are padded in order to create a // hotpatchable image. - const bool isCodeSection = - (sec->header.Characteristics & IMAGE_SCN_CNT_CODE) && - (sec->header.Characteristics & IMAGE_SCN_MEM_READ) && - (sec->header.Characteristics & IMAGE_SCN_MEM_EXECUTE); - uint32_t padding = isCodeSection ? config->functionPadMin : 0; + uint32_t padding = sec->isCodeSection() ? config->functionPadMin : 0; for (Chunk *c : sec->chunks) { if (padding && c->isHotPatchable()) diff --git a/lld/COFF/Writer.h b/lld/COFF/Writer.h index 4a74aa7ada59..9004bb310d07 100644 --- a/lld/COFF/Writer.h +++ b/lld/COFF/Writer.h @@ -64,6 +64,12 @@ public: // Used only when the name is longer than 8 bytes. void setStringTableOff(uint32_t v) { stringTableOff = v; } + bool isCodeSection() const { + return (header.Characteristics & llvm::COFF::IMAGE_SCN_CNT_CODE) && + (header.Characteristics & llvm::COFF::IMAGE_SCN_MEM_READ) && + (header.Characteristics & llvm::COFF::IMAGE_SCN_MEM_EXECUTE); + } + // N.B. The section index is one based. uint32_t sectionIndex = 0;