public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Fix tst-getpid{1,2} on ia64
@ 2005-03-08 16:04 Jakub Jelinek
  2005-03-08 16:21 ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Jelinek @ 2005-03-08 16:04 UTC (permalink / raw)
  To: Ulrich Drepper, Roland McGrath; +Cc: Glibc hackers

Hi!

When glibc is built with gcc-4_0-branch on IA-64, tst-getpid{1,2}
fails.  The problem is that while older GCCs always aligned
buffer as big as char st[256 * 1024]; to 16 bytes, GCC 4 only
aligns this to 8 bytes.
Now, either we require direct clone/__clone2 users to make sure
the stack passed to it is sufficiently aligned (as done e.g. in
the patch below, 64 is just a guess for all arches out there,
I think e.g. IA-64 needs just 16 bytes alingment), or we make sure
that glibc's __clone2 and clone align things themselves, or we
make sure the kernel aligns it.

2005-03-08  Jakub Jelinek  <jakub@redhat.com>

	* tst-getpid1.c: Include stdint.h.
	(do_test): Align stack passed to clone{2,} to 64 bytes.

--- libc/nptl/tst-getpid1.c.jj	2004-12-15 12:16:06.000000000 +0100
+++ libc/nptl/tst-getpid1.c	2005-03-08 16:54:43.947924210 +0100
@@ -1,6 +1,7 @@
 #include <sched.h>
 #include <signal.h>
 #include <string.h>
+#include <stdint.h>
 #include <stdio.h>
 #include <unistd.h>
 #include <sys/types.h>
@@ -44,11 +45,13 @@ do_test (void)
   extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
 		       size_t __child_stack_size, int __flags,
 		       void *__arg, ...);
-  char st[256 * 1024];
-  pid_t p = __clone2 (f, st, sizeof (st), TEST_CLONE_FLAGS, 0);
+  char st[256 * 1024 + 64];
+  char *stp = (char *) ((uintptr_t) (st + 64) & -64);
+  pid_t p = __clone2 (f, stp, sizeof (st) - 64, TEST_CLONE_FLAGS, 0);
 #else
