]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - elf/Makefile
nptl: Move stack list variables into _rtld_global
[thirdparty/glibc.git] / elf / Makefile
index 72a5aa88b1025e76c95126832a8049b354759dec..2015383eb2207c60edffbe2c6d84b38fb0119ca2 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright (C) 1995-2019 Free Software Foundation, Inc.
+# Copyright (C) 1995-2020 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
@@ -25,15 +25,17 @@ headers             = elf.h bits/elfclass.h link.h bits/link.h
 routines       = $(all-dl-routines) dl-support dl-iteratephdr \
                  dl-addr dl-addr-obj enbl-secure dl-profstub \
                  dl-origin dl-libc dl-sym dl-sysdep dl-error \
-                 dl-reloc-static-pie
+                 dl-reloc-static-pie libc_early_init
 
 # The core dynamic linking functions are in libc for the static and
 # profiled libraries.
-dl-routines    = $(addprefix dl-,load lookup object reloc deps hwcaps \
+dl-routines    = $(addprefix dl-,load lookup object reloc deps \
                                  runtime init fini debug misc \
                                  version profile tls origin scope \
                                  execstack open close trampoline \
-                                 exception sort-maps)
+                                 exception sort-maps lookup-direct \
+                                 call-libc-early-init write \
+                                 thread_gscope_wait)
 ifeq (yes,$(use-ldconfig))
 dl-routines += dl-cache
 endif
@@ -53,12 +55,13 @@ endif
 all-dl-routines = $(dl-routines) $(sysdep-dl-routines)
 # But they are absent from the shared libc, because that code is in ld.so.
 elide-routines.os = $(all-dl-routines) dl-support enbl-secure dl-origin \
-                   dl-sysdep dl-exception dl-reloc-static-pie
+                   dl-sysdep dl-exception dl-reloc-static-pie \
+                   thread_gscope_wait
 
 # ld.so uses those routines, plus some special stuff for being the program
 # interpreter and operating independent of libc.
 rtld-routines  = rtld $(all-dl-routines) dl-sysdep dl-environ dl-minimal \
-  dl-error-minimal dl-conflict
+  dl-error-minimal dl-conflict dl-hwcaps dl-usage
 all-rtld-routines = $(rtld-routines) $(sysdep-rtld-routines)
 
 CFLAGS-dl-runtime.c += -fexceptions -fasynchronous-unwind-tables
@@ -97,7 +100,7 @@ ld-map               = $(common-objpfx)ld.map
 endif
 
 ifeq (yes,$(build-shared))
-extra-objs     = $(all-rtld-routines:%=%.os) soinit.os sofini.os interp.os
+extra-objs     = $(all-rtld-routines:%=%.os) sofini.os interp.os
 generated      += librtld.os dl-allobjs.os ld.so ldd
 install-others = $(inst_rtlddir)/$(rtld-installed-name)
 install-bin-script = ldd
@@ -154,7 +157,9 @@ endif
 tests-static-normal := tst-leaks1-static tst-array1-static tst-array5-static \
               tst-dl-iter-static \
               tst-tlsalign-static tst-tlsalign-extern-static \
-              tst-linkall-static tst-env-setuid tst-env-setuid-tunables
+              tst-linkall-static tst-env-setuid tst-env-setuid-tunables \
+              tst-single_threaded-static tst-single_threaded-pthread-static
+
 tests-static-internal := tst-tls1-static tst-tls2-static \
               tst-ptrguard1-static tst-stackguard1-static \
               tst-tls1-static-non-pie tst-libc_dlvsym-static
@@ -162,8 +167,9 @@ tests-static-internal := tst-tls1-static tst-tls2-static \
 CRT-tst-tls1-static-non-pie := $(csu-objpfx)crt1.o
 tst-tls1-static-non-pie-no-pie = yes
 
-tests-container = \
-                         tst-ldconfig-bad-aux-cache
+tests-container := \
+                         tst-ldconfig-bad-aux-cache \
+                         tst-ldconfig-ld_so_conf-update
 
 tests := tst-tls9 tst-leaks1 \
        tst-array1 tst-array2 tst-array3 tst-array4 tst-array5 \
@@ -172,9 +178,11 @@ tests-internal := tst-tls1 tst-tls2 $(tests-static-internal)
 tests-static := $(tests-static-normal) $(tests-static-internal)
 
 ifeq (yes,$(build-shared))
