lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | #include <string.h> |
| 2 | #include <unistd.h> |
| 3 | |
| 4 | static void |
| 5 | preinit_0 (int argc __attribute__ ((unused)), char **argv) |
| 6 | { |
| 7 | char *p = strrchr (argv [0], '/'); |
| 8 | |
| 9 | if (p == NULL) |
| 10 | return; |
| 11 | |
| 12 | p++; |
| 13 | size_t len = strlen (p); |
| 14 | write (STDOUT_FILENO, "preinit array in executable: ", 29); |
| 15 | write (STDOUT_FILENO, p, len); |
| 16 | write (STDOUT_FILENO, "\n", 1); |
| 17 | } |
| 18 | |
| 19 | void (*const preinit_array []) (int, char **) |
| 20 | __attribute__ ((section (".preinit_array"), aligned (sizeof (void *)))) = |
| 21 | { |
| 22 | &preinit_0, |
| 23 | }; |
| 24 | |
| 25 | static void |
| 26 | init_0 (int argc __attribute__ ((unused)), char **argv) |
| 27 | { |
| 28 | char *p = strrchr (argv [0], '/'); |
| 29 | |
| 30 | if (p == NULL) |
| 31 | return; |
| 32 | |
| 33 | p++; |
| 34 | size_t len = strlen (p); |
| 35 | write (STDOUT_FILENO, "init array in executable: ", 26); |
| 36 | write (STDOUT_FILENO, p, len); |
| 37 | write (STDOUT_FILENO, "\n", 1); |
| 38 | } |
| 39 | |
| 40 | void (*const init_array []) (int, char **) |
| 41 | __attribute__ ((section (".init_array"), aligned (sizeof (void *)))) = |
| 42 | { |
| 43 | &init_0, |
| 44 | }; |
| 45 | |
| 46 | int |
| 47 | main (void) |
| 48 | { |
| 49 | return 0; |
| 50 | } |