malloc/Makefile: Split and sort tests
[glibc.git] / csu / Makefile
blob777d6720a70bef5ab7003ab3a0707d10792f7a99
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.
25 subdir := csu
27 include ../Makeconfig
29 routines = \
30 $(libc-init) \
31 check_fds \
32 dso_handle \
33 init-first \
34 libc-start \
35 libc-tls \
36 sysdep \
37 version \
38 # routines
39 aux = errno
40 elide-routines.os = libc-tls
41 csu-dummies = $(filter-out $(start-installed-name),crt1.o Mcrt1.o)
42 extra-objs = \
43 $(csu-dummies) \
44 $(start-installed-name) \
45 $(start-name-2.0) \
46 S$(start-installed-name) \
47 g$(start-installed-name) \
48 start.o \
49 # extra-objs
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))
55 install-lib = \
56 $(csu-dummies) \
57 $(start-installed-name) \
58 g$(start-installed-name) \
59 # install-lib
61 # No tests are allowed in the csu/ subdirectory because the startup
62 # code is compiled with special flags.
63 tests =
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 \
83 $(ssp-safe.os), \
84 $(routines) $(extra-no-ssp)))
86 ifeq (yes,$(build-shared))
87 extra-objs += \
88 S$(start-installed-name) \
89 gmon-start.os \
90 # extra-objs
91 ifneq ($(start-installed-name),$(static-start-installed-name))
92 extra-objs += gmon-start.o
93 endif
94 install-lib += S$(start-installed-name)
95 generated += start.os
96 else
97 extra-objs += gmon-start.o
98 endif
100 ifeq (yes,$(enable-static-pie))
101 extra-objs += \
102 gr$(start-installed-name) \
103 r$(start-installed-name) \
104 # extra-objs
105 install-lib += \
106 gr$(start-installed-name) \
107 r$(start-installed-name) \
108 # install-lib
109 endif
111 ifneq ($(start-installed-name),$(static-start-installed-name))
112 extra-objs += \
113 $(static-start-installed-name) \
114 g$(static-start-installed-name) \
115 # extra-objs
116 omit-deps += $(patsubst %.o,%,$(static-start-installed-name) \
117 g$(static-start-installed-name))
118 install-lib += \
119 $(static-start-installed-name) \
120 g$(static-start-installed-name) \
121 # install-lib
122 ifeq (yes,$(enable-static-pie))
123 extra-objs += \
124 gr$(static-start-installed-name) \
125 r$(static-start-installed-name) \
126 # extra-objs
127 omit-deps += $(patsubst %.o,%,r$(static-start-installed-name) \
128 gr$(static-start-installed-name))
129 install-lib += \
130 gr$(static-start-installed-name) \
131 r$(static-start-installed-name) \
132 # install-lib
133 endif
134 endif
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.
145 crtstuff = \
146 crti \
147 crtn \
148 # crtstuff
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)
156 endif
158 extra-objs += \
159 abi-note.o \
160 init.o \
161 static-reloc.o \
162 # extra-objs
163 ifeq (yes,$(build-shared))
164 extra-objs += static-reloc.os
165 endif
166 asm-CPPFLAGS += -I$(objpfx).
168 # Enable unwinding so backtrace unwinds to __libc_start_main
169 CFLAGS-libc-start.c += -funwind-tables
171 include ../Rules
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 $@ $^
178 endef
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
185 $(link-relocatable)
186 $(objpfx)$(start-name-2.0): $(objpfx)start.o $(objpfx)abi-note.o \
187 $(objpfx)static-reloc.o
188 $(link-relocatable)
189 $(objpfx)r$(start-installed-name): $(objpfx)start.o $(objpfx)abi-note.o \
190 $(objpfx)init.o
191 $(link-relocatable)
192 $(objpfx)S$(start-installed-name): $(objpfx)start.os $(objpfx)abi-note.o \
193 $(objpfx)init.o
194 $(link-relocatable)
195 endif
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
203 $(link-relocatable)
204 $(objpfx)gr$(start-installed-name): \
205 $(objpfx)gr%: $(objpfx)r% $(objpfx)gmon-start.o
206 $(link-relocatable)
207 ifneq ($(start-installed-name),$(static-start-installed-name))
208 $(objpfx)g$(static-start-installed-name): \
209 $(objpfx)g%: $(objpfx)% $(objpfx)gmon-start.o
210 $(link-relocatable)
211 $(objpfx)gr$(static-start-installed-name): \
212 $(objpfx)gr%: $(objpfx)r% $(objpfx)gmon-start.o
213 $(link-relocatable)
214 endif
215 else
216 $(addprefix $(objpfx),$(sort g$(start-installed-name) \
217 g$(static-start-installed-name))): \
218 $(objpfx)g%: $(objpfx)% $(objpfx)gmon-start.o
219 $(link-relocatable)
220 endif
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))):\
225 $(before-compile)
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)
231 rm -f $@.new
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; \
236 ( echo "$$tagos" | \
237 sed -e 's/[^0-9xXa-fA-F ]//' \
238 -e 's/^/#define __ABI_TAG_OS /'; \
239 echo "#ifndef __ABI_TAG_VERSION"; \
240 echo "$$tagver" | \
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; \
244 done
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)
251 endif