-tests-static += tst-tls9-static
-tst-tls9-static-ENV = \
-       LD_LIBRARY_PATH=$(objpfx):$(common-objpfx):$(common-objpfx)dlfcn
+tests-static += tst-tls9-static tst-single_threaded-static-dlopen
+static-dlopen-environment = \
+  LD_LIBRARY_PATH=$(objpfx):$(common-objpfx):$(common-objpfx)dlfcn
+tst-tls9-static-ENV = $(static-dlopen-environment)
+tst-single_threaded-static-dlopen-ENV = $(static-dlopen-environment)
 
 tests += restest1 preloadtest loadfail multiload origtest resolvfail \
         constload1 order noload filter \
@@ -199,13 +207,19 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \
         tst-debug1 tst-main1 tst-absolute-sym tst-absolute-zero tst-big-note \
         tst-unwind-ctor tst-unwind-main tst-audit13 \
         tst-sonamemove-link tst-sonamemove-dlopen tst-dlopen-tlsmodid \
-        tst-dlopen-self tst-auditmany tst-initfinilazyfail tst-dlopenfail
+        tst-dlopen-self tst-auditmany tst-initfinilazyfail tst-dlopenfail \
+        tst-dlopenfail-2 \
+        tst-filterobj tst-filterobj-dlopen tst-auxobj tst-auxobj-dlopen \
+        tst-audit14 tst-audit15 tst-audit16 \
+        tst-single_threaded tst-single_threaded-pthread \
+        tst-tls-ie tst-tls-ie-dlmopen \
+        argv0test
 #       reldep9
 tests-internal += loadtest unload unload2 circleload1 \
         neededtest neededtest2 neededtest3 neededtest4 \
         tst-tls3 tst-tls6 tst-tls7 tst-tls8 tst-dlmopen2 \
         tst-ptrguard1 tst-stackguard1 tst-libc_dlvsym \
-        tst-create_format1
+        tst-create_format1 tst-tls-surplus
 tests-container += tst-pldd tst-dlopen-tlsmodid-container \
   tst-dlopen-self-container
 test-srcs = tst-pathopt
@@ -309,7 +323,16 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
                tst-auditmanymod4 tst-auditmanymod5 tst-auditmanymod6 \
                tst-auditmanymod7 tst-auditmanymod8 tst-auditmanymod9 \
                tst-initlazyfailmod tst-finilazyfailmod \
