1 /* Copyright (C) 2005-2023 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
23 #include <tst-stack-align.h>
26 static int res
, fds
[2], result
;
27 static bool test_destructors
;
29 extern void in_dso (int *, bool *, int *);
31 static void __attribute__ ((constructor
)) con (void)
33 res
= TEST_STACK_ALIGN () ? -1 : 1;
36 static void __attribute__ ((destructor
)) des (void)
38 if (!test_destructors
)
41 char c
= TEST_STACK_ALIGN () ? 'B' : 'A';
42 write (fds
[1], &c
, 1);
50 puts ("binary's constructor has not been run");
55 puts ("binary's constructor has been run without sufficient alignment");
59 if (TEST_STACK_ALIGN ())
61 puts ("insufficient stack alignment in do_test");
65 in_dso (&result
, &test_destructors
, &fds
[1]);
69 printf ("couldn't create pipe: %m\n");
76 printf ("fork failed: %m\n");
83 test_destructors
= true;
91 int des_seen
= 0, dso_des_seen
= 0;
92 while ((len
= TEMP_FAILURE_RETRY (read (fds
[0], &c
, 1))) > 0)
97 puts ("insufficient alignment in binary's destructor");
104 puts ("insufficient alignment in DSO destructor");
111 printf ("unexpected character %x read from pipe", c
);
121 printf ("binary destructor run %d times instead of once\n", des_seen
);
125 if (dso_des_seen
!= 1)
127 printf ("DSO destructor run %d times instead of once\n", dso_des_seen
);
133 termpid
= TEMP_FAILURE_RETRY (waitpid (pid
, &status
, 0));
136 printf ("waitpid failed: %m\n");
139 else if (termpid
!= pid
)
141 printf ("waitpid returned %ld != %ld\n",
142 (long int) termpid
, (long int) pid
);
145 else if (!WIFEXITED (status
) || WEXITSTATUS (status
))
147 puts ("child hasn't exited with exit status 0");
154 #include <support/test-driver.c>