This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix check-execstack test


2010-12-28  Andreas Schwab  <schwab@linux-m68k.org>

	* elf/Makefile (check-execstack): Revert last change.  Depend on
	check-execstack.h.
	(check-execstack.h): New target.
	(generated): Add check-execstack.h.
	* elf/check-execstack.c: Include "check-execstack.h".
	(main): Revert last change.
	(handle_file): Return zero if GNU_STACK is absent and
	DEFAULT_STACK_PERMS doesn't include PF_X.
---
 elf/Makefile          |   18 ++++++++++--------
 elf/check-execstack.c |   20 ++++++++++----------
 2 files changed, 20 insertions(+), 18 deletions(-)

diff --git a/elf/Makefile b/elf/Makefile
index 9f38b94..75a7436 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -900,15 +900,17 @@ check-textrel-CFLAGS = -O -Wall -D_XOPEN_SOURCE=600 -D_BSD_SOURCE
 $(objpfx)check-textrel: check-textrel.c
 	$(native-compile)
 
-check-execstack-CFLAGS = -O -Wall -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -std=gnu99
-# Perform the same operation as $(native-compile) but add the sysdeps
-# directories as header search locations.
-$(objpfx)check-execstack: check-execstack.c
+check-execstack-CFLAGS = -O -Wall -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -std=gnu99 \
+			 $(objpfx:%/=-I%)
+$(objpfx)check-execstack: check-execstack.c $(objpfx)check-execstack.h
+	$(native-compile)
+$(objpfx)check-execstack.h: $(first-word $(wildcard $(sysdirs:%=%/stackinfo.h)))
 	$(make-target-directory)
-	$(patsubst %/,cd % &&,$(objpfx)) \
-	$(BUILD_CC) $($(basename $(<F))-CFLAGS) $(ALL_BUILD_CFLAGS) \
-	$(addprefix -I$(shell pwd)/,$(sysdirs)) -I$(shell pwd) \
-	$(firstword $(filter /%,$< $(shell pwd)/$<)) -o $(@F)
+	{ echo '#include <stackinfo.h>'; echo '@@@DEFAULT_STACK_PERMS@@@'; } | \
+	$(CC) $(CFLAGS) $(CPPFLAGS) -E -x c-header - | \
+	sed -n -e 's/^@@@\(.*\)@@@/#define DEFAULT_STACK_PERMS \1/p' > $@T
+	mv -f $@T $@
+generated += check-execstack.h
 
 check-localplt-CFLAGS = -O -Wall -D_GNU_SOURCE -std=gnu99
 $(objpfx)check-localplt: check-localplt.c
diff --git a/elf/check-execstack.c b/elf/check-execstack.c
index 6435375..96e4812 100644
--- a/elf/check-execstack.c
+++ b/elf/check-execstack.c
@@ -26,7 +26,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
-#include <stackinfo.h>
+#include "check-execstack.h"
 
 
 #ifdef BITS
@@ -92,8 +92,13 @@ AB(handle_file) (const char *fname, int fd)
 	return 0;
       }
 
-  printf ("%s: no PT_GNU_STACK entry\n", fname);
-  return 1;
+  if (DEFAULT_STACK_PERMS & PF_X)
+    {
+      printf ("%s: no PT_GNU_STACK entry\n", fname);
+      return 1;
+    }
+
+  return 0;
 }
 
 # undef BITS
@@ -151,13 +156,8 @@ main (int argc, char *argv[])
   int cnt;
   int result = 0;
 
-  /* We can return successfully, i.e., not fail, if PF_X isn't present.  If it
-   * is present then check for the GNU_STACK header.  */
-  if (DEFAULT_STACK_PERMS & PF_X)
-    {
-      for (cnt = 1; cnt < argc; ++cnt)
-	result |= handle_file (argv[cnt]);
-     }
+  for (cnt = 1; cnt < argc; ++cnt)
+    result |= handle_file (argv[cnt]);
   return result;
 }
 #endif
-- 
1.7.3.4


-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]