-               tst-dlopenfailmod1 tst-dlopenfaillinkmod tst-dlopenfailmod2
+               tst-dlopenfailmod1 tst-dlopenfaillinkmod tst-dlopenfailmod2 \
+               tst-dlopenfailmod3 tst-ldconfig-ld-mod \
+               tst-filterobj-flt tst-filterobj-aux tst-filterobj-filtee \
+               tst-auditlogmod-1 tst-auditlogmod-2 tst-auditlogmod-3 \
+               tst-single_threaded-mod1 tst-single_threaded-mod2 \
+               tst-single_threaded-mod3 tst-single_threaded-mod4 \
+               tst-tls-ie-mod0 tst-tls-ie-mod1 tst-tls-ie-mod2 \
+               tst-tls-ie-mod3 tst-tls-ie-mod4 tst-tls-ie-mod5 \
+               tst-tls-ie-mod6
+
 # Most modules build with _ISOMAC defined, but those filtered out
 # depend on internal headers.
 modules-names-tests = $(filter-out ifuncmod% tst-libc_dlvsym-dso tst-tlsmod%,\
@@ -394,9 +417,10 @@ endif
 ifeq (yes,$(build-shared))
 ifeq ($(run-built-tests),yes)
 tests-special += $(objpfx)tst-pathopt.out $(objpfx)tst-rtld-load-self.out \
-                $(objpfx)tst-rtld-preload.out
+                $(objpfx)tst-rtld-preload.out $(objpfx)argv0test.out
 endif
 tests-special += $(objpfx)check-textrel.out $(objpfx)check-execstack.out \
+                $(objpfx)check-wx-segment.out \
                 $(objpfx)check-localplt.out $(objpfx)check-initfini.out
 endif
 
@@ -479,28 +503,37 @@ $(objpfx)dl-allobjs.os: $(all-rtld-routines:%=$(objpfx)%.os)
 # are compiled with special flags, and puts these modules into rtld-libc.a
 # for us.  Then we do the real link using rtld-libc.a instead of libc_pic.a.
 
-# If the compiler can do SSP, build the mapfile with dummy __stack_chk_fail
-# and __stack_chk_fail_local symbols defined, to prevent the real things
-# being dragged into rtld even though rtld is never built with stack-
-# protection.
+# These symbols need to be stubbed out during symbol discovery because
+# their implementation is provided differently in rtld, and the symbol
+# discovery mechanism is not compatible with the libc implementation
+# when compiled for libc.
+rtld-stubbed-symbols = \
+  calloc \
+  free \
+  malloc \
+  realloc \
+
+# The GCC arguments that implement $(rtld-stubbed-symbols).
+rtld-stubbed-symbols-args = \
+  $(patsubst %,-Wl$(comma)--defsym=%=0, $(rtld-stubbed-symbols))
 
 ifeq ($(have-ssp),yes)
-dummy-stack-chk-fail := -Wl,--defsym='__stack_chk_fail=0' \
-                       -Wl,--defsym='__stack_chk_fail_local=0'
-else
-dummy-stack-chk-fail :=
+# rtld is not built with the stack protector, so these references will
+# go away in the rebuilds.
+rtld-stubbed-symbols += __stack_chk_fail __stack_chk_fail_local
 endif
 
 $(objpfx)librtld.map: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
        @-rm -f $@T
-       $(reloc-link) -o $@.o $(dummy-stack-chk-fail) \
+       $(reloc-link) -o $@.o $(rtld-stubbed-symbols-args) \
                '-Wl,-(' $^ -lgcc '-Wl,-)' -Wl,-Map,$@T
        rm -f $@.o
        mv -f $@T $@
 
+# For lld, skip preceding addresses and values before matching the archive and the member.
 $(objpfx)librtld.mk: $(objpfx)librtld.map Makefile
        LC_ALL=C \
-       sed -n 's@^$(common-objpfx)\([^(]*\)(\([^)]*\.os\)) *.*$$@\1 \2@p' \
+       sed -n 's@^[0-9a-f ]*$(common-objpfx)\([^(]*\)(\([^)]*\.os\)) *.*$$@\1 \2@p' \
            $< | \
        while read lib file; do \
          case $$lib in \
@@ -587,6 +620,12 @@ ldso_install: $(inst_rtlddir)/$(rtld-installed-name)
 endif
 
 
+# Workarounds for ${exec_prefix} expansion in configure variables.
+# config.status cannot be used directly for processing ldd.bash.in or
+# expanding variables such as sysconfdir because the expansion
+# contains the literal string ${exec_prefix}, which is not valid in C
+# headers or installed shell scripts.
+
 ldd-rewrite = -e 's%@RTLD@%$(rtlddir)/$(rtld-installed-name)%g' \
              -e 's%@VERSION@%$(version)%g' \
              -e 's|@PKGVERSION@|$(PKGVERSION)|g' \
@@ -624,6 +663,8 @@ libof-ldconfig = ldconfig
 CFLAGS-dl-cache.c += $(SYSCONF-FLAGS)
 CFLAGS-cache.c += $(SYSCONF-FLAGS)
 CFLAGS-rtld.c += $(SYSCONF-FLAGS)
+CFLAGS-dl-usage.c += $(SYSCONF-FLAGS) \
+  -D'RTLD="$(rtlddir)/$(rtld-installed-name)"'
 
 cpp-srcs-left := $(all-rtld-routines:=.os)
 lib := rtld
@@ -916,7 +957,7 @@ $(objpfx)tst-pathopt: $(libdl)
 $(objpfx)tst-pathopt.out: tst-pathopt.sh $(objpfx)tst-pathopt \
                          $(objpfx)pathoptobj.so
        $(SHELL) $< $(common-objpfx) '$(test-wrapper-env)' \
-                '$(run-program-env)' > $@; \
+                '$(run-program-env)'; \
        $(evaluate-test)
 
 $(objpfx)tst-rtld-load-self.out: tst-rtld-load-self.sh $(objpfx)ld.so
@@ -928,7 +969,7 @@ $(objpfx)tst-rtld-preload.out: tst-rtld-preload.sh $(objpfx)ld.so \
                               $(objpfx)preloadtest \
                               $(preloadtest-preloads:%=$(objpfx)%.so)
        $(SHELL) $< $(objpfx)ld.so $(objpfx)preloadtest \
-                   '$(test-wrapper)' '$(test-wrapper-env)' '$(run_program_env)' \
+                   '$(test-wrapper-env)' '$(run_program_env)' \
                    '$(rpath-link)' '$(tst-rtld-preload-OBJS)' > $@; \
        $(evaluate-test)
 
@@ -1167,6 +1208,12 @@ $(objpfx)check-execstack.out: $(..)scripts/check-execstack.awk \
        $(evaluate-test)
 generated += check-execstack.out
 
+$(objpfx)check-wx-segment.out: $(..)scripts/check-wx-segment.py \
+                             $(all-built-dso:=.phdr)
+       $(PYTHON) $^ --xfail="$(check-wx-segment-xfail)" > $@; \
+       $(evaluate-test)
+generated += check-wx-segment.out
+
 $(objpfx)tst-dlmodcount: $(libdl)
 $(objpfx)tst-dlmodcount.out: $(test-modules)
 
@@ -1375,10 +1422,10 @@ $(objpfx)ifuncmain5picstatic: $(addprefix $(objpfx),ifuncdep5pic.o)
 LDFLAGS-tst-ifunc-fault-lazy = -Wl,-z,lazy
 LDFLAGS-tst-ifunc-fault-bindnow = -Wl,-z,now
 define tst-ifunc-fault-script
-( $(objpfx)ld.so --verify --library-path  $(objpfx) $^ \
-  && LD_TRACE_LOADED_OBJECTS=1 $(objpfx)ld.so --library-path $(objpfx) $^ \
-  && LD_TRACE_LOADED_OBJECTS=1 LD_DEBUG=unused \
-    $(objpfx)ld.so --library-path  $(objpfx) $^ \
+( $(test-wrapper) $(rtld-prefix) --verify $^ \
+  && $(test-wrapper-env) LD_TRACE_LOADED_OBJECTS=1 $(rtld-prefix) $^ \
+  && $(test-wrapper-env) LD_TRACE_LOADED_OBJECTS=1 LD_DEBUG=unused \
+                        $(rtld-prefix) $^ \
 ) > $@; $(evaluate-test)
 endef
 $(objpfx)tst-ifunc-fault-lazy.out: $(objpfx)tst-ifunc-fault-lazy $(objpfx)ld.so
@@ -1478,6 +1525,22 @@ $(objpfx)tst-auditmany.out: $(objpfx)tst-auditmanymod1.so \
 tst-auditmany-ENV = \
   LD_AUDIT=tst-auditmanymod1.so:tst-auditmanymod2.so:tst-auditmanymod3.so:tst-auditmanymod4.so:tst-auditmanymod5.so:tst-auditmanymod6.so:tst-auditmanymod7.so:tst-auditmanymod8.so:tst-auditmanymod9.so
 
+LDFLAGS-tst-audit14 = -Wl,--audit=tst-auditlogmod-1.so
+$(objpfx)tst-auditlogmod-1.so: $(libsupport)
+$(objpfx)tst-audit14.out: $(objpfx)tst-auditlogmod-1.so
+LDFLAGS-tst-audit15 = \
+  -Wl,--audit=tst-auditlogmod-1.so,--depaudit=tst-auditlogmod-2.so
+$(objpfx)tst-auditlogmod-2.so: $(libsupport)
+$(objpfx)tst-audit15.out: \
+  $(objpfx)tst-auditlogmod-1.so $(objpfx)tst-auditlogmod-2.so
+LDFLAGS-tst-audit16 = \
+  -Wl,--audit=tst-auditlogmod-1.so:tst-auditlogmod-2.so \
+  -Wl,--depaudit=tst-auditlogmod-3.so
+$(objpfx)tst-auditlogmod-3.so: $(libsupport)
+$(objpfx)tst-audit16.out: \
+  $(objpfx)tst-auditlogmod-1.so $(objpfx)tst-auditlogmod-2.so \
+  $(objpfx)tst-auditlogmod-3.so
+
 # tst-sonamemove links against an older implementation of the library.
 LDFLAGS-tst-sonamemove-linkmod1.so = \
   -Wl,--version-script=tst-sonamemove-linkmod1.map \
@@ -1644,6 +1707,10 @@ $(objpfx)tst-dlopenfailmod1.so: \
   $(shared-thread-library) $(objpfx)tst-dlopenfaillinkmod.so
 LDFLAGS-tst-dlopenfaillinkmod.so = -Wl,-soname,tst-dlopenfail-missingmod.so
 $(objpfx)tst-dlopenfailmod2.so: $(shared-thread-library)
+$(objpfx)tst-dlopenfail-2: $(libdl)
+$(objpfx)tst-dlopenfail.out: \
+  $(objpfx)tst-dlopenfailmod1.so $(objpfx)tst-dlopenfailmod2.so \
+  $(objpfx)tst-dlopenfailmod3.so
 
 $(objpfx)tst-dlopen-nodelete-reloc: $(libdl)
 $(objpfx)tst-dlopen-nodelete-reloc.out: \
@@ -1689,3 +1756,61 @@ $(objpfx)tst-dlopen-nodelete-reloc-mod17.so: \
   $(objpfx)tst-dlopen-nodelete-reloc-mod15.so \
   $(objpfx)tst-dlopen-nodelete-reloc-mod16.so
 LDFLAGS-tst-dlopen-nodelete-reloc-mod17.so = -Wl,--no-as-needed
+
+$(objpfx)tst-ldconfig-ld_so_conf-update.out: $(objpfx)tst-ldconfig-ld-mod.so
+$(objpfx)tst-ldconfig-ld_so_conf-update: $(libdl)
+
+LDFLAGS-tst-filterobj-flt.so = -Wl,--filter=$(objpfx)tst-filterobj-filtee.so
+$(objpfx)tst-filterobj: $(objpfx)tst-filterobj-flt.so
+$(objpfx)tst-filterobj-dlopen: $(libdl)
+$(objpfx)tst-filterobj.out: $(objpfx)tst-filterobj-filtee.so
+$(objpfx)tst-filterobj-dlopen.out: $(objpfx)tst-filterobj-filtee.so
+
+LDFLAGS-tst-filterobj-aux.so = -Wl,--auxiliary=$(objpfx)tst-filterobj-filtee.so
+$(objpfx)tst-auxobj: $(objpfx)tst-filterobj-aux.so
+$(objpfx)tst-auxobj-dlopen: $(libdl)
+$(objpfx)tst-auxobj.out: $(objpfx)tst-filterobj-filtee.so
+$(objpfx)tst-auxobj-dlopen.out: $(objpfx)tst-filterobj-filtee.so
+
+$(objpfx)tst-single_threaded: $(objpfx)tst-single_threaded-mod1.so $(libdl)
+$(objpfx)tst-single_threaded.out: \
+  $(objpfx)tst-single_threaded-mod2.so $(objpfx)tst-single_threaded-mod3.so
+$(objpfx)tst-single_threaded-static-dlopen: \
+  $(objpfx)tst-single_threaded-mod1.o $(common-objpfx)dlfcn/libdl.a
+$(objpfx)tst-single_threaded-static-dlopen.out: \
+  $(objpfx)tst-single_threaded-mod2.so
+$(objpfx)tst-single_threaded-pthread: \
+  $(objpfx)tst-single_threaded-mod1.so $(libdl) $(shared-thread-library)
+$(objpfx)tst-single_threaded-pthread.out: \
+  $(objpfx)tst-single_threaded-mod2.so $(objpfx)tst-single_threaded-mod3.so \
+  $(objpfx)tst-single_threaded-mod4.so
+$(objpfx)tst-single_threaded-pthread-static: $(static-thread-library)
+
+$(objpfx)tst-tls-ie: $(libdl) $(shared-thread-library)
+$(objpfx)tst-tls-ie.out: \
+  $(objpfx)tst-tls-ie-mod0.so \
+  $(objpfx)tst-tls-ie-mod1.so \
+  $(objpfx)tst-tls-ie-mod2.so \
+  $(objpfx)tst-tls-ie-mod3.so \
+  $(objpfx)tst-tls-ie-mod4.so \
+  $(objpfx)tst-tls-ie-mod5.so \
+  $(objpfx)tst-tls-ie-mod6.so
+
+$(objpfx)tst-tls-ie-dlmopen: $(libdl) $(shared-thread-library)
+$(objpfx)tst-tls-ie-dlmopen.out: \
+  $(objpfx)tst-tls-ie-mod0.so \
+  $(objpfx)tst-tls-ie-mod1.so \
+  $(objpfx)tst-tls-ie-mod2.so \
+  $(objpfx)tst-tls-ie-mod3.so \
+  $(objpfx)tst-tls-ie-mod4.so \
+  $(objpfx)tst-tls-ie-mod5.so \
+  $(objpfx)tst-tls-ie-mod6.so
+
+$(objpfx)tst-tls-surplus: $(libdl)
+
+$(objpfx)argv0test.out: tst-rtld-argv0.sh $(objpfx)ld.so \
+                       $(objpfx)argv0test
+       $(SHELL) $< $(objpfx)ld.so $(objpfx)argv0test \
+            '$(test-wrapper-env)' '$(run_program_env)' \
+            '$(rpath-link)' 'test-argv0' > $@; \
+    $(evaluate-test)