-  char st[128 * 1024];
-  pid_t p = clone (f, st + sizeof (st), TEST_CLONE_FLAGS, 0);
+  char st[128 * 1024 + 64];
+  char *stp = (char *) ((uintptr_t) (st + 64) & -64);
+  pid_t p = clone (f, stp + sizeof (st) - 64, TEST_CLONE_FLAGS, 0);
 #endif
   if (p == -1)
     {

	Jakub

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Fix tst-getpid{1,2} on ia64
  2005-03-08 16:04 [PATCH] Fix tst-getpid{1,2} on ia64 Jakub Jelinek
@ 2005-03-08 16:21 ` Andreas Schwab
  2005-03-08 16:27   ` Jakub Jelinek
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2005-03-08 16:21 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Ulrich Drepper, Roland McGrath, Glibc hackers

Jakub Jelinek <jakub@redhat.com> writes:

> Now, either we require direct clone/__clone2 users to make sure
> the stack passed to it is sufficiently aligned

Would __attribute__((aligned)) work here?

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Fix tst-getpid{1,2} on ia64
  2005-03-08 16:21 ` Andreas Schwab
@ 2005-03-08 16:27   ` Jakub Jelinek
  2005-03-08 16:40     ` Andreas Schwab
  0 siblings, 1 reply; 5+ messages in thread
From: Jakub Jelinek @ 2005-03-08 16:27 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Ulrich Drepper, Roland McGrath, Glibc hackers

On Tue, Mar 08, 2005 at 05:20:54PM +0100, Andreas Schwab wrote:
> Jakub Jelinek <jakub@redhat.com> writes:
> 
> > Now, either we require direct clone/__clone2 users to make sure
> > the stack passed to it is sufficiently aligned
> 
> Would __attribute__((aligned)) work here?

On IA-64 yes, but is __attribute__((aligned)) on all architectures
equal to the needed stack alignment?
If it is bigger than stack alignment, GCC disregards it (or just aligns
to stack alignment?), if it is on some arch smaller than needed stack
alignment, then it will not help.

	Jakub

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] Fix tst-getpid{1,2} on ia64
  2005-03-08 16:27   ` Jakub Jelinek
@ 2005-03-08 16:40     ` Andreas Schwab
  2005-03-10 11:18       ` [PATCH] Fix tst-getpid{1,2} on ia64 (take 2) Jakub Jelinek
  0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2005-03-08 16:40 UTC (permalink / raw)
  To: Jakub Jelinek; +Cc: Ulrich Drepper, Roland McGrath, Glibc hackers

Jakub Jelinek <jakub@redhat.com> writes:

> On Tue, Mar 08, 2005 at 05:20:54PM +0100, Andreas Schwab wrote:
>> Jakub Jelinek <jakub@redhat.com> writes:
>> 
>> > Now, either we require direct clone/__clone2 users to make sure
>> > the stack passed to it is sufficiently aligned
>> 
>> Would __attribute__((aligned)) work here?
>
> On IA-64 yes, but is __attribute__((aligned)) on all architectures
> equal to the needed stack alignment?

It can't be worse than the current situation.

> If it is bigger than stack alignment, GCC disregards it (or just aligns
> to stack alignment?), if it is on some arch smaller than needed stack
> alignment, then it will not help.

IMHO it should be ok for now.  GCC already needs to know how to keep the
stack aligned anyway.

Andreas.

-- 
Andreas Schwab, SuSE Labs, schwab@suse.de
SuSE Linux Products GmbH, Maxfeldstraße 5, 90409 Nürnberg, Germany
Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] Fix tst-getpid{1,2} on ia64 (take 2)
  2005-03-08 16:40     ` Andreas Schwab
@ 2005-03-10 11:18       ` Jakub Jelinek
  0 siblings, 0 replies; 5+ messages in thread
From: Jakub Jelinek @ 2005-03-10 11:18 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: Ulrich Drepper, Roland McGrath, Glibc hackers

On Tue, Mar 08, 2005 at 05:40:02PM +0100, Andreas Schwab wrote:
> It can't be worse than the current situation.
> 
> > If it is bigger than stack alignment, GCC disregards it (or just aligns
> > to stack alignment?), if it is on some arch smaller than needed stack
> > alignment, then it will not help.
> 
> IMHO it should be ok for now.  GCC already needs to know how to keep the
> stack aligned anyway.

Ok, let's go with this instead then...

2005-03-10  Jakub Jelinek  <jakub@redhat.com>

	* tst-getpid1.c (do_test): Align stack passed to clone{2,}.

--- libc/nptl/tst-getpid1.c.jj	2004-12-15 12:16:06.000000000 +0100
+++ libc/nptl/tst-getpid1.c	2005-03-10 12:16:18.988119781 +0100
@@ -44,10 +44,10 @@ do_test (void)
   extern int __clone2 (int (*__fn) (void *__arg), void *__child_stack_base,
 		       size_t __child_stack_size, int __flags,
 		       void *__arg, ...);
-  char st[256 * 1024];
+  char st[256 * 1024] __attribute__ ((aligned));
   pid_t p = __clone2 (f, st, sizeof (st), TEST_CLONE_FLAGS, 0);
 #else
-  char st[128 * 1024];
+  char st[128 * 1024] __attribute__ ((aligned));
   pid_t p = clone (f, st + sizeof (st), TEST_CLONE_FLAGS, 0);
 #endif
   if (p == -1)

	Jakub

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2005-03-10 11:18 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-03-08 16:04 [PATCH] Fix tst-getpid{1,2} on ia64 Jakub Jelinek
2005-03-08 16:21 ` Andreas Schwab
2005-03-08 16:27   ` Jakub Jelinek
2005-03-08 16:40     ` Andreas Schwab
2005-03-10 11:18       ` [PATCH] Fix tst-getpid{1,2} on ia64 (take 2) Jakub Jelinek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).