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.
This commit is contained in:
Ulrich Drepper 2003-09-17 08:47:44 +00:00
parent 6c052003bd
commit a4db3439f1
13 changed files with 179 additions and 25 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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;

View File

@ -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;

View File

@ -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

View File

@ -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");

View File

@ -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; \
})

View File

@ -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

View File

@ -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

View File

@ -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