[llvm] r362412 - [PowerPC] Set PROT_READ flag for MF_EXEC to prevent segfaults on PPC machines

Nemanja Ivanovic via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 3 09:20:59 PDT 2019


Author: nemanjai
Date: Mon Jun  3 09:20:59 2019
New Revision: 362412

URL: http://llvm.org/viewvc/llvm-project?rev=362412&view=rev
Log:
[PowerPC] Set PROT_READ flag for MF_EXEC to prevent segfaults on PPC machines

The big endian PPC buildbots are all failing now due to calls to cache
invalidation in unit tests on data that has only the PROT_EXEC flag set.
This has been an issue all along on FreeBSD but it can affect Linux machines
depending on configuration.

This patch mitigates the issue the same way it is mitigated on FreeBSD.

Since this is needed to bring the buildbots back to green, I plan to commit this
and allow for post-commit review, but I thought I would also post it here for
ease of access/readability.

Differential revision: https://reviews.llvm.org/D62741

Modified:
    llvm/trunk/lib/Support/Unix/Memory.inc

Modified: llvm/trunk/lib/Support/Unix/Memory.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Memory.inc?rev=362412&r1=362411&r2=362412&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Memory.inc (original)
+++ llvm/trunk/lib/Support/Unix/Memory.inc Mon Jun  3 09:20:59 2019
@@ -58,14 +58,13 @@ int getPosixProtectionFlags(unsigned Fla
       llvm::sys::Memory::MF_EXEC:
     return PROT_READ | PROT_WRITE | PROT_EXEC;
   case llvm::sys::Memory::MF_EXEC:
-#if defined(__FreeBSD__)
+#if (defined(__FreeBSD__) || defined(__POWERPC__) || defined (__ppc__) || \
+     defined(_POWER) || defined(_ARCH_PPC))
     // On PowerPC, having an executable page that has no read permission
     // can have unintended consequences.  The function InvalidateInstruction-
     // Cache uses instructions dcbf and icbi, both of which are treated by
     // the processor as loads.  If the page has no read permissions,
     // executing these instructions will result in a segmentation fault.
-    // Somehow, this problem is not present on Linux, but it does happen
-    // on FreeBSD.
     return PROT_READ | PROT_EXEC;
 #else
     return PROT_EXEC;




More information about the llvm-commits mailing list