1 /* Copyright (C) 2005-2013 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Jakub Jelinek <jakub@redhat.com>, 2005.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
24 #include <tst-stack-align.h>
27 static int res
, fds
[2], result
;
28 static bool test_destructors
;
30 extern void in_dso (int *, bool *, int *);
32 static void __attribute__ ((constructor
)) con (void)
34 res
= TEST_STACK_ALIGN () ? -1 : 1;
37 static void __attribute__ ((destructor
)) des (void)
39 if (!test_destructors
)
42 char c
= TEST_STACK_ALIGN () ? 'B' : 'A';
43 write (fds
[1], &c
, 1);
51 puts ("binary's constructor has not been run");
56 puts ("binary's constructor has been run without sufficient alignment");
60 if (TEST_STACK_ALIGN ())
62 puts ("insufficient stack alignment in do_test");
66 in_dso (&result
, &test_destructors
, &fds
[1]);
70 printf ("couldn't create pipe: %m\n");
77 printf ("fork failed: %m\n");
84 test_destructors
= true;
92 int des_seen
= 0, dso_des_seen
= 0;
93 while ((len
= TEMP_FAILURE_RETRY (read (fds
[0], &c
, 1))) > 0)
98 puts ("insufficient alignment in binary's destructor");
105 puts ("insufficient alignment in DSO destructor");
112 printf ("unexpected character %x read from pipe", c
);
122 printf ("binary destructor run %d times instead of once\n", des_seen
);
126 if (dso_des_seen
!= 1)
128 printf ("DSO destructor run %d times instead of once\n", dso_des_seen
);
134 termpid
= TEMP_FAILURE_RETRY (waitpid (pid
, &status
, 0));
137 printf ("waitpid failed: %m\n");
140 else if (termpid
!= pid
)
142 printf ("waitpid returned %ld != %ld\n",
143 (long int) termpid
, (long int) pid
);
146 else if (!WIFEXITED (status
) || WEXITSTATUS (status
))
148 puts ("child hasn't exited with exit status 0");
155 #define TEST_FUNCTION do_test ()
156 #include "../test-skeleton.c"