blob: 31e8bb98a068f42cbcf5e27500f0bef73c55c1a1 [file] [log] [blame]
xf.libdd93d52023-05-12 07:10:14 -07001# Makefile for csu code for GNU C library.
2# Copyright (C) 1995-2016 Free Software Foundation, Inc.
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
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.
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
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13# Lesser General Public License for more details.
14
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# <http://www.gnu.org/licenses/>.
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
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.
24
25subdir := csu
26
27include ../Makeconfig
28
29routines = init-first libc-start $(libc-init) sysdep version check_fds \
30 libc-tls elf-init dso_handle
31aux = errno
32elide-routines.os = libc-tls
33static-only-routines = elf-init
34csu-dummies = $(filter-out $(start-installed-name),crt1.o Mcrt1.o)
35extra-objs = start.o \
36 $(start-installed-name) g$(start-installed-name) $(csu-dummies) \
37 S$(start-installed-name)
38omit-deps = $(patsubst %.o,%,$(start-installed-name) g$(start-installed-name) \
39 b$(start-installed-name) $(csu-dummies) \
40 S$(start-installed-name))
41install-lib = $(start-installed-name) g$(start-installed-name) $(csu-dummies)
42generated += version-info.h
43before-compile += $(objpfx)version-info.h
44
45tests := tst-empty tst-atomic tst-atomic-long
46tests-static := tst-empty
47
48ifeq (yes,$(build-shared))
49extra-objs += S$(start-installed-name) gmon-start.os
50ifneq ($(start-installed-name),$(static-start-installed-name))
51extra-objs += gmon-start.o
52endif
53install-lib += S$(start-installed-name)
54generated += start.os
55else
56extra-objs += gmon-start.o
57endif
58
59ifneq ($(start-installed-name),$(static-start-installed-name))
60extra-objs += $(static-start-installed-name) g$(static-start-installed-name)
61omit-deps += $(patsubst %.o,%,$(static-start-installed-name) \
62 g$(static-start-installed-name))
63install-lib += $(static-start-installed-name) g$(static-start-installed-name)
64endif
65
66before-compile += $(objpfx)abi-tag.h
67generated += abi-tag.h
68
69# These are the special initializer/finalizer files. They are always the
70# first and last file in the link. crti.o ... crtn.o define the global
71# "functions" _init and _fini to run the .init and .fini sections.
72crtstuff = crti crtn
73
74install-lib += $(crtstuff:=.o)
75extra-objs += $(crtstuff:=.o)
76
77extra-objs += abi-note.o init.o
78asm-CPPFLAGS += -I$(objpfx).
79
80include ../Rules
81
82# Make these in the lib pass so they're available in time to link things with.
83subdir_lib: $(extra-objs:%=$(objpfx)%)
84
85define link-relocatable
86$(CC) -nostdlib -nostartfiles -r -o $@ $^
87endef
88
89ifndef start-installed-name-rule
90# We link the ELF startfile along with a SHT_NOTE section indicating
91# the kernel ABI the binaries linked with this library will require.
92$(objpfx)$(start-installed-name): $(objpfx)start.o $(objpfx)abi-note.o \
93 $(objpfx)init.o
94 $(link-relocatable)
95$(objpfx)S$(start-installed-name): $(objpfx)start.os $(objpfx)abi-note.o \
96 $(objpfx)init.o
97 $(link-relocatable)
98endif
99
100# The profiling startfile is made by linking together the normal
101# startfile with gmon-start.o, which defines a constructor function
102# to turn on profiling code at startup.
103ifeq (yes,$(build-shared))
104$(objpfx)g$(start-installed-name): \
105 $(objpfx)g%: $(objpfx)S% $(objpfx)gmon-start.os
106 $(link-relocatable)
107ifneq ($(start-installed-name),$(static-start-installed-name))
108$(objpfx)g$(static-start-installed-name): \
109 $(objpfx)g%: $(objpfx)% $(objpfx)gmon-start.o
110 $(link-relocatable)
111endif
112else
113$(addprefix $(objpfx),$(sort g$(start-installed-name) \
114 g$(static-start-installed-name))): \
115 $(objpfx)g%: $(objpfx)% $(objpfx)gmon-start.o
116 $(link-relocatable)
117endif
118
119# These extra files are sometimes expected by system standard linking
120# procedures, but we have nothing for them to do. So compile empty files.
121$(addprefix $(objpfx),$(filter-out $(start-installed-name), $(csu-dummies))):\
122 $(before-compile)
123 $(COMPILE.c) -o $@ -x c /dev/null
124
125# These headers are used by the startup code.
126$(objpfx)abi-tag.h: $(..)abi-tags
127 $(make-target-directory)
128 rm -f $@.new
129 sed -e 's/#.*$$//' -e '/^[ ]*$$/d' $< | \
130 while read conf tagos tagver; do \
131 test `expr '$(config-machine)-$(config-vendor)-$(config-os)' \
132 : "$$conf"` != 0 || continue; \
133 ( echo "$$tagos" | \
134 sed -e 's/[^0-9xXa-fA-F ]//' \
135 -e 's/^/#define __ABI_TAG_OS /'; \
136 echo "#ifndef __ABI_TAG_VERSION"; \
137 echo "$$tagver" | \
138 sed -e 's/[^0-9xXa-fA-F]/ /g' -e 's/ *$$//' \
139 -e 's/ /,/g' -e 's/^/# define __ABI_TAG_VERSION /'; \
140 echo "#endif" ) > $@.new; \
141 done
142 if test -r $@.new; then mv -f $@.new $@; \
143 else echo >&2 'This configuration not matched in $<'; exit 1; fi
144
145all-Banner-files = $(wildcard $(addsuffix /Banner,\
146 $(sort $(subdir-srcdirs) \
147 $(sysdeps-srcdirs))))
148$(objpfx)version-info.h: $(common-objpfx)config.make $(all-Banner-files)
149 $(make-target-directory)
150 (files="$(all-Banner-files)"; \
151 if test -n "$$files"; then \
152 printf '"Available extensions:\\n"\n'; \
153 sed -e '/^#/d' -e 's/^[[:space:]]*/ /' \
154 -e 's/^\(.*\)$$/\"\1\\n\"/' $$files; \
155 fi) > $@T
156 mv -f $@T $@