1 # Makefile for csu code for GNU C library.
2 # Copyright (C) 1995-2018 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
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/>.
19 # This directory contains the C startup code (that which calls main). This
20 # consists of the startfile, built from start.c and installed as crt0.o
21 # (traditionally) or crt1.o (for ELF). In ELF we also install crti.o and
22 # crtn.o, special "initializer" and "finalizer" files used in the link
23 # to make the .init and .fini sections work right.
29 routines
= init-first libc-start
$(libc-init
) sysdep version check_fds \
30 libc-tls elf-init dso_handle
32 elide-routines.os
= libc-tls
33 static-only-routines
= elf-init
34 csu-dummies
= $(filter-out $(start-installed-name
),crt1.o Mcrt1.o
)
35 extra-objs
= start.o \
36 $(start-installed-name
) g
$(start-installed-name
) $(csu-dummies
) \
37 S
$(start-installed-name
)
38 omit-deps
= $(patsubst %.o
,%,$(start-installed-name
) g
$(start-installed-name
) \
39 b
$(start-installed-name
) $(csu-dummies
) \
40 S
$(start-installed-name
) \
41 r
$(start-installed-name
) \
42 gr
$(start-installed-name
))
43 install-lib
= $(start-installed-name
) g
$(start-installed-name
) $(csu-dummies
)
45 # No tests are allowed in the csu/ subdirectory because the startup
46 # code is compiled with special flags.
49 CFLAGS-.o
+= $(no-stack-protector
)
50 CFLAGS-.op
+= $(no-stack-protector
)
51 CFLAGS-.os
+= $(no-stack-protector
)
53 # Dummy object not actually used for anything. It is linked into
54 # crt1.o nevertheless, which in turn is statically linked into
55 # applications, so that build flags matter.
56 # See <https://sourceware.org/ml/libc-alpha/2018-07/msg00101.html>.
57 # NB: Using $(stack-protector) in this way causes a wrong definition
58 # STACK_PROTECTOR_LEVEL due to the preceding $(no-stack-protector),
59 # but it does not matter for this source file.
60 CFLAGS-static-reloc.os
+= $(stack-protector
)
62 # This file is not actually part of the startup code in the nonshared
63 # case and statically linked into applications. See
64 # <https://sourceware.org/bugzilla/show_bug.cgi?id=23323>,
65 # <https://sourceware.org/ml/libc-alpha/2018-06/msg00717.html>.
66 # Also see the note above regarding STACK_PROTECTOR_LEVEL.
67 CFLAGS-elf-init.oS
+= $(stack-protector
)
69 ifeq (yes
,$(build-shared
))
70 extra-objs
+= S
$(start-installed-name
) gmon-start.os
71 ifneq ($(start-installed-name
),$(static-start-installed-name
))
72 extra-objs
+= gmon-start.o
74 install-lib
+= S
$(start-installed-name
)
77 extra-objs
+= gmon-start.o
80 ifneq ($(start-installed-name
),$(static-start-installed-name
))
81 # FIXME: Only Hurd defines static-start-installed-name. Hurd needs to
82 # provide special rules to support static PIE.
83 extra-objs
+= $(static-start-installed-name
) g
$(static-start-installed-name
)
84 omit-deps
+= $(patsubst %.o
,%,$(static-start-installed-name
) \
85 g
$(static-start-installed-name
))
86 install-lib
+= $(static-start-installed-name
) g
$(static-start-installed-name
)
88 ifeq (yes
,$(enable-static-pie
))
89 extra-objs
+= r
$(start-installed-name
) gr
$(start-installed-name
)
90 install-lib
+= r
$(start-installed-name
) gr
$(start-installed-name
)
94 before-compile
+= $(objpfx
)abi-tag.h
95 generated
+= abi-tag.h
97 # These are the special initializer/finalizer files. They are always the
98 # first and last file in the link. crti.o ... crtn.o define the global
99 # "functions" _init and _fini to run the .init and .fini sections.
102 install-lib
+= $(crtstuff
:=.o
)
103 extra-objs
+= $(crtstuff
:=.o
)
105 ifneq ($(multidir
),.
)
106 multilib-extra-objs
= $(addprefix $(multidir
)/, $(install-lib
))
107 extra-objs
+= $(multilib-extra-objs
)
110 extra-objs
+= abi-note.o init.o static-reloc.o
111 ifeq (yes
,$(build-shared
))
112 extra-objs
+= static-reloc.os
114 asm-CPPFLAGS
+= -I
$(objpfx
).
116 # Enable unwinding so backtrace unwinds to __libc_start_main
117 CFLAGS-libc-start.c
+= -funwind-tables
121 # Make these in the lib pass so they're available in time to link things with.
122 subdir_lib
: $(extra-objs
:%=$(objpfx
)%)
124 define link-relocatable
125 $(CC
) -nostdlib
-nostartfiles
-r
-o
$@
$^
128 ifndef start-installed-name-rule
129 # We link the ELF startfile along with a SHT_NOTE section indicating
130 # the kernel ABI the binaries linked with this library will require.
131 $(objpfx
)$(start-installed-name
): $(objpfx
)start.o
$(objpfx
)abi-note.o \
132 $(objpfx
)init.o
$(objpfx
)static-reloc.o
134 $(objpfx
)r
$(start-installed-name
): $(objpfx
)start.o
$(objpfx
)abi-note.o \
137 $(objpfx
)S
$(start-installed-name
): $(objpfx
)start.os
$(objpfx
)abi-note.o \
142 # The profiling startfile is made by linking together the normal
143 # startfile with gmon-start.o, which defines a constructor function
144 # to turn on profiling code at startup.
145 ifeq (yes
,$(build-shared
))
146 $(objpfx
)g
$(start-installed-name
): \
147 $(objpfx
)g
%: $(objpfx
)S
% $(objpfx
)gmon-start.os
$(objpfx
)static-reloc.os
149 $(objpfx
)gr
$(start-installed-name
): \
150 $(objpfx
)gr
%: $(objpfx
)r
% $(objpfx
)gmon-start.o
152 ifneq ($(start-installed-name
),$(static-start-installed-name
))
153 $(objpfx
)g
$(static-start-installed-name
): \
154 $(objpfx
)g
%: $(objpfx
)% $(objpfx
)gmon-start.o
158 $(addprefix $(objpfx
),$(sort g
$(start-installed-name
) \
159 g
$(static-start-installed-name
))): \
160 $(objpfx
)g
%: $(objpfx
)% $(objpfx
)gmon-start.o
164 # These extra files are sometimes expected by system standard linking
165 # procedures, but we have nothing for them to do. So compile empty files.
166 $(addprefix $(objpfx
),$(filter-out $(start-installed-name
), $(csu-dummies
))):\
168 $(COMPILE.c
) -o
$@
-x c
/dev
/null
170 # These headers are used by the startup code.
171 $(objpfx
)abi-tag.h
: $(..
)abi-tags
172 $(make-target-directory
)
174 sed
-e
's/#.*$$//' -e
'/^[ ]*$$/d' $< | \
175 while read conf tagos tagver
; do \
176 test `expr '$(config-machine)-$(config-vendor)-$(config-os)' \
177 : "$$conf"` != 0 || continue
; \
179 sed
-e
's/[^0-9xXa-fA-F ]//' \
180 -e
's/^/#define __ABI_TAG_OS /'; \
181 echo
"#ifndef __ABI_TAG_VERSION"; \
183 sed
-e
's/[^0-9xXa-fA-F]/ /g' -e
's/ *$$//' \
184 -e
's/ /,/g' -e
's/^/# define __ABI_TAG_VERSION /'; \
185 echo
"#endif" ) > $@.new
; \
187 if
test -r
$@.new
; then mv
-f
$@.new
$@
; \
188 else echo
>&2 'This configuration not matched in $<'; exit
1; fi
190 ifneq ($(multidir
),.
)
191 $(addprefix $(objpfx
)$(multidir
)/, $(install-lib
)): $(addprefix $(objpfx
), $(install-lib
))
192 $(make-link-multidir
)