-# Copyright (C) 1991-2012 Free Software Foundation, Inc.
+# Copyright (C) 1991-2018 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
$(before-compile))
# Even before that, we need abi-versions.h which is generated right here.
-ifeq ($(versioning),yes)
+ifeq ($(build-shared),yes)
ifndef avoid-generated
before-compile := $(common-objpfx)abi-versions.h $(before-compile)
$(common-objpfx)abi-versions.h: $(..)scripts/abi-versions.awk \
$(common-objpfx)Versions.all
- LC_ALL=C $(AWK) -v oldest_abi=$(oldest-abi) -f $^ > $@T
+ LC_ALL=C $(AWK) -f $^ > $@T
mv -f $@T $@
$(common-objpfx)%.latest: $(common-objpfx)abi-versions.h
sed -n '/ VERSION_$*_/{s/^.*_\([A-Z0-9_]*\).*$$/\1/;h;};$${g;p;}' \
$(common-objpfx)abi-versions.h > $@T
mv -f $@T $@
+
+# first-versions.h and ldbl-compat-choose.h provide macros used in
+# various symbol versioning macro calls.
+before-compile := $(common-objpfx)first-versions.h \
+ $(common-objpfx)ldbl-compat-choose.h $(before-compile)
+$(common-objpfx)first-versions.h: $(common-objpfx)versions.stmp
+$(common-objpfx)ldbl-compat-choose.h: $(common-objpfx)versions.stmp
endif # avoid-generated
-endif # $(versioning) = yes
+endif # $(build-shared) = yes
ifndef avoid-generated
+ifneq (,$(CXX))
+# If C++ headers <cstdlib> or <cmath> are used, GCC 6 will include
+# /usr/include/stdlib.h or /usr/include/math.h from "#include_next"
+# (instead of stdlib/stdlib.h or math/math.h in the glibc source
+# directory), and this turns up as a make dependency. An implicit
+# rule will kick in and make will try to install stdlib/stdlib.h or
+# math/math.h as /usr/include/stdlib.h or /usr/include/math.h because
+# the target is out of date. We make a copy of <cstdlib> and <cmath>
+# in the glibc build directory so that stdlib/stdlib.h and math/math.h
+# will be used instead of /usr/include/stdlib.h and /usr/include/math.h.
+before-compile := $(common-objpfx)cstdlib $(common-objpfx)cmath \
+ $(before-compile)
+$(common-objpfx)cstdlib: $(c++-cstdlib-header)
+ $(INSTALL_DATA) $< $@T
+ $(move-if-change) $@T $@
+$(common-objpfx)cmath: $(c++-cmath-header)
+ $(INSTALL_DATA) $< $@T
+ $(move-if-change) $@T $@
+ifneq (,$(c++-bits-std_abs-h))
+# Also make a copy of <bits/std_abs.h> from GCC 7 to prevent it from
+# including /usr/include/stdlib.h.
+before-compile := $(common-objpfx)bits/std_abs.h $(before-compile)
+$(common-objpfx)bits/std_abs.h: $(c++-bits-std_abs-h)
+ $(INSTALL_DATA) $< $@T
+ $(move-if-change) $@T $@
+endif
+endif
+
before-compile := $(common-objpfx)libc-abis.h $(before-compile)
$(common-objpfx)libc-abis.h: $(common-objpfx)libc-abis.stamp; @:
$(common-objpfx)libc-abis.stamp: $(..)scripts/gen-libc-abis \
common-generated += $(common-objpfx)libc-abis.h
endif # avoid-generated
+ifeq (yes,$(build-shared))
+$(common-objpfx)runtime-linker.h: $(common-objpfx)runtime-linker.stamp; @:
+$(common-objpfx)runtime-linker.stamp: $(common-objpfx)config.make
+ $(make-target-directory)
+ echo '#define RUNTIME_LINKER "$(rtlddir)/$(rtld-installed-name)"' \
+ > ${@:stamp=T}
+ $(move-if-change) ${@:stamp=T} ${@:stamp=h}
+ touch $@
+endif
+
# Make sure the subdirectory for object files gets created.
ifdef objpfx
ifeq (,$(wildcard $(objpfx).))
-e 's@^\([^ \/$$][^ \]*\)@$$(..)\1@g'
endif
+ifdef gen-py-const-headers
+# We'll use a static pattern rule to match .pysym files with their
+# corresponding generated .py files.
+# The generated .py files go in the submodule's dir in the glibc build dir.
+py-const-files := $(patsubst %.pysym,%.py,$(gen-py-const-headers))
+py-const-dir := $(objpfx)
+py-const := $(addprefix $(py-const-dir),$(py-const-files))
+py-const-script := $(..)scripts/gen-py-const.awk
+
+# This is a hack we use to generate .py files with constants for Python
+# pretty printers. It works the same way as gen-as-const.
+# See scripts/gen-py-const.awk for details on how the awk | gcc mechanism
+# works.
+#
+# $@.tmp and $@.tmp2 are temporary files we use to store the partial contents
+# of the target file. We do this instead of just writing on $@ because, if the
+# build process terminates prematurely, re-running Make wouldn't run this rule
+# since Make would see that the target file already exists (despite it being
+# incomplete).
+#
+# The sed line replaces "@name@SOME_NAME@value@SOME_VALUE@" strings from the
+# output of 'gcc -S' with "SOME_NAME = SOME_VALUE" strings.
+# The '-n' option, combined with the '/p' command, makes sed output only the
+# modified lines instead of the whole input file. The output is redirected
+# to a .py file; we'll import it in the pretty printers file to read
+# the constants generated by gen-py-const.awk.
+# The regex has two capturing groups, for SOME_NAME and SOME_VALUE
+# respectively. Notice SOME_VALUE may be prepended by a special character,
+# depending on the assembly syntax (e.g. immediates are prefixed by a '$'
+# in AT&T x86, and by a '#' in ARM). We discard it using a complemented set
+# before the second capturing group.
+$(py-const): $(py-const-dir)%.py: %.pysym $(py-const-script) \
+ $(common-before-compile)
+ $(make-target-directory)
+ $(AWK) -f $(py-const-script) $< \
+ | $(CC) -S -o $@.tmp $(CFLAGS) $(CPPFLAGS) -x c -
+ echo '# GENERATED FILE\n' > $@.tmp2
+ echo '# Constant definitions for pretty printers.' >> $@.tmp2
+ echo '# See gen-py-const.awk for details.\n' >> $@.tmp2
+ sed -n -r 's/^.*@name@([^@]+)@value@[^[:xdigit:]Xx-]*([[:xdigit:]Xx-]+)@.*/\1 = \2/p' \
+ $@.tmp >> $@.tmp2
+ mv -f $@.tmp2 $@
+ rm -f $@.tmp
+
+generated += $(py-const)
+endif # gen-py-const-headers
ifdef gen-as-const-headers
# Generating headers for assembly constants.
# We need this defined early to get into before-compile before
# it's used in sysd-rules, below.
+# Define GEN_AS_CONST_HEADERS to avoid circular dependency [BZ #22792].
+# NB: <tcb-offsets.h> is generated from tcb-offsets.sym to define
+# offsets and sizes of types in <tls.h> and maybe <pthread.h> which
+# may include <tcb-offsets.h>. Target header files can check if
+# GEN_AS_CONST_HEADERS is defined to avoid circular dependency which
+# may lead to build hang on a many-core machine.
$(common-objpfx)%.h $(common-objpfx)%.h.d: $(..)scripts/gen-as-const.awk \
%.sym $(common-before-compile)
$(AWK) -f $< $(filter %.sym,$^) \
- | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) -x c - \
+ | $(CC) -S -o $(@:.h.d=.h)T3 $(CFLAGS) $(CPPFLAGS) \
+ -DGEN_AS_CONST_HEADERS -x c - \
-MD -MP -MF $(@:.h=.h.d)T -MT '$(@:.h=.h.d) $(@:.h.d=.h)'
sed -n 's/^.*@@@name@@@\([^@]*\)@@@value@@@[^0-9Xxa-fA-F-]*\([0-9Xxa-fA-F-][0-9Xxa-fA-F-]*\).*@@@end@@@.*$$/#define \1 \2/p' \
$(@:.h.d=.h)T3 > $(@:.h.d=.h)T
vpath %.sym $(sysdirs)
before-compile += $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
-tests += $(gen-as-const-headers:%.sym=test-as-const-%)
+tests-internal += $(gen-as-const-headers:%.sym=test-as-const-%)
generated += $(gen-as-const-headers:%.sym=test-as-const-%.c)
$(objpfx)test-as-const-%.c: $(..)scripts/gen-as-const.awk $(..)Makerules \
%.sym $(common-objpfx)%.h
mv -f $@T $@
endif
\f
+ifeq (yes,$(build-shared))
+# Generate the header containing the names of all shared libraries.
+# We use a stamp file to avoid unnecessary recompilations.
+before-compile += $(common-objpfx)gnu/lib-names.h
+ifeq ($(soversions.mk-done),t)
+ifndef abi-variants
+lib-names-h-abi = gnu/lib-names.h
+lib-names-stmp-abi = gnu/lib-names.stmp
+else
+lib-names-h-abi = gnu/lib-names-$(default-abi).h
+lib-names-stmp-abi = gnu/lib-names-$(default-abi).stmp
+before-compile += $(common-objpfx)$(lib-names-h-abi)
+common-generated += gnu/lib-names.h
+install-others-nosubdir: $(inst_includedir)/$(lib-names-h-abi)
+$(common-objpfx)gnu/lib-names.h:
+ $(make-target-directory)
+ { \
+ echo '/* This file is automatically generated.';\
+ echo ' It defines macros to allow user program to find the shared'; \
+ echo ' library files which come as part of GNU libc. */'; \
+ echo '#ifndef __GNU_LIB_NAMES_H'; \
+ echo '#define __GNU_LIB_NAMES_H 1'; \
+ echo ''; \
+ $(if $(abi-includes), \
+ $(foreach h,$(abi-includes), echo '#include <$(h)>';) \
+ echo '';) \
+ $(foreach v,$(abi-variants),\
+ $(if $(abi-$(v)-condition),\
+ echo '#if $(abi-$(v)-condition)'; \
+ echo '# include <gnu/lib-names-$(v).h>'); \
+ $(if $(abi-$(v)-condition),echo '#endif';)) \
+ echo ''; \
+ echo '#endif /* gnu/lib-names.h */'; \
+ } > $@
+endif
+$(common-objpfx)$(lib-names-h-abi): $(common-objpfx)$(lib-names-stmp-abi); @:
+$(common-objpfx)$(lib-names-stmp-abi): $(..)scripts/lib-names.awk \
+ $(common-objpfx)soversions.i
+ $(make-target-directory)
+ { \
+ $(if $(abi-variants), \
+ echo '/* This file is automatically generated. */';\
+ echo '#ifndef __GNU_LIB_NAMES_H'; \
+ echo '# error "Never use <$(lib-names-h-abi)> directly; include <gnu/lib-names.h> instead."'; \
+ echo '#endif';, \
+ echo '/* This file is automatically generated.';\
+ echo ' It defines macros to allow user program to find the shared'; \
+ echo ' library files which come as part of GNU libc. */'; \
+ echo '#ifndef __GNU_LIB_NAMES_H'; \
+ echo '#define __GNU_LIB_NAMES_H 1';) \
+ echo ''; \
+ ($(foreach s,$(all-sonames), echo $(s);)) \
+ | LC_ALL=C $(AWK) -f $(firstword $^) | LC_ALL=C sort; \
+ $(if $(abi-variants),, \
+ echo ''; \
+ echo '#endif /* gnu/lib-names.h */';) \
+ } > ${@:stmp=T}
+ $(move-if-change) ${@:stmp=T} ${@:stmp=h}
+ touch $@
+endif
+common-generated += $(lib-names-h-abi) $(lib-names-stmp-abi)
+endif
+\f
+###############################################################################
+# NOTE! Everything adding to before-compile needs to come before this point! #
+###############################################################################
+
# Generate an ordered list of implicit rules which find the source files in
# each sysdep directory. The old method was to use vpath to search all the
# sysdep directories. However, that had the problem that a .S file in a
# later directory would be chosen over a .c file in an earlier directory,
# which does not preserve the desired sysdeps ordering behavior.
-# System-dependent makefiles can put in `inhibit-sysdep-asm' wildcard
-# patterns matching sysdep directories whose assembly source files should
-# be suppressed.
-ifdef inhibit-sysdep-asm
-define check-inhibit-asm
-case $$sysdir in $(subst $(empty) ,|,$(inhibit-sysdep-asm))) asm= ;; esac;
-endef
-endif
+# System-dependent makefiles can put in `inhibit-sysdep-asm' regexps
+# matching sysdep directories whose assembly source files should be
+# suppressed.
-include $(common-objpfx)sysd-rules
ifneq ($(sysd-rules-sysdirs),$(config-sysdirs))
sysd-rules-force = FORCE
FORCE:
endif
-$(common-objpfx)sysd-rules: $(common-objpfx)config.make $(..)Makerules \
+$(common-objpfx)sysd-rules: $(..)scripts/sysd-rules.awk \
+ $(common-objpfx)config.make $(..)Makerules \
$(sysdep-makefiles) $(sysdep-makeconfigs) \
$(sysd-rules-force)
-@rm -f $@T
- (echo 'sysd-rules-sysdirs := $(config-sysdirs)'; \
- for dir in $(config-sysdirs); do \
- case "$$dir" in \
- /*) ;; \
- *) dir="\$$(..)$$dir" ;; \
- esac; \
- asm='.S .s'; \
- $(check-inhibit-asm) \
- for o in $(all-object-suffixes); do \
- set $(subst :, ,$(sysd-rules-patterns)); \
- while [ $$# -ge 2 ]; do \
- t=$$1; shift; \
- d=$$1; shift; \
- v=$${t%%%}; [ x"$$v" = x ] || v="\$$($${v}CPPFLAGS)"; \
- for s in $$asm .c; do \
- echo "\$$(objpfx)$$t$$o: $$dir/$$d$$s \$$(before-compile)"; \
- echo " \$$(compile-command$$s) $$v"; \
- done; \
- done; \
- done; \
- echo "\$$(inst_includedir)/%.h: $$dir/%.h \$$(+force)"; \
- echo " \$$(do-install)"; \
- done; \
- echo 'sysd-rules-done = t') > $@T
+ LC_ALL=C $(AWK) -f $< > $@T \
+ -v all_object_suffixes='$(all-object-suffixes)' \
+ -v inhibit_sysdep_asm='$(inhibit-sysdep-asm)' \
+ -v sysd_rules_patterns='$(sysd-rules-patterns)' \
+ -v config_sysdirs='$(config-sysdirs)'
mv -f $@T $@
ifndef sysd-rules-done
object-suffixes-left := $(all-object-suffixes)
include $(o-iterator)
-define o-iterator-doit
-$(objpfx)%$o: %.s $(before-compile); $$(compile-command.s)
-endef
-object-suffixes-left := $(all-object-suffixes)
-include $(o-iterator)
-
define o-iterator-doit
$(objpfx)%$o: %.c $(before-compile); $$(compile-command.c)
endef
object-suffixes-left := $(all-object-suffixes)
include $(o-iterator)
-define o-iterator-doit
-$(objpfx)%$o: $(objpfx)%.s $(before-compile); $$(compile-command.s)
-endef
-object-suffixes-left := $(all-object-suffixes)
-include $(o-iterator)
-
define o-iterator-doit
$(objpfx)%$o: $(objpfx)%.c $(before-compile); $$(compile-command.c)
endef
# Generate version maps, but wait until sysdep-subdirs is known
ifeq ($(sysd-sorted-done),t)
-ifeq ($(versioning),yes)
+ifeq ($(build-shared),yes)
-include $(common-objpfx)sysd-versions
$(addprefix $(common-objpfx),$(version-maps)): $(common-objpfx)sysd-versions
common-generated += $(version-maps)
postclean-generated += sysd-versions Versions.all abi-versions.h \
- Versions.def.v.i Versions.def.v Versions.v.i Versions.v
+ Versions.def Versions.v.i Versions.v
ifndef avoid-generated
ifneq ($(sysd-versions-subdirs),$(sorted-subdirs) $(config-sysdirs))
sysd-versions-force = FORCE
FORCE:
endif
-# See %.v/%.v.i implicit rules in Makeconfig.
-$(common-objpfx)Versions.def.v.i: $(..)Versions.def \
- $(wildcard $(add-ons:%=$(..)%/Versions.def))
+
+$(common-objpfx)Versions.def: $(..)scripts/versionlist.awk \
+ $(common-objpfx)Versions.v
+ LC_ALL=C $(AWK) -f $^ > $@T
+ mv -f $@T $@
+
$(common-objpfx)Versions.all: $(..)scripts/firstversions.awk \
$(common-objpfx)soversions.i \
- $(common-objpfx)Versions.def.v
+ $(common-objpfx)Versions.def
{ while read which lib version setname; do \
test x"$$which" = xDEFAULT || continue; \
test -z "$$setname" || echo "$$lib : $$setname"; \
# See %.v/%.v.i implicit rules in Makeconfig.
$(common-objpfx)Versions.v.i: $(wildcard $(subdirs:%=$(..)%/Versions)) \
$(wildcard $(sysdirs:%=%/Versions)) \
- $(common-objpfx)abi-versions.h \
$(sysd-versions-force)
-$(common-objpfx)sysd-versions: $(common-objpfx)Versions.all \
+$(common-objpfx)sysd-versions: $(common-objpfx)versions.stmp
+$(common-objpfx)versions.stmp: $(common-objpfx)Versions.all \
$(common-objpfx)Versions.v \
$(..)scripts/versions.awk
( echo 'sysd-versions-subdirs = $(subdirs) $(config-sysdirs)' ; \
| LC_ALL=C $(AWK) -v buildroot=$(common-objpfx) -v defsfile=$< \
-v move_if_change='$(move-if-change)' \
-f $(word 3,$^); \
- ) > $@T
- mv -f $@T $@
+ ) > $(common-objpfx)sysd-versionsT
+ mv -f $(common-objpfx)sysd-versionsT $(common-objpfx)sysd-versions
+ touch $@
endif # avoid-generated
-endif # $(versioning) = yes
+endif # $(build-shared) = yes
endif # sysd-sorted-done
# Generate .dT files as we compile.
compile-mkdep-flags = -MD -MP -MF $@.dt -MT $@
compile-command.S = $(compile.S) $(OUTPUT_OPTION) $(compile-mkdep-flags)
-compile-command.s = $(COMPILE.s) $< $(OUTPUT_OPTION) $(compile-mkdep-flags)
compile-command.c = $(compile.c) $(OUTPUT_OPTION) $(compile-mkdep-flags)
compile-command.cc = $(compile.cc) $(OUTPUT_OPTION) $(compile-mkdep-flags)
compile.cc = $(CXX) $< -c $(CXXFLAGS) $(CPPFLAGS)
compile.S = $(CC) $< -c $(CPPFLAGS) $(S-CPPFLAGS) \
$(ASFLAGS) $(ASFLAGS-$(suffix $@))
+COMPILE.c = $(CC) -c $(CFLAGS) $(CPPFLAGS)
COMPILE.S = $(CC) -c $(CPPFLAGS) $(S-CPPFLAGS) \
$(ASFLAGS) $(ASFLAGS-$(suffix $@))
-COMPILE.s = $(filter-out -pipe,$(CC)) -c $(ASFLAGS)
# We need this for the output to go in the right place. It will default to
# empty if make was configured to work with a cc that can't grok -c and -o
# together. You can't compile the C library with such a compiler.
OUTPUT_OPTION = -o $@
+# This is the end of the pipeline for compiling generated C code.
+compile-stdin.c = $(COMPILE.c) -o $@ -x c - $(compile-mkdep-flags)
+
# We need the $(CFLAGS) to be in there to have the right predefines during
# the dependency run for C sources. But having it for assembly sources can
# get the wrong predefines.
endif
endif
-# Bounded pointer thunks are only built for *.ob
-elide-bp-thunks = $(addprefix $(bppfx),$(bp-thunks))
-
elide-routines.oS += $(filter-out $(static-only-routines),\
- $(routines) $(aux) $(sysdep_routines)) \
- $(elide-bp-thunks)
-elide-routines.os += $(static-only-routines) $(elide-bp-thunks)
+ $(routines) $(aux) $(sysdep_routines))
+elide-routines.os += $(static-only-routines)
# If we have versioned code we don't need the old versions in any of the
# static libraries.
-elide-routines.o += $(shared-only-routines) $(elide-bp-thunks)
-elide-routines.op += $(shared-only-routines) $(elide-bp-thunks)
-elide-routines.og += $(shared-only-routines) $(elide-bp-thunks)
-elide-routines.ob += $(shared-only-routines)
+elide-routines.o += $(shared-only-routines)
+elide-routines.op += $(shared-only-routines)
\f
# Shared library building.
ifeq (yes,$(build-shared))
-# Reference map file only when versioning is selected and a map file name
+# Reference map file only when shared libraries are built and a map file name
# is given.
-ifeq ($(versioning),yes)
+ifeq ($(build-shared),yes)
map-file = $(firstword $($(@F:.so=-map)) \
$(addprefix $(common-objpfx), \
$(filter $(@F:.so=.map),$(version-maps))))
load-map-file = $(map-file:%=-Wl,--version-script=%)
endif
+# Compiler arguments to use to link a shared object with libc and
+# ld.so. This is intended to be as similar as possible to a default
+# link with an installed libc.
+link-libc-args = -Wl,--start-group \
+ $(libc-for-link) \
+ $(common-objpfx)libc_nonshared.a \
+ $(as-needed) $(elf-objpfx)ld.so $(no-as-needed) \
+ -Wl,--end-group
+
+# The corresponding shared libc to use. This may be modified for a
+# particular target.
+libc-for-link = $(common-objpfx)libc.so
+
+# The corresponding dependencies. As these are used in dependencies,
+# not just commands, they cannot use target-specific variables so need
+# to name both possible libc.so objects.
+link-libc-deps = $(common-objpfx)libc.so $(common-objpfx)linkobj/libc.so \
+ $(common-objpfx)libc_nonshared.a $(elf-objpfx)ld.so
+
# Pattern rule to build a shared object from an archive of PIC objects.
# This must come after the installation rules so Make doesn't try to
# build shared libraries in place from the installed *_pic.a files.
# $(LDLIBS-%.so) may contain -l switches to generate run-time dependencies
-# on other shared objects.
-lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(+interp)
- $(build-shlib)
+# on other shared objects. The linking with libc and ld.so is intended
+# to be as similar as possible to a default link with an installed libc.
+lib%.so: lib%_pic.a $(+preinit) $(+postinit) $(link-libc-deps)
+ $(build-shlib) $(link-libc-args)
+ $(call after-link,$@)
define build-shlib-helper
-$(LINK.o) -shared $(static-libgcc) -Wl,-O1 $(sysdep-LDFLAGS) \
- $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(config-LDFLAGS) \
+$(LINK.o) -shared -static-libgcc -Wl,-O1 $(sysdep-LDFLAGS) \
+ $(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) $(rtld-LDFLAGS) \
$(extra-B-$(@F:lib%.so=%).so) -B$(csu-objpfx) \
$(extra-B-$(@F:lib%.so=%).so) $(load-map-file) \
-Wl,-soname=lib$(libprefix)$(@F:lib%.so=%).so$($(@F)-version) \
- $(LDFLAGS.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
+ $(LDFLAGS.so) $(LDFLAGS-lib.so) $(LDFLAGS-$(@F:lib%.so=%).so) \
-L$(subst :, -L,$(rpath-link)) -Wl,-rpath-link=$(rpath-link)
endef
$(common-objpfx)shlib.lds: $(common-objpfx)config.make $(..)Makerules
$(LINK.o) -shared -Wl,-O1 \
-nostdlib -nostartfiles \
- $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
+ $(sysdep-LDFLAGS) $(rtld-LDFLAGS) $(LDFLAGS.so) \
-Wl,--verbose 2>&1 | \
sed > $@T \
-e '/^=========/,/^=========/!d;/^=========/d' \
PROVIDE(__start___libc_atexit = .);\
__libc_atexit : { *(__libc_atexit) }\
PROVIDE(__stop___libc_atexit = .);\
- PROVIDE(__start___libc_thread_subfreeres = .);\
- __libc_thread_subfreeres : { *(__libc_thread_subfreeres) }\
- PROVIDE(__stop___libc_thread_subfreeres = .);\
+ PROVIDE(__start___libc_IO_vtables = .);\
+ __libc_IO_vtables : { *(__libc_IO_vtables) }\
+ PROVIDE(__stop___libc_IO_vtables = .);\
/DISCARD/ : { *(.gnu.glibc-stub.*) }@'
test -s $@T
mv -f $@T $@
endef
define build-module-helper
-$(LINK.o) -shared $(static-libgcc) $(sysdep-LDFLAGS) $(config-LDFLAGS) \
+$(LINK.o) -shared -static-libgcc $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
$(if $($(@F)-no-z-defs)$(no-z-defs),,-Wl,-z,defs) \
-B$(csu-objpfx) $(load-map-file) \
$(LDFLAGS.so) $(LDFLAGS-$(@F:%.so=%).so) \
# not for shared objects
define build-module
$(build-module-helper) -o $@ $(shlib-lds-flags) \
- $(csu-objpfx)abi-note.o $(build-module-objlist)
+ $(csu-objpfx)abi-note.o $(build-module-objlist) $(link-libc-args)
+$(call after-link,$@)
endef
define build-module-asneeded
$(build-module-helper) -o $@ $(shlib-lds-flags) \
$(csu-objpfx)abi-note.o \
- -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed
+ -Wl,--as-needed $(build-module-objlist) -Wl,--no-as-needed \
+ $(link-libc-args)
+$(call after-link,$@)
endef
+# sofini.os must be placed last since it terminates .eh_frame section.
build-module-helper-objlist = \
$(patsubst %_pic.a,$(whole-archive) %_pic.a $(no-whole-archive),\
- $(filter-out %.lds $(map-file) $(+preinit) $(+postinit),$^))
+ $(filter-out %.lds $(map-file) $(+preinit) $(+postinit) \
+ $(elf-objpfx)sofini.os \
+ $(link-libc-deps),$^))
build-module-objlist = $(build-module-helper-objlist) $(LDLIBS-$(@F:%.so=%).so)
build-shlib-objlist = $(build-module-helper-objlist) \
- $(LDLIBS-$(@F:lib%.so=%).so)
+ $(LDLIBS-$(@F:lib%.so=%).so) \
+ $(filter $(elf-objpfx)sofini.os,$^)
# Don't try to use -lc when making libc.so itself.
# Also omits crti.o and crtn.o, which we do not want
LDLIBS-c.so += $(libc.so-gnulib)
# Give libc.so an entry point and make it directly runnable itself.
LDFLAGS-c.so += -e __libc_main
-# If lazy relocation is disabled add the -z now flag.
-ifeq ($(bind-now),yes)
-LDFLAGS-c.so += -Wl,-z,now
-endif
# Pre-link the objects of libc_pic.a so that we can locally resolve
# COMMON symbols before we link against ld.so. This is because ld.so
# contains some of libc_pic.a already, which will prevent the COMMONs
libc_pic_clean := .clean
endif
-# Use our own special initializer and finalizer files for libc.so.
-$(common-objpfx)libc.so: $(elfobjdir)/soinit.os \
+# Build a possibly-modified version of libc_pic.a for use in building
+# linkobj/libc.so.
+ifeq (,$(filter sunrpc,$(subdirs)))
+$(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a
+ $(make-target-directory)
+ ln -f $< $@
+else
+$(common-objpfx)linkobj/libc_pic.a: $(common-objpfx)libc_pic.a \
+ $(common-objpfx)sunrpc/librpc_compat_pic.a
+ $(make-target-directory)
+ (cd $(common-objpfx)linkobj; \
+ $(AR) x ../libc_pic.a; \
+ rm $$($(AR) t ../sunrpc/librpc_compat_pic.a | sed 's/^compat-//'); \
+ $(AR) x ../sunrpc/librpc_compat_pic.a; \
+ $(AR) cr libc_pic.a *.os; \
+ rm *.os)
+endif # $(subdirs) contains sunrpc
+
+# Clear link-libc-deps for the libc.so libraries so build-shlibs does not
+# filter ld.so out of the list of linked objects.
+$(common-objpfx)libc.so: link-libc-deps = # empty
+$(common-objpfx)linkobj/libc.so: link-libc-deps = # empty
+
+# Use our own special initializer and finalizer files for the libc.so
+# libraries.
+$(common-objpfx)libc.so: $(elf-objpfx)soinit.os \
$(common-objpfx)libc_pic.os$(libc_pic_clean) \
- $(elfobjdir)/sofini.os \
- $(elfobjdir)/interp.os $(elfobjdir)/ld.so \
+ $(elf-objpfx)sofini.os \
+ $(elf-objpfx)interp.os \
+ $(elf-objpfx)ld.so \
+ $(shlib-lds)
+ $(build-shlib)
+ $(call after-link,$@)
+
+$(common-objpfx)linkobj/libc.so: $(elf-objpfx)soinit.os \
+ $(common-objpfx)linkobj/libc_pic.a \
+ $(elf-objpfx)sofini.os \
+ $(elf-objpfx)interp.os \
+ $(elf-objpfx)ld.so \
$(shlib-lds)
$(build-shlib)
-ifeq ($(versioning),yes)
+ $(call after-link,$@)
+
+ifeq ($(build-shared),yes)
$(common-objpfx)libc.so: $(common-objpfx)libc.map
endif
common-generated += libc.so libc_pic.os
# This is the list of all object files, gotten by
# replacing every ".c" in `sources' with a ".o".
-# We also add bounded-pointer thunks, which are later
-# elided for all suffixes except for `.ob'.
-override objects := $(addprefix $(objpfx),$(sources:.c=.o) \
- $(patsubst %,$(bppfx)%.o,\
- $(filter $(routines) $(sysdep_routines),$(bp-thunks))))
+override objects := $(addprefix $(objpfx),$(sources:.c=.o))
# The makefile may define $(extra-libs) with `libfoo libbar'
# The makefile may define $(modules-names) to build additional modules.
# These are built with $(build-module), except any in $(modules-names-nobuild).
+# MODULE_NAME=extramodules, except any in $(modules-names-tests).
ifdef modules-names
-# extra-lib.mk is included once for each extra lib to define rules
-# to build it, and to add its objects to the various variables.
-# During its evaluation, $(lib) is set to the name of the library.
-extra-modules-left := $(modules-names)
-include $(patsubst %,$(..)extra-modules.mk,$(modules-names))
+cpp-srcs-left := $(filter-out $(modules-names-tests),$(modules-names))
+ifneq (,$(cpp-srcs-left))
+lib := extramodules
+include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
+endif
+
+ifdef modules-names-tests
+cpp-srcs-left := $(filter $(modules-names-tests),$(modules-names))
+ifneq (,$(cpp-srcs-left))
+lib := testsuite
+include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
+endif
+endif
extra-modules-build := $(filter-out $(modules-names-nobuild),$(modules-names))
$(extra-modules-build:%=$(objpfx)%.so): $(objpfx)%.so: \
- $(objpfx)%.os $(shlib-lds) \
- $(common-objpfx)libc.so $(common-objpfx)libc_nonshared.a
+ $(objpfx)%.os $(shlib-lds) $(link-libs-deps)
$(build-module)
endif
\f
$(patsubst %.o,%.d,$(filter %.o,$(extra-objs:.os=.o))) \
$(patsubst %.oS,%.d,$(filter %.oS,$(extra-objs))) \
$(patsubst %.o,%.d,$(filter %.o,$(extra-test-objs:.os=.o))) \
- $(addsuffix .d,$(tests) $(xtests) $(test-srcs))
+ $(addsuffix .d,$(tests) $(tests-internal) $(xtests) $(test-srcs))
ifeq ($(build-programs),yes)
+depfiles += $(addsuffix .d,$(others) $(sysdep-others))
endif
installed-libcs := $(foreach o,$(filter-out .os,$(object-suffixes-for-libc)),\
$(inst_libdir)/$(patsubst %,$(libtype$o),\
$(libprefix)$(libc-name)))
+
+.PHONY: check-install-supported
+check-install-supported:
+
+# Check to see if the prefix or exec_prefix GNU standard variable
+# has been overridden on the command line and, if so, fail with
+# an error message since doing so is not supported (set DESTDIR
+# instead).
+ifeq ($(origin prefix),command line)
+check-install-supported:
+ $(error Overriding prefix is not supported. Set DESTDIR instead.)
+endif
+
+ifeq ($(origin exec_prefix),command line)
+check-install-supported:
+ $(error Overriding exec_prefix is not supported. Set DESTDIR instead.)
+endif
+
+install: check-install-supported
+
install: $(installed-libcs)
$(installed-libcs): $(inst_libdir)/lib$(libprefix)%: lib $(+force)
$(make-target-directory)
# $(inst_libdir)/libfoo.so -- for linking, symlink or ld script
# $(inst_slibdir)/libfoo.so.NN -- for loading by SONAME, symlink
# $(inst_slibdir)/libfoo-X.Y.Z.so -- the real shared object file
-V := $(firstword $($(subdir)-version) $(version))
+lib-version := $(firstword $($(subdir)-version) $(version))
install-lib-nosubdir: $(install-lib.so-unversioned:%=$(inst_slibdir)/%) \
$(foreach L,$(install-lib.so-versioned),\
$(inst_libdir)/$L \
- $(inst_slibdir)/$(L:.so=)-$V.so \
+ $(inst_slibdir)/$(L:.so=)-$(lib-version).so \
$(inst_slibdir)/$L$($L-version))
# Install all the unversioned shared libraries.
$(SHELL) $(..)scripts/rellns-sh $< $@.new
mv -f $@.new $@
endef
+define make-link-multidir
+$(patsubst %/,cd %,$(objpfx)); \
+ $(addprefix $(abspath $(..)scripts/mkinstalldirs) ,$(dir $(multidir))); \
+ $(LN_S) . $(multidir) 2> /dev/null; \
+ test -L $(multidir)
+endef
else
# If we have no symbolic links don't bother with rellns-sh.
define make-link
$(LN_S) $< $@.new
mv -f $@.new $@
endef
+define make-link-multidir
+$(make-target-directory)
+ln -f $(objpfx)/$(@F) $@
+endef
endif
ifeq (yes,$(build-shared))
ifeq (no,$(cross-compiling))
-symbolic-link-prog := $(common-objpfx)elf/sln
-symbolic-link-list := $(common-objpfx)elf/symlink.list
+symbolic-link-prog := $(elf-objpfx)sln
+symbolic-link-list := $(elf-objpfx)symlink.list
define make-shlib-link
-echo $(<F) $@ >> $(symbolic-link-list)
+echo `$(..)scripts/rellns-sh -p $< $@` $@ >> $(symbolic-link-list)
endef
else # cross-compiling
# We need a definition that can be used by elf/Makefile's install rules.
ifndef make-shlib-link
define make-shlib-link
rm -f $@
-$(LN_S) $(<F) $@
+$(LN_S) `$(..)scripts/rellns-sh -p $< $@` $@
endef
endif
ifneq (unknown,$(output-format))
echo > $@.new 'OUTPUT_FORMAT($(output-format))'
else
- $(LINK.o) -shared $(sysdep-LDFLAGS) $(config-LDFLAGS) $(LDFLAGS.so) \
+ $(LINK.o) -shared $(sysdep-LDFLAGS) $(rtld-LDFLAGS) \
+ $(LDFLAGS.so) $(LDFLAGS-lib.so) \
-x c /dev/null -o $@.so -Wl,--verbose -v 2>&1 \
| sed -n -f $< > $@.new
test -s $@.new
cat $<; \
echo 'GROUP ( $(slibdir)/libc.so$(libc.so-version)' \
'$(libdir)/$(patsubst %,$(libtype.oS),$(libprefix)$(libc-name))'\
- ' AS_NEEDED (' $(slibdir)/$(rtld-installed-name) ') )' \
+ ' AS_NEEDED (' $(rtlddir)/$(rtld-installed-name) ') )' \
) > $@.new
mv -f $@.new $@
define do-install-so
$(do-install-program)
-$(patsubst %,ln -s -f $(@F) $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
+$(patsubst %,$(LN_S) -f $(@F) \
+ $(@D)/$(patsubst %$*.so,%,$(<F))$(libprefix)$*.so,\
$(filter-out %.so,$@))
endef
endif
ifdef install-lib
install-lib.a := $(filter lib%.a,$(install-lib))
+install-lib.a := $(filter-out $(install-lib-ldscripts),$(install-lib.a))
install-lib-non.a := $(filter-out lib%.a,$(install-lib))
ifdef install-lib-non.a
$(addprefix $(inst_libdir)/$(libprefix),$(install-lib-non.a)): \
.PHONY: xcheck
xcheck: xtests
-all-nonlib = $(strip $(tests) $(xtests) $(test-srcs) $(test-extras) $(others))
+# The only difference between MODULE_NAME=testsuite and MODULE_NAME=nonlib is
+# that almost all internal declarations from config.h, libc-symbols.h, and
+# include/*.h are not available to 'testsuite' code, but are to 'nonlib' code.
+all-testsuite := $(strip $(tests) $(xtests) $(test-srcs) $(test-extras))
+ifneq (,$(all-testsuite))
+cpp-srcs-left = $(all-testsuite)
+lib := testsuite
+include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
+endif
+
+all-nonlib := $(strip $(tests-internal) $(test-internal-extras) \
+ $(others) $(others-extras))
ifneq (,$(all-nonlib))
-cpp-srcs-left = $(all-nonlib:=.c) $(all-nonlib:=.cc)
+cpp-srcs-left = $(all-nonlib)
lib := nonlib
-include $(patsubst %,$(..)cppflags-iterator.mk,$(cpp-srcs-left))
+include $(patsubst %,$(..)libof-iterator.mk,$(cpp-srcs-left))
endif
-# The include magic above causes those files to use this variable for flags.
-CPPFLAGS-nonlib = -DNOT_IN_libc=1
-
-ifeq ($(versioning),yes)
+ifeq ($(build-shared),yes)
# Generate normalized lists of symbols, versions, and data sizes.
# This is handy for checking against existing library binaries.
mv -f $@T $@
%.dynsym: %.so
- $(OBJDUMP) --dynamic-syms $< > $@T
+ LC_ALL=C $(OBJDUMP) --dynamic-syms $< > $@T
mv -f $@T $@
+# A sysdeps/.../Makefile can set abilist-pattern to something like
+# %-foo.abilist to look for libc-foo.abilist instead of libc.abilist.
+# This makes sense if multiple ABIs can be most cleanly supported by a
+# configuration without using separate sysdeps directories for each.
+ifdef abilist-pattern
+vpath $(abilist-pattern) $(+sysdep_dirs)
+endif
+
vpath %.abilist $(+sysdep_dirs)
# The .PRECIOUS rule prevents the files built by an implicit rule whose
.PRECIOUS: %.symlist
generated += $(extra-libs:=.symlist)
-check-abi-%: $(common-objpfx)config.make %.abilist $(objpfx)%.symlist
- $(check-abi)
-check-abi-%: $(common-objpfx)config.make %.abilist $(common-objpfx)%.symlist
- $(check-abi)
+ifdef abilist-pattern
+$(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
+ $(objpfx)%.symlist
+ $(check-abi-pattern); \
+ $(evaluate-test)
+$(objpfx)check-abi-%.out: $(common-objpfx)config.make $(abilist-pattern) \
+ $(common-objpfx)%.symlist
+ $(check-abi-pattern); \
+ $(evaluate-test)
+endif
+$(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
+ $(objpfx)%.symlist
+ $(check-abi); \
+ $(evaluate-test)
+$(objpfx)check-abi-%.out: $(common-objpfx)config.make %.abilist \
+ $(common-objpfx)%.symlist
+ $(check-abi); \
+ $(evaluate-test)
+define check-abi-pattern
+ diff -p -U 0 $(filter $(abilist-pattern),$^) $(filter %.symlist,$^) \
+ > $@
+endef
define check-abi
- diff -p -U 0 $(filter %.abilist,$^) $(filter %.symlist,$^)
+ diff -p -U 0 $(filter %.abilist,$^) $(filter %.symlist,$^) > $@
endef
+ifdef abilist-pattern
+update-abi-%: $(objpfx)%.symlist $(abilist-pattern)
+ $(update-abi-pattern)
+update-abi-%: $(common-objpfx)%.symlist $(abilist-pattern)
+ $(update-abi-pattern)
+endif
update-abi-%: $(objpfx)%.symlist %.abilist
$(update-abi)
update-abi-%: $(common-objpfx)%.symlist %.abilist
$(update-abi)
+define update-abi-pattern
+@if cmp -s $^ 2> /dev/null; \
+ then \
+ echo '+++ $(filter $(abilist-pattern),$^) is unchanged'; \
+ else cp -f $^; \
+ echo '*** Now check $(filter $(abilist-pattern),$^) changes for correctness ***'; \
+ fi
+endef
define update-abi
@if cmp -s $^ 2> /dev/null; \
then \
fi
endef
-.PHONY: update-abi check-abi
+# Patch all .abilist files for one DSO. The find command locates
+# abilist files for all architectures. The regular expression in the
+# find invocation is needed to separate libc.abilist and
+# libcrypt.abilist, for example. It assumes that abilist-pattern, if
+# set, is of the form "%-SUFFIX", and not "%SUFFIX", that is, there is
+# a non-alphanumeric seperator between the pattern and the suffix
+# added. The abilist files in /generic/ are filtered out because
+# these are expected to remain empty.
+define update-all-abi
+$(SHELL) $(..)scripts/update-abilist.sh $^ \
+ $$(find $(..)sysdeps \
+ -regextype posix-egrep -regex '.*/$*([^a-z0-9].*)?\.abilist$$' \
+ \! -regex '.*/generic/.*')
+endef
+ifdef abilist-pattern
+update-all-abi-%: $(abilist-pattern) $(objpfx)%.symlist
+ $(update-all-abi)
+update-all-abi-%: $(abilist-pattern) $(common-objpfx)%.symlist
+ $(update-all-abi)
+endif
+update-all-abi-%: %.abilist $(objpfx)%.symlist
+ $(update-all-abi)
+update-all-abi-%: %.abilist $(common-objpfx)%.symlist
+ $(update-all-abi)
+
+.PHONY: update-abi update-all-abi check-abi
update-abi: $(patsubst %.so,update-abi-%,$(install-lib.so-versioned))
-check-abi: $(patsubst %.so,check-abi-%,$(install-lib.so-versioned))
+update-all-abi: $(patsubst %.so,update-all-abi-%,$(install-lib.so-versioned))
+check-abi-list = $(patsubst %.so,$(objpfx)check-abi-%.out, \
+ $(install-lib.so-versioned))
+check-abi: $(check-abi-list)
ifdef subdir
subdir_check-abi: check-abi
subdir_update-abi: update-abi
+subdir_update-all-abi: update-all-abi
else
check-abi: subdir_check-abi
+ if grep -q '^FAIL:' $(objpfx)*/check-abi*.test-result; then \
+ cat $(objpfx)*/check-abi*.out && exit 1; fi
update-abi: subdir_update-abi
+update-all-abi: subdir_update-all-abi
endif
ifeq ($(subdir),elf)
-check-abi: check-abi-libc
+check-abi: $(objpfx)check-abi-libc.out
+tests-special += $(objpfx)check-abi-libc.out
update-abi: update-abi-libc
+update-all-abi: update-all-abi-libc
common-generated += libc.symlist
endif
ifeq ($(build-shared),yes)
ifdef subdir
-tests: check-abi
+tests-special += $(check-abi-list)
endif
endif
endif
-
+\f
# These will have been set by sysdeps/posix/Makefile.
L_tmpnam ?= 1
TMP_MAX ?= 0
$(common-objpfx)config.make
$(make-target-directory)
{ echo '#include "$(..)posix/bits/posix1_lim.h"'; \
- echo '#define _LIBC 1'; \
- echo '#include "$(..)misc/sys/uio.h"'; } | \
+ } | \
$(CC) -E -dM -MD -MP -MF $(@:st=dT) -MT '$(@:st=h) $(@:st=d)' \
- $(+includes) -xc - -o $(@:st=hT)
+ $(CPPUNDEFS) $(+includes) -xc - -o $(@:st=hT)
sed $(sed-remove-objpfx) $(sed-remove-dotdot) \
$(@:st=dT) > $(@:st=dt)
mv -f $(@:st=dt) $(@:st=d)
fopen_max=`sed -n 's/^#define OPEN_MAX //1p' $(@:st=hT)`; \
filename_max=`sed -n 's/^#define PATH_MAX //1p' $(@:st=hT)`; \
- iov_max=`sed -n 's/^#define UIO_MAXIOV //p' $(@:st=hT)`; \
fopen_max=$${fopen_max:-16}; \
filename_max=$${filename_max:-1024}; \
- if [ -z "$$iov_max" ]; then \
- define_iov_max="# undef IOV_MAX"; \
- else \
- define_iov_max="# define IOV_MAX $$iov_max"; \
- fi; \
sed -e "s/@FOPEN_MAX@/$$fopen_max/" \
-e "s/@FILENAME_MAX@/$$filename_max/" \
-e "s/@L_tmpnam@/$(L_tmpnam)/" \
-e "s/@TMP_MAX@/$(TMP_MAX)/" \
-e "s/@L_ctermid@/$(L_ctermid)/" \
-e "s/@L_cuserid@/$(L_cuserid)/" \
- -e "s/@define_IOV_MAX@/$$define_iov_max/" \
$< > $(@:st=h.new)
$(move-if-change) $(@:st=h.new) $(@:st=h)
# Remove these last so that they can be examined if something went wrong.
mostlyclean: common-mostlyclean
do-tests-clean:
- -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) $(xtests) \
+ -rm -f $(addprefix $(objpfx),$(addsuffix .out,$(tests) \
+ $(tests-internal) \
+ $(xtests) \
$(test-srcs)) \
- $(addsuffix -bp.out,$(tests) $(xtests) \
- $(test-srcs)))
+ $(addsuffix .test-result,$(tests) \
+ $(tests-internal) \
+ $(xtests) \
+ $(test-srcs)))
# Remove the object files.
common-mostlyclean:
- -rm -f $(addprefix $(objpfx),$(tests) $(xtests) $(test-srcs) \
+ -rm -f $(addprefix $(objpfx),$(tests) $(tests-internal) $(xtests) \
+ $(test-srcs) \
$(others) $(sysdep-others) stubs \
- $(addsuffix .o,$(tests) $(xtests) \
- $(test-srcs) $(others) \
+ $(addsuffix .o,$(tests) \
+ $(tests-internal) \
+ $(xtests) \
+ $(test-srcs) \
+ $(others) \
$(sysdep-others)) \
- $(addsuffix -bp,$(tests) $(xtests) \
- $(test-srcs)) \
- $(addsuffix .out,$(tests) $(xtests) \
+ $(addsuffix .out,$(tests) \
+ $(tests-internal) \
+ $(xtests) \
$(test-srcs)) \
- $(addsuffix -bp.out,$(tests) $(xtests) \
- $(test-srcs)))
+ $(addsuffix .test-result,$(tests) \
+ $(tests-internal) \
+ $(xtests) \
+ $(test-srcs)))
-rm -f $(addprefix $(objpfx),$(extra-objs) $(extra-test-objs) \
$(install-lib) $(install-lib.so) \
$(install-lib.so:%.so=%_pic.a))
-rm -f $(gen-as-const-headers:%.sym=$(common-objpfx)%.h)
\f
# Produce a file `stubs' which contains `#define __stub_FUNCTION'
-# for each function which is a stub. We grovel over all the .d files
-# looking for references to <stub-tag.h>. Then we grovel over each
-# referenced source file to see what stub function it defines.
+# for each function which is a stub.
ifdef objpfx
.PHONY: stubs # The parent Makefile calls this target.