]> granicus.if.org Git - llvm/commitdiff
[PowerPC] Set PROT_READ flag for MF_EXEC to prevent segfaults on PPC machines
authorNemanja Ivanovic <nemanja.i.ibm@gmail.com>
Mon, 3 Jun 2019 16:20:59 +0000 (16:20 +0000)
committerNemanja Ivanovic <nemanja.i.ibm@gmail.com>
Mon, 3 Jun 2019 16:20:59 +0000 (16:20 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@362412 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/Unix/Memory.inc

index 3b0033629597a5e048a136c2bebe4c5c8b98744a..a0927da50e4871aa329ae5c69a1b5dc766830b22 100644 (file)
@@ -58,14 +58,13 @@ int getPosixProtectionFlags(unsigned Flags) {
       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;