]> git.ipfire.org Git - thirdparty/glibc.git/blame - csu/Makefile
Fix NEWS entry from 9bf8e29ca136
[thirdparty/glibc.git] / csu / Makefile
CommitLineData
28f540f4 1# Makefile for csu code for GNU C library.
04277e02 2# Copyright (C) 1995-2019 Free Software Foundation, Inc.
28f540f4
RM
3# This file is part of the GNU C Library.
4
5# The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
28f540f4
RM
9
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
41bdb6e2
AJ
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
28f540f4 14
41bdb6e2 15# You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16# License along with the GNU C Library; if not, see
17# <http://www.gnu.org/licenses/>.
28f540f4
RM
18
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
0f9cc699 21# (traditionally) or crt1.o (for ELF). In ELF we also install crti.o and
b5ca0fb0 22# crtn.o, special "initializer" and "finalizer" files used in the link
0e7dfaef 23# to make the .init and .fini sections work right.
28f540f4
RM
24
25subdir := csu
26
a5f891ac
JM
27include ../Makeconfig
28
8a30f00f 29routines = init-first libc-start $(libc-init) sysdep version check_fds \
ee2a5ae8 30 libc-tls elf-init dso_handle
ce460d04 31aux = errno
2a76f7ef 32elide-routines.os = libc-tls
06b31ad3 33static-only-routines = elf-init
b6da933b 34csu-dummies = $(filter-out $(start-installed-name),crt1.o Mcrt1.o)
d49499c1 35extra-objs = start.o \
b6da933b
UD
36 $(start-installed-name) g$(start-installed-name) $(csu-dummies) \
37 S$(start-installed-name)
11c981a9 38omit-deps = $(patsubst %.o,%,$(start-installed-name) g$(start-installed-name) \
bc4647a1 39 b$(start-installed-name) $(csu-dummies) \
9d7a3741
L
40 S$(start-installed-name) \
41 r$(start-installed-name) \
42 gr$(start-installed-name))
98186375 43install-lib = $(start-installed-name) g$(start-installed-name) $(csu-dummies)
28f540f4 44
2908885c
NA
45# No tests are allowed in the csu/ subdirectory because the startup
46# code is compiled with special flags.
47tests =
d15851ec 48
10c85e76
NA
49CFLAGS-.o += $(no-stack-protector)
50CFLAGS-.op += $(no-stack-protector)
51CFLAGS-.os += $(no-stack-protector)
52
3a885c1f
FW
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.
60CFLAGS-static-reloc.os += $(stack-protector)
61
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.
67CFLAGS-elf-init.oS += $(stack-protector)
68
bc4647a1 69ifeq (yes,$(build-shared))
d49499c1 70extra-objs += S$(start-installed-name) gmon-start.os
edd4cbcf
ST
71ifneq ($(start-installed-name),$(static-start-installed-name))
72extra-objs += gmon-start.o
73endif
bc4647a1 74install-lib += S$(start-installed-name)
95fa8590 75generated += start.os
d49499c1
L
76else
77extra-objs += gmon-start.o
bc4647a1
UD
78endif
79
083973f3 80ifneq ($(start-installed-name),$(static-start-installed-name))
9d7a3741
L
81# FIXME: Only Hurd defines static-start-installed-name. Hurd needs to
82# provide special rules to support static PIE.
083973f3
RM
83extra-objs += $(static-start-installed-name) g$(static-start-installed-name)
84omit-deps += $(patsubst %.o,%,$(static-start-installed-name) \
85 g$(static-start-installed-name))
86install-lib += $(static-start-installed-name) g$(static-start-installed-name)
9d7a3741
L
87else
88ifeq (yes,$(enable-static-pie))
89extra-objs += r$(start-installed-name) gr$(start-installed-name)
90install-lib += r$(start-installed-name) gr$(start-installed-name)
91endif
083973f3
RM
92endif
93
c7562c74 94before-compile += $(objpfx)abi-tag.h
da2d1bc5 95generated += abi-tag.h
b8dc6a10 96
37f91d33 97# These are the special initializer/finalizer files. They are always the
4e1bac76
RM
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.
100crtstuff = crti crtn
37f91d33
RM
101
102install-lib += $(crtstuff:=.o)
103extra-objs += $(crtstuff:=.o)
3add8e13 104
abcb584d
L
105ifneq ($(multidir),.)
106multilib-extra-objs = $(addprefix $(multidir)/, $(install-lib))
107extra-objs += $(multilib-extra-objs)
108endif
109
9d7a3741
L
110extra-objs += abi-note.o init.o static-reloc.o
111ifeq (yes,$(build-shared))
112extra-objs += static-reloc.os
113endif
92f1da4d 114asm-CPPFLAGS += -I$(objpfx).
51702635 115
ca3a382e
WD
116# Enable unwinding so backtrace unwinds to __libc_start_main
117CFLAGS-libc-start.c += -funwind-tables
118
28f540f4
RM
119include ../Rules
120
71cf0361
UD
121# Make these in the lib pass so they're available in time to link things with.
122subdir_lib: $(extra-objs:%=$(objpfx)%)
123
779ae82e
UD
124define link-relocatable
125$(CC) -nostdlib -nostartfiles -r -o $@ $^
126endef
127
b8dc6a10 128ifndef start-installed-name-rule
779ae82e 129# We link the ELF startfile along with a SHT_NOTE section indicating
3081378b 130# the kernel ABI the binaries linked with this library will require.
6973fc01 131$(objpfx)$(start-installed-name): $(objpfx)start.o $(objpfx)abi-note.o \
9d7a3741
L
132 $(objpfx)init.o $(objpfx)static-reloc.o
133 $(link-relocatable)
134$(objpfx)r$(start-installed-name): $(objpfx)start.o $(objpfx)abi-note.o \
6973fc01 135 $(objpfx)init.o
779ae82e 136 $(link-relocatable)
bc4647a1
UD
137$(objpfx)S$(start-installed-name): $(objpfx)start.os $(objpfx)abi-note.o \
138 $(objpfx)init.o
139 $(link-relocatable)
779ae82e 140endif
28f540f4 141
11c981a9
RM
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.
d49499c1 145ifeq (yes,$(build-shared))
edd4cbcf 146$(objpfx)g$(start-installed-name): \
9d7a3741
L
147 $(objpfx)g%: $(objpfx)S% $(objpfx)gmon-start.os $(objpfx)static-reloc.os
148 $(link-relocatable)
149$(objpfx)gr$(start-installed-name): \
150 $(objpfx)gr%: $(objpfx)r% $(objpfx)gmon-start.o
d49499c1 151 $(link-relocatable)
edd4cbcf
ST
152ifneq ($(start-installed-name),$(static-start-installed-name))
153$(objpfx)g$(static-start-installed-name): \
154 $(objpfx)g%: $(objpfx)% $(objpfx)gmon-start.o
155 $(link-relocatable)
156endif
d49499c1 157else
083973f3
RM
158$(addprefix $(objpfx),$(sort g$(start-installed-name) \
159 g$(static-start-installed-name))): \
160 $(objpfx)g%: $(objpfx)% $(objpfx)gmon-start.o
779ae82e 161 $(link-relocatable)
d49499c1 162endif
11c981a9 163
28f540f4
RM
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.
b6da933b 166$(addprefix $(objpfx),$(filter-out $(start-installed-name), $(csu-dummies))):\
c6696b79
RM
167 $(before-compile)
168 $(COMPILE.c) -o $@ -x c /dev/null
92f1da4d 169
c7562c74 170# These headers are used by the startup code.
92f1da4d 171$(objpfx)abi-tag.h: $(..)abi-tags
39e16978 172 $(make-target-directory)
92f1da4d 173 rm -f $@.new
0f9cc699 174 sed -e 's/#.*$$//' -e '/^[ ]*$$/d' $< | \
a986484f 175 while read conf tagos tagver; do \
92f1da4d
UD
176 test `expr '$(config-machine)-$(config-vendor)-$(config-os)' \
177 : "$$conf"` != 0 || continue; \
a986484f
UD
178 ( echo "$$tagos" | \
179 sed -e 's/[^0-9xXa-fA-F ]//' \
180 -e 's/^/#define __ABI_TAG_OS /'; \
181 echo "#ifndef __ABI_TAG_VERSION"; \
182 echo "$$tagver" | \
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; \
92f1da4d
UD
186 done
187 if test -r $@.new; then mv -f $@.new $@; \
188 else echo >&2 'This configuration not matched in $<'; exit 1; fi
abcb584d
L
189
190ifneq ($(multidir),.)
191$(addprefix $(objpfx)$(multidir)/, $(install-lib)): $(addprefix $(objpfx), $(install-lib))
192 $(make-link-multidir)
193endif