From e9b394b08eb6db5aa225441cf3fb9d4380ff4533 Mon Sep 17 00:00:00 2001 From: Job Noorman Date: Mon, 3 Apr 2023 20:18:19 +0200 Subject: [PATCH] [JITLink][ELF] Only make sections with SHF_WRITE writable All non-executable sections used to be mapped as RW- causing read-only sections such as .rodata to be writable. Reviewed By: lhames Differential Revision: https://reviews.llvm.org/D147442 --- llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h index 1d98acf..c1f69d0 100644 --- a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h +++ b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h @@ -360,11 +360,11 @@ template Error ELFLinkGraphBuilder::graphifySections() { }); // Get the section's memory protection flags. - orc::MemProt Prot; + orc::MemProt Prot = orc::MemProt::Read; if (Sec.sh_flags & ELF::SHF_EXECINSTR) - Prot = orc::MemProt::Read | orc::MemProt::Exec; - else - Prot = orc::MemProt::Read | orc::MemProt::Write; + Prot |= orc::MemProt::Exec; + if (Sec.sh_flags & ELF::SHF_WRITE) + Prot |= orc::MemProt::Write; // Look for existing sections first. auto *GraphSec = G->findSectionByName(*Name); -- 2.7.4