1/* Copyright (C) 1998-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3
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.
8
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.
13
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/>. */
17
18#include <stdlib.h>
19#include <unistd.h>
20#include <ldsodefs.h>
21#include <sysdep.h>
22
23#ifndef SHARED
24#include <hwcapinfo.h>
25#endif
26
27/* The main work is done in the generic function. */
28#define LIBC_START_MAIN generic_start_main
29#define LIBC_START_DISABLE_INLINE
30#define LIBC_START_MAIN_AUXVEC_ARG
31#define MAIN_AUXVEC_ARG
32#define INIT_MAIN_ARGS
33#include <csu/libc-start.c>
34
35struct startup_info
36 {
37 void *sda_base;
38 int (*main) (int, char **, char **, void *);
39 int (*init) (int, char **, char **, void *);
40 void (*fini) (void);
41 };
42
43int
44__libc_start_main_impl (int argc, char **argv,
45 char **ev,
46 ElfW (auxv_t) * auxvec,
47 void (*rtld_fini) (void),
48 struct startup_info *stinfo,
49 char **stack_on_entry)
50{
51 /* the PPC SVR4 ABI says that the top thing on the stack will
52 be a NULL pointer, so if not we assume that we're being called
53 as a statically-linked program by Linux... */
54 if (*stack_on_entry != NULL)
55 {
56 char **temp;
57 /* ...in which case, we have argc as the top thing on the
58 stack, followed by argv (NULL-terminated), envp (likewise),
59 and the auxiliary vector. */
60 /* 32/64-bit agnostic load from stack */
61 argc = *(long int *) stack_on_entry;
62 argv = stack_on_entry + 1;
63 ev = argv + argc + 1;
64#ifdef HAVE_AUX_VECTOR
65 temp = ev;
66 while (*temp != NULL)
67 ++temp;
68 auxvec = (ElfW (auxv_t) *)++ temp;
69#endif
70 rtld_fini = NULL;
71 }
72
73 for (ElfW (auxv_t) * av = auxvec; av->a_type != AT_NULL; ++av)
74 switch (av->a_type)
75 {
76 /* For the static case, we also need _dl_hwcap, _dl_hwcap2 and
77 _dl_platform, so we can call
78 __tcb_parse_hwcap_and_convert_at_platform (). */
79#ifndef SHARED
80 case AT_HWCAP:
81 _dl_hwcap = (unsigned long int) av->a_un.a_val;
82 break;
83 case AT_HWCAP2:
84 _dl_hwcap2 = (unsigned long int) av->a_un.a_val;
85 break;
86 case AT_PLATFORM:
87 _dl_platform = (void *) av->a_un.a_val;
88 break;
89#endif
90 }
91
92 /* Initialize hwcap/hwcap2 and platform data so it can be copied to
93 the TCB later in __libc_setup_tls (). (static case only). */
94#ifndef SHARED
95 __tcb_parse_hwcap_and_convert_at_platform ();
96#endif
97
98 return generic_start_main (main: stinfo->main, argc, argv, auxvec,
99 init: stinfo->init, fini: stinfo->fini, rtld_fini,
100 stack_end: stack_on_entry);
101}
102DEFINE_LIBC_START_MAIN_VERSION
103

source code of glibc/sysdeps/unix/sysv/linux/powerpc/libc-start.c