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
) \
45 S
$(start-installed-name
) \
46 g
$(start-installed-name
) \
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
))
56 $(start-installed-name
) \
57 g
$(start-installed-name
) \
60 # No tests are allowed in the csu/ subdirectory because the startup
61 # code is compiled with special flags.
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 \
83 $(routines
) $(extra-no-ssp
)))
85 ifeq (yes
,$(build-shared
))
87 S
$(start-installed-name
) \
90 ifneq ($(start-installed-name
),$(static-start-installed-name
))
91 extra-objs
+= gmon-start.o
93 install-lib
+= S
$(start-installed-name
)
96 extra-objs
+= gmon-start.o
99 ifeq (yes
,$(enable-static-pie
))
101 gr
$(start-installed-name
) \
102 r
$(start-installed-name
) \
105 gr
$(start-installed-name
) \
106 r
$(start-installed-name
) \
110 ifneq ($(start-installed-name
),$(static-start-installed-name
))
112 $(static-start-installed-name
) \
113 g
$(static-start-installed-name
) \
115 omit-deps
+= $(patsubst %.o
,%,$(static-start-installed-name
) \
116 g
$(static-start-installed-name
))
118 $(static-start-installed-name
) \
119 g
$(static-start-installed-name
) \
121 ifeq (yes
,$(enable-static-pie
))
123 gr
$(static-start-installed-name
) \
124 r
$(static-start-installed-name
) \
126 omit-deps
+= $(patsubst %.o
,%,r
$(static-start-installed-name
) \
127 gr
$(static-start-installed-name
))
129 gr
$(static-start-installed-name
) \
130 r
$(static-start-installed-name
) \
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.
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
)
162 ifeq (yes
,$(build-shared
))
163 extra-objs
+= static-reloc.os
165 asm-CPPFLAGS
+= -I
$(objpfx
).
167 # Enable unwinding so backtrace unwinds to __libc_start_main
168 CFLAGS-libc-start.c
+= -funwind-tables
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
$@
$^
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
185 $(objpfx
)r
$(start-installed-name
): $(objpfx
)start.o
$(objpfx
)abi-note.o \
188 $(objpfx
)S
$(start-installed-name
): $(objpfx
)start.os
$(objpfx
)abi-note.o \
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
200 $(objpfx
)gr
$(start-installed-name
): \
201 $(objpfx
)gr
%: $(objpfx
)r
% $(objpfx
)gmon-start.o
203 ifneq ($(start-installed-name
),$(static-start-installed-name
))
204 $(objpfx
)g
$(static-start-installed-name
): \
205 $(objpfx
)g
%: $(objpfx
)% $(objpfx
)gmon-start.o
207 $(objpfx
)gr
$(static-start-installed-name
): \
208 $(objpfx
)gr
%: $(objpfx
)r
% $(objpfx
)gmon-start.o
212 $(addprefix $(objpfx
),$(sort g
$(start-installed-name
) \
213 g
$(static-start-installed-name
))): \
214 $(objpfx
)g
%: $(objpfx
)% $(objpfx
)gmon-start.o
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
))):\
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
)
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
; \
233 sed
-e
's/[^0-9xXa-fA-F ]//' \
234 -e
's/^/#define __ABI_TAG_OS /'; \
235 echo
"#ifndef __ABI_TAG_VERSION"; \
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
; \
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
)