about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--elf/dl-load.c36
1 files changed, 12 insertions, 24 deletions
diff --git a/elf/dl-load.c b/elf/dl-load.c
index fe552e8721..0bc01eca20 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -131,18 +131,6 @@ static const struct r_strlenpair *capstr;
 static size_t ncapstr;
 static size_t max_capstrlen;
 
-const unsigned char _dl_pf_to_prot[8] =
-{
-  [0] = PROT_NONE,
-  [PF_R] = PROT_READ,
-  [PF_W] = PROT_WRITE,
-  [PF_R | PF_W] = PROT_READ | PROT_WRITE,
-  [PF_X] = PROT_EXEC,
-  [PF_R | PF_X] = PROT_READ | PROT_EXEC,
-  [PF_W | PF_X] = PROT_WRITE | PROT_EXEC,
-  [PF_R | PF_W | PF_X] = PROT_READ | PROT_WRITE | PROT_EXEC
-};
-
 
 /* Get the generated information about the trusted directories.  */
 #include "trusted-dirs.h"
@@ -926,18 +914,18 @@ _dl_map_object_from_fd (const char *name, int fd, struct filebuf *fbp,
 	    c->mapoff = ph->p_offset & ~(ph->p_align - 1);
 
 	    /* Optimize a common case.  */
-	    if ((PF_R | PF_W | PF_X) == 7)
-	      c->prot = _dl_pf_to_prot[ph->p_flags & (PF_R | PF_W | PF_X)];
-	    else
-	      {
-		c->prot = 0;
-		if (ph->p_flags & PF_R)
-		  c->prot |= PROT_READ;
-		if (ph->p_flags & PF_W)
-		  c->prot |= PROT_WRITE;
-		if (ph->p_flags & PF_X)
-		  c->prot |= PROT_EXEC;
-	      }
+#if (PF_R | PF_W | PF_X) == 7 && (PROT_READ | PROT_WRITE | PROT_EXEC) == 7
+	    c->prot = (PF_TO_PROT
+		       >> ((ph->p_flags & (PF_R | PF_W | PF_X)) * 4)) & 0xf;
+#else
+	    c->prot = 0;
+	    if (ph->p_flags & PF_R)
+	      c->prot |= PROT_READ;
+	    if (ph->p_flags & PF_W)
+	      c->prot |= PROT_WRITE;
+	    if (ph->p_flags & PF_X)
+	      c->prot |= PROT_EXEC;
+#endif
 	  }
 	  break;
 	}