riscv: Fix alignment-ignorant memcpy implementation
[glibc.git] / csu / Makefile
blob946fd910314296262f5a3bf29a66a3e94ca0defb
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 S$(start-installed-name) \
46 g$(start-installed-name) \
47 start.o \
48 # extra-objs
49 omit-deps = $(patsubst %.o,%,$(start-installed-name) g$(start-installed-name) \
50 b$(start-installed-name) $(csu-dummies) \
51 S$(start-installed-name) \
52 r$(start-installed-name) \
53 gr$(start-installed-name))
54 install-lib = \
55 $(csu-dummies) \
56 $(start-installed-name) \
57 g$(start-installed-name) \
58 # install-lib
60 # No tests are allowed in the csu/ subdirectory because the startup
61 # code is compiled with special flags.
62 tests =
64 # static-reloc.os is a dummy object not actually used for anything. It is
65 # linked into crt1.o nevertheless, which in turn is statically linked into
66 # applications, so that build flags matter.
67 # See <https://sourceware.org/ml/libc-alpha/2018-07/msg00101.html>.
69 # The function is called prior the thread pointer setup, and if stack
70 # protector is enabled the compiler might still generate the stack check
71 # (which requires the thread pointer correctly set).
72 extra-no-ssp = static-reloc
74 # libc-start.os is safe to be built with stack protector since
75 # __libc_start_main is called after stack canary setup is done.
76 ssp-safe.os = libc-start
78 CFLAGS-.o += $(call elide-stack-protector,.o,$(routines) $(extra-no-ssp))
79 CFLAGS-.op += $(call elide-stack-protector,.op,$(routines) $(extra-no-ssp))
80 CFLAGS-.oS += $(call elide-stack-protector,.oS,$(routines) $(extra-no-ssp))
81 CFLAGS-.os += $(call elide-stack-protector,.os,$(filter-out \
82 $(ssp-safe.os), \
83 $(routines) $(extra-no-ssp)))
85 ifeq (yes,$(build-shared))
86 extra-objs += \
87 S$(start-installed-name) \
88 gmon-start.os \
89 # extra-objs
90 ifneq ($(start-installed-name),$(static-start-installed-name))
91 extra-objs += gmon-start.o
92 endif
93 install-lib += S$(start-installed-name)
94 generated += start.os
95 else
96 extra-objs += gmon-start.o
97 endif
99 ifeq (yes,$(enable-static-pie))
100 extra-objs += \
101 gr$(start-installed-name) \
102 r$(start-installed-name) \
103 # extra-objs
104 install-lib += \
105 gr$(start-installed-name) \
106 r$(start-installed-name) \
107 # install-lib
108 endif
110 ifneq ($(start-installed-name),$(static-start-installed-name))
111 extra-objs += \
112 $(static-start-installed-name) \
113 g$(static-start-installed-name) \
114 # extra-objs
115 omit-deps += $(patsubst %.o,%,$(static-start-installed-name) \
116 g$(static-start-installed-name))
117 install-lib += \
118 $(static-start-installed-name) \
119 g$(static-start-installed-name) \
120 # install-lib
121 ifeq (yes,$(enable-static-pie))
122 extra-objs += \
123 gr$(static-start-installed-name) \
124 r$(static-start-installed-name) \
125 # extra-objs
126 omit-deps += $(patsubst %.o,%,r$(static-start-installed-name) \
127 gr$(static-start-installed-name))
128 install-lib += \
129 gr$(static-start-installed-name) \
130 r$(static-start-installed-name) \
131 # install-lib
132 endif
133 endif
135 before-compile += $(objpfx)abi-tag.h
136 generated += abi-tag.h
138 # Put it here to generate it earlier.
139 gen-as-const-headers += rtld-sizes.sym
141 # These are the special initializer/finalizer files. They are always the
142 # first and last file in the link. crti.o ... crtn.o define the global
143 # "functions" _init and _fini to run the .init and .fini sections.
144 crtstuff = \
145 crti \
146 crtn \
147 # crtstuff
149 install-lib += $(crtstuff:=.o)
150 extra-objs += $(crtstuff:=.o)
152 ifneq ($(multidir),.)
153 multilib-extra-objs = $(addprefix $(multidir)/, $(install-lib))
154 extra-objs += $(multilib-extra-objs)
155 endif
157 extra-objs += \
158 abi-note.o \
159 init.o \
160 static-reloc.o \
161 # extra-objs
162 ifeq (yes,$(build-shared))
163 extra-objs += static-reloc.os
164 endif
165 asm-CPPFLAGS += -I$(objpfx).
167 # Enable unwinding so backtrace unwinds to __libc_start_main
168 CFLAGS-libc-start.c += -funwind-tables
170 include ../Rules
172 # Make these in the lib pass so they're available in time to link things with.
173 subdir_lib: $(extra-objs:%=$(objpfx)%)
175 define link-relocatable
176 $(CC) -nostdlib -nostartfiles -r -o $@ $^
177 endef
179 ifndef start-installed-name-rule
180 # We link the ELF startfile along with a SHT_NOTE section indicating
181 # the kernel ABI the binaries linked with this library will require.
182 $(objpfx)$(start-installed-name): $(objpfx)start.o $(objpfx)abi-note.o \
183 $(objpfx)init.o $(objpfx)static-reloc.o
184 $(link-relocatable)
185 $(objpfx)r$(start-installed-name): $(objpfx)start.o $(objpfx)abi-note.o \
186 $(objpfx)init.o
187 $(link-relocatable)
188 $(objpfx)S$(start-installed-name): $(objpfx)start.os $(objpfx)abi-note.o \
189 $(objpfx)init.o
190 $(link-relocatable)
191 endif
193 # The profiling startfile is made by linking together the normal
194 # startfile with gmon-start.o, which defines a constructor function
195 # to turn on profiling code at startup.
196 ifeq (yes,$(build-shared))
197 $(objpfx)g$(start-installed-name): \
198 $(objpfx)g%: $(objpfx)S% $(objpfx)gmon-start.os $(objpfx)static-reloc.os
199 $(link-relocatable)
200 $(objpfx)gr$(start-installed-name): \
201 $(objpfx)gr%: $(objpfx)r% $(objpfx)gmon-start.o
202 $(link-relocatable)
203 ifneq ($(start-installed-name),$(static-start-installed-name))
204 $(objpfx)g$(static-start-installed-name): \
205 $(objpfx)g%: $(objpfx)% $(objpfx)gmon-start.o
206 $(link-relocatable)
207 $(objpfx)gr$(static-start-installed-name): \
208 $(objpfx)gr%: $(objpfx)r% $(objpfx)gmon-start.o
209 $(link-relocatable)
210 endif
211 else
212 $(addprefix $(objpfx),$(sort g$(start-installed-name) \
213 g$(static-start-installed-name))): \
214 $(objpfx)g%: $(objpfx)% $(objpfx)gmon-start.o
215 $(link-relocatable)
216 endif
218 # These extra files are sometimes expected by system standard linking
219 # procedures, but we have nothing for them to do. So compile empty files.
220 $(addprefix $(objpfx),$(filter-out $(start-installed-name), $(csu-dummies))):\
221 $(before-compile)
222 $(COMPILE.c) -o $@ -x c /dev/null
224 # These headers are used by the startup code.
225 $(objpfx)abi-tag.h: $(..)abi-tags
226 $(make-target-directory)
227 rm -f $@.new
228 sed -e 's/#.*$$//' -e '/^[ ]*$$/d' $< | \
229 while read conf tagos tagver; do \
230 test `expr '$(config-machine)-$(config-vendor)-$(config-os)' \
231 : "$$conf"` != 0 || continue; \
232 ( echo "$$tagos" | \
233 sed -e 's/[^0-9xXa-fA-F ]//' \
234 -e 's/^/#define __ABI_TAG_OS /'; \
235 echo "#ifndef __ABI_TAG_VERSION"; \
236 echo "$$tagver" | \
237 sed -e 's/[^0-9xXa-fA-F]/ /g' -e 's/ *$$//' \
238 -e 's/ /,/g' -e 's/^/# define __ABI_TAG_VERSION /'; \
239 echo "#endif" ) > $@.new; \
240 done
241 if test -r $@.new; then mv -f $@.new $@; \
242 else echo >&2 'This configuration not matched in $<'; exit 1; fi
244 ifneq ($(multidir),.)
245 $(addprefix $(objpfx)$(multidir)/, $(install-lib)): $(addprefix $(objpfx), $(install-lib))
246 $(make-link-multidir)
247 endif