[llvm] e9b394b - [JITLink][ELF] Only make sections with SHF_WRITE writable

Job Noorman via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 3 11:19:08 PDT 2023


Author: Job Noorman
Date: 2023-04-03T20:18:27+02:00
New Revision: e9b394b08eb6db5aa225441cf3fb9d4380ff4533

URL: https://github.com/llvm/llvm-project/commit/e9b394b08eb6db5aa225441cf3fb9d4380ff4533
DIFF: https://github.com/llvm/llvm-project/commit/e9b394b08eb6db5aa225441cf3fb9d4380ff4533.diff

LOG: [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

Added: 
    

Modified: 
    llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h

Removed: 
    


################################################################################
diff  --git a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h
index 1d98acf868695..c1f69d0bf5698 100644
--- a/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h
+++ b/llvm/lib/ExecutionEngine/JITLink/ELFLinkGraphBuilder.h
@@ -360,11 +360,11 @@ template <typename ELFT> Error ELFLinkGraphBuilder<ELFT>::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);


        


More information about the llvm-commits mailing list