riscv64: fix linking with binutils 2.40
[uclibc-ng.git] / libc / sysdeps / linux / riscv64 / crt1.S
blob15aa0763c3e9e9f8889b969205d0546e0e3caf28
1 /* Startup code compliant to the ELF RISC-V ABI.
2    Copyright (C) 1995-2018 Free Software Foundation, Inc.
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    In addition to the permissions in the GNU Lesser General Public
10    License, the Free Software Foundation gives you unlimited
11    permission to link the compiled version of this file with other
12    programs, and to distribute those programs without any restriction
13    coming from the use of this file. (The GNU Lesser General Public
14    License restrictions do apply in other respects; for example, they
15    cover modification of the file, and distribution when not linked
16    into another program.)
18    Note that people who make modified versions of this file are not
19    obligated to grant this special exception for their modified
20    versions; it is their choice whether to do so. The GNU Lesser
21    General Public License gives permission to release a modified
22    version without this exception; this exception also makes it
23    possible to release a modified version which carries forward this
24    exception.
26    The GNU C Library is distributed in the hope that it will be useful,
27    but WITHOUT ANY WARRANTY; without even the implied warranty of
28    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
29    Lesser General Public License for more details.
31    You should have received a copy of the GNU Lesser General Public
32    License along with the GNU C Library.  If not, see
33    <http://www.gnu.org/licenses/>.  */
35 #define __ASSEMBLY__ 1
37 #include <sysdep.h>
38 #include <sys/asm.h>
40 /* The entry point's job is to call __uClibc_main.  Per the ABI,
41    a0 contains the address of a function to be passed to atexit.
42    __uClibc_main wants this in a5.  */
44 .text
45         .globl  _start
46         .type   _start,%function
48         .weak _init
49         .weak _fini
51 _start:
52         call  .Lload_gp
53         mv    a5, a0  /* rtld_fini.  */
54         /* main may be in a shared library.  */
55         la   a0, main
56         REG_L a1, 0(sp)      /* argc.  */
57         addi  a2, sp, SZREG  /* argv.  */
58         andi  sp, sp, ALMASK /* Align stack. */
59         lla   a3, _init
60         lla   a4, _fini
61         mv    a6, sp  /* stack_end.  */
63         tail  __uClibc_main@plt
65         .size   _start,.-_start
67 /* Dynamic links need the global pointer to be initialized prior to calling
68    any shared library's initializers, so we use preinit_array to load it.
69    This doesn't cut it for static links, though, since the global pointer
70    needs to be initialized before calling __libc_start_main in that case.
71    So we redundantly initialize it at the beginning of _start.  */
73 .Lload_gp:
74 .option push
75 .option norelax
76         lla   gp, __global_pointer$
77 .option pop
78         ret
80         .section .preinit_array,"aw"
81         .dc.a .Lload_gp
83 /* Define a symbol for the first piece of initialized data.  */
84         .data
85         .globl __data_start
86 __data_start:
87         .weak data_start
88         data_start = __data_start