diff options
-rw-r--r-- | ChangeLog | 18 | ||||
-rw-r--r-- | Makeconfig | 3 | ||||
-rw-r--r-- | nptl/ChangeLog | 11 | ||||
-rw-r--r-- | nptl/Makefile | 1 | ||||
-rw-r--r-- | nptl/cond-perf.c | 7 | ||||
-rw-r--r-- | nptl/pthread_attr_init.c | 6 | ||||
-rw-r--r-- | nptl/tst-align.c | 20 | ||||
-rw-r--r-- | stdlib/Makefile | 2 | ||||
-rw-r--r-- | stdlib/tst-bsearch.c | 18 | ||||
-rw-r--r-- | sysdeps/generic/tst-stack-align.h | 35 | ||||
-rw-r--r-- | sysdeps/i386/Makefile | 35 | ||||
-rw-r--r-- | sysdeps/i386/i686/Makefile | 3 | ||||
-rw-r--r-- | sysdeps/i386/i686/tst-stack-align.h | 45 |
13 files changed, 179 insertions, 25 deletions
diff --git a/ChangeLog b/ChangeLog index cda4f87fea..1c28bf2477 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2003-09-15 Jakub Jelinek <jakub@redhat.com> + + * sysdeps/i386/Makefile (sysdep-CFLAGS): If not in math or csu + subdir, add -mpreferred-stack-boundary=4, with few exceptions. + +2003-09-17 Jakub Jelinek <jakub@redhat.com> + + * Makeconfig (stack-align-test-flags): Set. + * stdlib/Makefile (CFLAGS-tst-bsearch.c): Add + $(stack-align-test-flags). + * stdlib/tst-bsearch.c: Include tst-stack-align.h. + (align_check): New var. + (comp): Use TEST_STACK_ALIGN macro. + (do_test): Fail if align_check != 1. + * sysdeps/generic/tst-stack-align.h: New file. + * sysdeps/i386/i686/Makefile (stack-align-test-flags): Add -msse. + * sysdeps/i386/i686/tst-stack-align.h: New file. + 2003-09-17 Ulrich Drepper <drepper@redhat.com> * sysdeps/unix/sysv/linux/i386/clone.S: Make sure child gets a diff --git a/Makeconfig b/Makeconfig index 36671db665..8035572b79 100644 --- a/Makeconfig +++ b/Makeconfig @@ -86,6 +86,9 @@ include $(common-objpfx)config.make # What flags to give to sources which call user provided callbacks uses-callbacks = $(exceptions) +# What flags to give to tests which test stack alignment +stack-align-test-flags = + # We have a special subdir for each binary format. # For now, only ELF is fully supported. ifeq ($(elf),yes) diff --git a/nptl/ChangeLog b/nptl/ChangeLog index 2491cd990e..0983e0be21 100644 --- a/nptl/ChangeLog +++ b/nptl/ChangeLog @@ -1,3 +1,14 @@ +2003-09-17 Jakub Jelinek <jakub@redhat.com> + + * Makefile (CFLAGS-tst-align.c): Add $(stack-align-test-flags). + * tst-align.c: Include tst-stack-align.h. + (tf, do_test): Use TEST_STACK_ALIGN macro. + +2003-09-17 Ulrich Drepper <drepper@redhat.com> + + * pthread_attr_init.c (__pthread_attr_init_2_0): Remove unused + variable. + 2003-09-16 Ulrich Drepper <drepper@redhat.com> * pthread_getattr_np.c (pthread_getattr_np): Correctly fill in the diff --git a/nptl/Makefile b/nptl/Makefile index fb0f0a6b59..7876331e52 100644 --- a/nptl/Makefile +++ b/nptl/Makefile @@ -393,6 +393,7 @@ CFLAGS-tst-cleanupx2.c += -fexceptions CFLAGS-tst-cleanupx3.c += -fexceptions CFLAGS-tst-oncex3.c += -fexceptions CFLAGS-tst-oncex4.c += -fexceptions +CFLAGS-tst-align.c += $(stack-align-test-flags) tst-cancel7-ARGS = --command "$(built-program-cmd)" tst-umask1-ARGS = $(objpfx)tst-umask1.temp diff --git a/nptl/cond-perf.c b/nptl/cond-perf.c index 53d85637b8..e37914e6b7 100644 --- a/nptl/cond-perf.c +++ b/nptl/cond-perf.c @@ -4,6 +4,7 @@ #include <stdlib.h> #include <string.h> #include <unistd.h> +#include <atomic.h> static pthread_cond_t cond1 = PTHREAD_COND_INITIALIZER; static pthread_mutex_t mut1 = PTHREAD_MUTEX_INITIALIZER; @@ -23,7 +24,7 @@ cons (void *arg) do { - if (--ntogo == 0) + if (atomic_decrement_and_test (&ntogo)) { pthread_mutex_lock (&mut2); alldone = true; @@ -68,11 +69,11 @@ main (int argc, char *argv[]) pthread_t th[nthreads]; int i; - for (i = 0; i < nthreads; ++i) + for (i = 0; __builtin_expect (i < nthreads, 1); ++i) if (__builtin_expect ((err = pthread_create (&th[i], NULL, cons, (void *) (long) i)) != 0, 0)) printf ("pthread_create: %s\n", strerror (err)); - for (i = 0; i < nrounds; ++i) + for (i = 0; __builtin_expect (i < nrounds, 1); ++i) { pthread_mutex_lock (&mut2); while (! alldone) diff --git a/nptl/pthread_attr_init.c b/nptl/pthread_attr_init.c index 90c8dc2ede..b202d46bd3 100644 --- a/nptl/pthread_attr_init.c +++ b/nptl/pthread_attr_init.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2002 Free Software Foundation, Inc. +/* Copyright (C) 2002, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2002. @@ -79,15 +79,13 @@ __pthread_attr_init_2_0 (attr) struct sched_param schedparam; int inheritsched; int scope; - } *iattr; + }; /* Many elements are initialized to zero so let us do it all at once. This also takes care of clearing the bytes which are not internally used. */ memset (attr, '\0', sizeof (struct old_attr)); - iattr = (struct old_attr *) attr; - /* We cannot enqueue the attribute because that member is not in the old attribute structure. */ return 0; diff --git a/nptl/tst-align.c b/nptl/tst-align.c index 902a1c772a..2de9d7a107 100644 --- a/nptl/tst-align.c +++ b/nptl/tst-align.c @@ -21,7 +21,7 @@ #include <stdbool.h> #include <stdint.h> #include <stdio.h> - +#include <tst-stack-align.h> static void * tf (void *arg) @@ -30,14 +30,7 @@ tf (void *arg) puts ("in thread"); - double d = 2.0; - printf ("double: %g %p %zu\n", d, &d, __alignof (double)); - if ((((uintptr_t) &d) & (__alignof (double) - 1)) != 0) - ok = false; - - long double ld = 3.0; - printf ("ldouble: %Lg %p %zu\n", ld, &ld, __alignof (long double)); - if ((((uintptr_t) &ld) & (__alignof (long double) - 1)) != 0) + if (TEST_STACK_ALIGN ()) ok = false; return ok ? NULL : (void *) -1l; @@ -50,14 +43,7 @@ do_test (void) puts ("in main"); - double d = 0.0; - printf ("double: %g %p %zu\n", d, &d, __alignof (double)); - if ((((uintptr_t) &d) & (__alignof (double) - 1)) != 0) - ok = false; - - long double ld = 1.0; - printf ("ldouble: %Lg %p %zu\n", ld, &ld, __alignof (long double)); - if ((((uintptr_t) &ld) & (__alignof (long double) - 1)) != 0) + if (TEST_STACK_ALIGN ()) ok = false; pthread_t th; diff --git a/stdlib/Makefile b/stdlib/Makefile index 5ff7dfdbc6..f882a554ef 100644 --- a/stdlib/Makefile +++ b/stdlib/Makefile @@ -96,6 +96,8 @@ ifeq (yes,$(have-protected)) CFLAGS-atexit.c = -DHAVE_DOT_HIDDEN endif +CFLAGS-tst-bsearch.c = $(stack-align-test-flags) + include ../Rules # Testdir has to be named stdlib and needs to be writable diff --git a/stdlib/tst-bsearch.c b/stdlib/tst-bsearch.c index ad80776785..8d2fd895fe 100644 --- a/stdlib/tst-bsearch.c +++ b/stdlib/tst-bsearch.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2000, 2002 Free Software Foundation, Inc. +/* Copyright (C) 2000, 2002, 2003 Free Software Foundation, Inc. This file is part of the GNU C Library. Contributed by Ulrich Drepper <drepper@redhat.com>, 2000. @@ -19,6 +19,7 @@ #include <stdio.h> #include <stdlib.h> +#include <tst-stack-align.h> struct entry { @@ -40,6 +41,7 @@ struct entry }; #define narr (sizeof (arr) / sizeof (arr[0])) +static int align_check; static int comp (const void *p1, const void *p2) @@ -47,6 +49,9 @@ comp (const void *p1, const void *p2) struct entry *e1 = (struct entry *) p1; struct entry *e2 = (struct entry *) p2; + if (!align_check) + align_check = TEST_STACK_ALIGN () ? -1 : 1; + return e1->val - e2->val; } @@ -128,6 +133,17 @@ main (void) } } + if (align_check == 0) + { + puts ("alignment not checked"); + result = 1; + } + else if (align_check == -1) + { + puts ("stack not sufficiently aligned"); + result = 1; + } + if (result == 0) puts ("all OK"); diff --git a/sysdeps/generic/tst-stack-align.h b/sysdeps/generic/tst-stack-align.h new file mode 100644 index 0000000000..59b1e656a2 --- /dev/null +++ b/sysdeps/generic/tst-stack-align.h @@ -0,0 +1,35 @@ +/* Copyright (C) 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <stdio.h> +#include <stdint.h> + +#define TEST_STACK_ALIGN() \ + ({ \ + double _d = 12.0; \ + long double _ld = 15.0; \ + int _ret = 0; \ + printf ("double: %g %p %zu\n", _d, &_d, __alignof (double)); \ + if ((((uintptr_t) &_d) & (__alignof (double) - 1)) != 0) \ + _ret = 1; \ + \ + printf ("ldouble: %Lg %p %zu\n", _ld, &_ld, __alignof (long double)); \ + if ((((uintptr_t) &_ld) & (__alignof (long double) - 1)) != 0) \ + _ret = 1; \ + _ret; \ + }) diff --git a/sysdeps/i386/Makefile b/sysdeps/i386/Makefile index ba0d21f13f..56027703ce 100644 --- a/sysdeps/i386/Makefile +++ b/sysdeps/i386/Makefile @@ -20,3 +20,38 @@ CFLAGS-rtld.c += -Wno-uninitialized -Wno-unused CFLAGS-dl-load.c += -Wno-unused CFLAGS-dl-reloc.c += -Wno-unused endif + +# Most of the glibc routines don't ever call user defined callbacks +# nor use any FPU or SSE* and as such don't need bigger %esp alignment +# than 4 bytes. +# Lots of routines in math will use FPU, so make math subdir an exception +# here. +ifeq ($(subdir),math) +sysdep-CFLAGS += -mpreferred-stack-boundary=4 +else +ifeq ($(subdir),csu) +sysdep-CFLAGS += -mpreferred-stack-boundary=4 +else +sysdep-CFLAGS += -mpreferred-stack-boundary=2 +# Likewise, any function which calls user callbacks +uses-callbacks += -mpreferred-stack-boundary=4 +endif +endif + +# And a couple of other routines +ifeq ($(subdir),stdlib) +CFLAGS-exit.c += -mpreferred-stack-boundary=4 +endif +ifeq ($(subdir),elf) +CFLAGS-dl-init.c += -mpreferred-stack-boundary=4 +CFLAGS-dl-fini.c += -mpreferred-stack-boundary=4 +CFLAGS-dl-open.c += -mpreferred-stack-boundary=4 +CFLAGS-dl-close.c += -mpreferred-stack-boundary=4 +CFLAGS-dl-error.c += -mpreferred-stack-boundary=4 +endif +ifeq ($(subdir),dlfcn) +CFLAGS-dlopen.c += -mpreferred-stack-boundary=4 +CFLAGS-dlopenold.c += -mpreferred-stack-boundary=4 +CFLAGS-dlclose.c += -mpreferred-stack-boundary=4 +CFLAGS-dlerror.c += -mpreferred-stack-boundary=4 +endif diff --git a/sysdeps/i386/i686/Makefile b/sysdeps/i386/i686/Makefile index b85167fe4d..e9ac505e78 100644 --- a/sysdeps/i386/i686/Makefile +++ b/sysdeps/i386/i686/Makefile @@ -2,3 +2,6 @@ ifeq ($(subdir),csu) sysdep_routines += hp-timing static-only-routines += hp-timing endif + +# So that we can test __m128's alignment +stack-align-test-flags += -msse -mpreferred-stack-boundary=4 diff --git a/sysdeps/i386/i686/tst-stack-align.h b/sysdeps/i386/i686/tst-stack-align.h new file mode 100644 index 0000000000..e1894c65ec --- /dev/null +++ b/sysdeps/i386/i686/tst-stack-align.h @@ -0,0 +1,45 @@ +/* Copyright (C) 2003 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, write to the Free + Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + 02111-1307 USA. */ + +#include <stdio.h> +#include <stdint.h> +#ifndef __SSE__ +#include_next <tst-stack-align.h> +#else +#include <xmmintrin.h> + +#define TEST_STACK_ALIGN() \ + ({ \ + __m128 _m; \ + double _d = 12.0; \ + long double _ld = 15.0; \ + int _ret = 0; \ + printf ("__m128: %p %zu\n", &_m, __alignof (__m128)); \ + if ((((uintptr_t) &_m) & (__alignof (__m128) - 1)) != 0) \ + _ret = 1; \ + \ + printf ("double: %g %p %zu\n", _d, &_d, __alignof (double)); \ + if ((((uintptr_t) &_d) & (__alignof (double) - 1)) != 0) \ + _ret = 1; \ + \ + printf ("ldouble: %Lg %p %zu\n", _ld, &_ld, __alignof (long double)); \ + if ((((uintptr_t) &_ld) & (__alignof (long double) - 1)) != 0) \ + _ret = 1; \ + _ret; \ + }) +#endif |