1 # Makefile for csu code for GNU C library.
2 # Copyright (C) 1995-2024 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 # <https://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.
40 elide-routines.os
= libc-tls
41 csu-dummies
= $(filter-out $(start-installed-name
),crt1.o Mcrt1.o
)
44 $(start-installed-name
) \
46 S
$(start-installed-name
) \
47 g
$(start-installed-name
) \
50 omit-deps
= $(patsubst %.o
,%,$(start-installed-name
) g
$(start-installed-name
) \
51 b
$(start-installed-name
) $(csu-dummies
) \
52 S
$(start-installed-name
) \
53 r
$(start-installed-name
) \
54 gr
$(start-installed-name
))
57 $(start-installed-name
) \
58 g
$(start-installed-name
) \
61 # No tests are allowed in the csu/ subdirectory because the startup
62 # code is compiled with special flags.
65 # static-reloc.os is a dummy object not actually used for anything. It is
66 # linked into crt1.o nevertheless, which in turn is statically linked into
67 # applications, so that build flags matter.
68 # See <https://sourceware.org/ml/libc-alpha/2018-07/msg00101.html>.
70 # The function is called prior the thread pointer setup, and if stack
71 # protector is enabled the compiler might still generate the stack check
72 # (which requires the thread pointer correctly set).
73 extra-no-ssp
= static-reloc
75 # libc-start.os is safe to be built with stack protector since
76 # __libc_start_main is called after stack canary setup is done.
77 ssp-safe.os
= libc-start
79 CFLAGS-.o
+= $(call elide-stack-protector
,.o
,$(routines
) $(extra-no-ssp
))
80 CFLAGS-.op
+= $(call elide-stack-protector
,.op
,$(routines
) $(extra-no-ssp
))
81 CFLAGS-.oS
+= $(call elide-stack-protector
,.oS
,$(routines
) $(extra-no-ssp
))
82 CFLAGS-.os
+= $(call elide-stack-protector
,.os
,$(filter-out \
84 $(routines
) $(extra-no-ssp
)))
86 ifeq (yes
,$(build-shared
))
88 S
$(start-installed-name
) \
91 ifneq ($(start-installed-name
),$(static-start-installed-name
))
92 extra-objs
+= gmon-start.o
94 install-lib
+= S
$(start-installed-name
)
97 extra-objs
+= gmon-start.o
100 ifeq (yes
,$(enable-static-pie
))
102 gr
$(start-installed-name
) \
103 r
$(start-installed-name
) \
106 gr
$(start-installed-name
) \
107 r
$(start-installed-name
) \
111 ifneq ($(start-installed-name
),$(static-start-installed-name
))
113 $(static-start-installed-name
) \
114 g
$(static-start-installed-name
) \
116 omit-deps
+= $(patsubst %.o
,%,$(static-start-installed-name
) \
117 g
$(static-start-installed-name
))
119 $(static-start-installed-name
) \
120 g
$(static-start-installed-name
) \
122 ifeq (yes
,$(enable-static-pie
))
124 gr
$(static-start-installed-name
) \
125 r
$(static-start-installed-name
) \
127 omit-deps
+= $(patsubst %.o
,%,r
$(static-start-installed-name
) \
128 gr
$(static-start-installed-name
))
130 gr
$(static-start-installed-name
) \
131 r
$(static-start-installed-name
) \
136 before-compile
+= $(objpfx
)abi-tag.h
137 generated
+= abi-tag.h
139 # Put it here to generate it earlier.
140 gen-as-const-headers
+= rtld-sizes.sym
142 # These are the special initializer/finalizer files. They are always the
143 # first and last file in the link. crti.o ... crtn.o define the global
144 # "functions" _init and _fini to run the .init and .fini sections.
150 install-lib
+= $(crtstuff
:=.o
)
151 extra-objs
+= $(crtstuff
:=.o
)
153 ifneq ($(multidir
),.
)
154 multilib-extra-objs
= $(addprefix $(multidir
)/, $(install-lib
))
155 extra-objs
+= $(multilib-extra-objs
)
163 ifeq (yes
,$(build-shared
))
164 extra-objs
+= static-reloc.os
166 asm-CPPFLAGS
+= -I
$(objpfx
).
168 # Enable unwinding so backtrace unwinds to __libc_start_main
169 CFLAGS-libc-start.c
+= -funwind-tables
173 # Make these in the lib pass so they're available in time to link things with.
174 subdir_lib
: $(extra-objs
:%=$(objpfx
)%)
176 define link-relocatable
177 $(CC
) -nostdlib
-nostartfiles
-r
-o
$@
$^
180 ifndef start-installed-name-rule
181 # We link the ELF startfile along with a SHT_NOTE section indicating
182 # the kernel ABI the binaries linked with this library will require.
183 $(objpfx
)$(start-installed-name
): $(objpfx
)start.o
$(objpfx
)abi-note.o \
184 $(objpfx
)init.o
$(objpfx
)static-reloc.o
186 $(objpfx
)$(start-name-2.0
): $(objpfx
)start.o
$(objpfx
)abi-note.o \
187 $(objpfx
)static-reloc.o
189 $(objpfx
)r
$(start-installed-name
): $(objpfx
)start.o
$(objpfx
)abi-note.o \
192 $(objpfx
)S
$(start-installed-name
): $(objpfx
)start.os
$(objpfx
)abi-note.o \
197 # The profiling startfile is made by linking together the normal
198 # startfile with gmon-start.o, which defines a constructor function
199 # to turn on profiling code at startup.
200 ifeq (yes
,$(build-shared
))
201 $(objpfx
)g
$(start-installed-name
): \
202 $(objpfx
)g
%: $(objpfx
)S
% $(objpfx
)gmon-start.os
$(objpfx
)static-reloc.os
204 $(objpfx
)gr
$(start-installed-name
): \
205 $(objpfx
)gr
%: $(objpfx
)r
% $(objpfx
)gmon-start.o
207 ifneq ($(start-installed-name
),$(static-start-installed-name
))
208 $(objpfx
)g
$(static-start-installed-name
): \
209 $(objpfx
)g
%: $(objpfx
)% $(objpfx
)gmon-start.o
211 $(objpfx
)gr
$(static-start-installed-name
): \
212 $(objpfx
)gr
%: $(objpfx
)r
% $(objpfx
)gmon-start.o
216 $(addprefix $(objpfx
),$(sort g
$(start-installed-name
) \
217 g
$(static-start-installed-name
))): \
218 $(objpfx
)g
%: $(objpfx
)% $(objpfx
)gmon-start.o
222 # These extra files are sometimes expected by system standard linking
223 # procedures, but we have nothing for them to do. So compile empty files.
224 $(addprefix $(objpfx
),$(filter-out $(start-installed-name
), $(csu-dummies
))):\
226 $(COMPILE.c
) -o
$@
-x c
/dev
/null
228 # These headers are used by the startup code.
229 $(objpfx
)abi-tag.h
: $(..
)abi-tags
230 $(make-target-directory
)
232 sed
-e
's/#.*$$//' -e
'/^[ ]*$$/d' $< | \
233 while read conf tagos tagver
; do \
234 test `expr '$(config-machine)-$(config-vendor)-$(config-os)' \
235 : "$$conf"` != 0 || continue
; \
237 sed
-e
's/[^0-9xXa-fA-F ]//' \
238 -e
's/^/#define __ABI_TAG_OS /'; \
239 echo
"#ifndef __ABI_TAG_VERSION"; \
241 sed
-e
's/[^0-9xXa-fA-F]/ /g' -e
's/ *$$//' \
242 -e
's/ /,/g' -e
's/^/# define __ABI_TAG_VERSION /'; \
243 echo
"#endif" ) > $@.new
; \
245 if
test -r
$@.new
; then mv
-f
$@.new
$@
; \
246 else echo
>&2 'This configuration not matched in $<'; exit
1; fi
248 ifneq ($(multidir
),.
)
249 $(addprefix $(objpfx
)$(multidir
)/, $(install-lib
)): $(addprefix $(objpfx
), $(install-lib
))
250 $(make-link-multidir
)