Update.
[glibc.git] / elf / Makefile
blobe45d89d62fd21fed28aca6681af220f570e02ff1
1 # Copyright (C) 1995-1999, 2000, 2001 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
4 # The GNU C Library is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU Library General Public License as
6 # published by the Free Software Foundation; either version 2 of the
7 # License, or (at your option) any later version.
9 # The GNU C Library is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # Library General Public License for more details.
14 # You should have received a copy of the GNU Library General Public
15 # License along with the GNU C Library; see the file COPYING.LIB. If not,
16 # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 # Boston, MA 02111-1307, USA.
19 # Makefile for elf subdirectory of GNU C Library.
21 subdir := elf
23 headers = elf.h bits/elfclass.h link.h
24 routines = $(dl-routines) dl-open dl-close dl-support \
25 dl-addr enbl-secure dl-profstub dl-origin dl-libc dl-sym
27 # The core dynamic linking functions are in libc for the static and
28 # profiled libraries.
29 dl-routines = $(addprefix dl-,load cache lookup object reloc deps \
30 runtime error init fini debug misc \
31 version profile)
32 all-dl-routines = $(dl-routines) $(sysdep-dl-routines)
33 # But they are absent from the shared libc, because that code is in ld.so.
34 elide-routines.os = $(all-dl-routines) dl-support enbl-secure
36 # ld.so uses those routines, plus some special stuff for being the program
37 # interpreter and operating independent of libc.
38 rtld-routines := rtld $(dl-routines) dl-sysdep dl-environ dl-minimal
39 all-rtld-routines = $(rtld-routines) $(sysdep-rtld-routines)
41 distribute := $(rtld-routines:=.c) dynamic-link.h do-rel.h dl-machine.h \
42 dl-cache.h dl-hash.h soinit.c sofini.c ldd.bash.in \
43 genrtldtbl.awk atomicity.h dl-procinfo.h ldsodefs.h \
44 dl-librecon.h interp.c sln.c dl-dst.h hp-timing.h \
45 do-lookup.h dl-lookupcfg.h sprof.c gen-trusted-dirs.awk \
46 testobj1.c testobj2.c testobj3.c testobj4.c testobj5.c \
47 testobj6.c testobj1_1.c failobj.c unloadmod.c \
48 ldconfig.h ldconfig.c cache.c readlib.c readelflib.c \
49 chroot_canon.c gccframe.h \
50 dep1.c dep2.c dep3.c dep4.c dl-dtprocnum.h unsecvars.h \
51 vismain.c vismod1.c vismod2.c vismod3.c \
52 constload2.c constload3.c filtmod1.c filtmod2.c \
53 nodlopenmod.c nodelete.c nodelmod1.c nodelmod2.c \
54 nodelmod3.c nodelmod4.c nodlopen.c dl-osinfo.h \
55 reldepmod1.c reldepmod2.c reldepmod3.c reldepmod4.c \
56 reldep4mod1.c reldep4mod2.c reldep4mod3.c reldep4mod4.c \
57 nextmod1.c nextmod2.c pathoptobj.c tst-pathopt.sh \
58 neededobj1.c neededobj2.c neededobj3.c neededobj4.c \
59 neededobj5.c neededobj6.c firstobj.c \
60 unload2mod.c unload2dep.c ltglobmod1.c ltglobmod2.c \
61 testobj.h vismod.h globalmod1.c
63 include ../Makeconfig
65 before-compile = $(objpfx)trusted-dirs.h
66 generated := trusted-dirs.h trusted-dirs.st for-renamed/renamed.so
67 generated-dirs := for-renamed
69 ifeq ($(versioning),yes)
70 ld-map = $(common-objpfx)ld.map
71 endif
73 ifeq (yes,$(build-shared))
74 extra-objs = $(all-rtld-routines:%=%.os) soinit.os sofini.os interp.os
75 generated += librtld.os dl-allobjs.os ld.so ldd
76 install-others = $(inst_slibdir)/$(rtld-installed-name)
77 install-bin = ldd
78 endif
80 others = sprof sln
81 install-bin += sprof
82 others-static = sln
83 install-rootsbin = sln
85 ifeq (yes,$(use-ldconfig))
86 ifeq (yes,$(build-shared))
87 others-static += ldconfig
88 others += ldconfig
89 install-rootsbin += ldconfig
91 ldconfig-modules := cache readlib xmalloc xstrdup chroot_canon
92 extra-objs += $(ldconfig-modules:=.o)
94 # To find xmalloc.c and xstrdup.c
95 vpath %.c ../locale/programs
97 endif
98 endif
100 ifeq (yes,$(build-shared))
101 tests = loadtest restest1 preloadtest loadfail multiload origtest resolvfail \
102 constload1 order $(tests-vis-$(have-protected)) noload filter unload \
103 reldep reldep2 reldep3 reldep4 next $(tests-nodelete-$(have-z-nodelete)) \
104 $(tests-nodlopen-$(have-z-nodlopen)) neededtest neededtest2 \
105 neededtest3 neededtest4 unload2 lateglobal initfirst global \
106 restest2
107 test-srcs = tst-pathopt
108 tests-vis-yes = vismain
109 tests-nodelete-yes = nodelete
110 tests-nodlopen-yes = nodlopen
111 endif
112 modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
113 testobj1_1 failobj constload2 constload3 unloadmod \
114 dep1 dep2 dep3 dep4 $(modules-vis-$(have-protected)) \
115 $(modules-nodelete-$(have-z-nodelete)) \
116 $(modules-nodlopen-$(have-z-nodlopen)) filtmod1 filtmod2 \
117 reldepmod1 reldepmod2 reldepmod3 reldepmod4 nextmod1 nextmod2 \
118 reldep4mod1 reldep4mod2 reldep4mod3 reldep4mod4 \
119 neededobj1 neededobj2 neededobj3 neededobj4 \
120 neededobj5 neededobj6 firstobj globalmod1 \
121 unload2mod unload2dep ltglobmod1 ltglobmod2 pathoptobj
122 modules-vis-yes = vismod1 vismod2 vismod3
123 modules-nodelete-yes = nodelmod1 nodelmod2 nodelmod3 nodelmod4
124 modules-nodlopen-yes = nodlopenmod
125 extra-objs += $(addsuffix .os,$(strip $(modules-names)))
127 include ../Rules
129 ifeq (yes,$(build-shared))
130 # Make sure these things are built in the `make lib' pass so they can be used
131 # to run programs during the `make others' pass.
132 lib-noranlib: $(objpfx)$(rtld-installed-name) \
133 $(addprefix $(objpfx),$(extra-objs))
134 endif
136 # Command to link into a larger single relocatable object.
137 reloc-link = $(LINK.o) -nostdlib -nostartfiles -r -o $@
139 $(objpfx)dl-allobjs.os: $(all-rtld-routines:%=$(objpfx)%.os)
140 $(reloc-link) $^
142 # Link together the dynamic linker into a single relocatable object.
143 $(objpfx)librtld.os: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
144 $(reloc-link) '-Wl,-(' $^ -lgcc '-Wl,-)'
146 # Do we need a linker script?
147 rtld-ldscript-in := $(firstword $(wildcard $(+sysdep_dirs:%=%/rtld-ldscript.in)))
149 ifneq (,$(rtld-ldscript-in))
150 rtld-ldscript = $(objpfx)rtld-ldscript
151 generated += rtld-ldscript
153 LDFLAGS-rtld = -T $(rtld-ldscript)
154 before-compile += $(rtld-ldscript)
156 rtld-parms = $(wildcard $(+sysdep_dirs:%=%/rtld-parms))
157 include $(rtld-parms)
159 $(rtld-ldscript): $(rtld-ldscript-in) $(rtld-parms)
160 sed -e 's#@@rtld-oformat@@#$(rtld-oformat)#' \
161 -e 's#@@rtld-arch@@#$(rtld-arch)#' \
162 -e 's#@@rtld-entry@@#$(rtld-entry)#' \
163 -e 's#@@rtld-base@@#$(rtld-base)#' $< >$@
164 endif
166 $(objpfx)ld.so: $(objpfx)librtld.os $(rtld-ldscript) $(ld-map)
167 $(LINK.o) -nostdlib -nostartfiles -shared -o $@ $(LDFLAGS-rtld) \
168 $(filter-out $(rtld-ldscript) $(map-file),$^) \
169 $(load-map-file) -Wl,-soname=$(rtld-installed-name)
171 # interp.c exists just to get this string into the libraries.
172 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
174 ifneq (ld.so,$(rtld-installed-name))
175 # Make sure ld.so.1 exists in the build directory so we can link
176 # against it.
177 $(objpfx)$(rtld-installed-name): $(objpfx)ld.so
178 rm -f $@
179 ln -s $(<F) $@
180 generated += $(rtld-installed-name)
181 endif
183 # Build a file mentioning all trustworthy directories to look for shared
184 # libraries when using LD_LIBRARY_PATH in a setuid program. The user can
185 # add directories to the list by defining $(user-defined-trusted-dirs)
186 # before starting make.
187 $(objpfx)trusted-dirs.h: $(objpfx)trusted-dirs.st; @:
188 $(objpfx)trusted-dirs.st: Makefile $(..)Makeconfig
189 $(make-target-directory)
190 echo "$(subst :, ,$(default-rpath) $(user-defined-trusted-dirs))" \
191 | $(AWK) -f gen-trusted-dirs.awk > ${@:st=T};
192 $(move-if-change) ${@:st=T} ${@:st=h}
193 touch $@
194 CPPFLAGS-dl-load.c = -I$(objpfx). -I$(csu-objpfx).
196 ifeq (yes,$(build-shared))
197 $(inst_slibdir)/$(rtld-version-installed-name): $(objpfx)ld.so $(+force)
198 $(make-target-directory)
199 $(do-install-program)
201 $(inst_slibdir)/$(rtld-installed-name): \
202 $(inst_slibdir)/$(rtld-version-installed-name) \
203 $(inst_slibdir)/libc-$(version).so
204 $(make-shlib-link)
206 # Special target called by parent to install just the dynamic linker.
207 .PHONY: ldso_install
208 ldso_install: $(inst_slibdir)/$(rtld-installed-name)
209 endif
212 common-ldd-rewrite = -e 's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \
213 -e 's%@VERSION@%$(version)%g'
214 sh-ldd-rewrite = $(common-ldd-rewrite) -e 's%@BASH@%/bin/sh%g;s/\$$"/"/g'
215 bash-ldd-rewrite = $(common-ldd-rewrite) -e 's%@BASH@%$(BASH)%g' \
216 -e 's%@TEXTDOMAINDIR@%$(msgcatdir)%g'
218 ifneq ($(have-bash2),yes)
219 ldd-shell = sh
220 else
221 ldd-shell = bash
222 endif
224 ifeq ($(ldd-rewrite-script),no)
225 define gen-ldd
226 sed $($(ldd-shell)-ldd-rewrite) < $< > $@.new
227 endef
228 else
229 define gen-ldd
230 sed $($(ldd-shell)-ldd-rewrite) < $< | sed -f $(ldd-rewrite-script) > $@.new
231 endef
232 endif
234 $(objpfx)ldd: ldd.bash.in $(common-objpfx)soversions.mk \
235 $(common-objpfx)config.make
236 $(gen-ldd)
237 chmod 555 $@.new
238 mv -f $@.new $@
240 $(objpfx)sprof: $(libdl)
242 $(objpfx)ldconfig: $(ldconfig-modules:%=$(objpfx)%.o)
243 SYSCONF-FLAGS := -D'SYSCONFDIR="$(sysconfdir)"'
244 CFLAGS-ldconfig.c = $(SYSCONF-FLAGS) -D'LIBDIR="$(libdir)"' -D'SLIBDIR="$(slibdir)"'
245 CFLAGS-dl-cache.c = $(SYSCONF-FLAGS)
246 CFLAGS-cache.c = $(SYSCONF-FLAGS)
248 test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(strip $(modules-names))))
249 generated += $(addsuffix .so,$(strip $(modules-names)))
251 ifeq (yes,$(build-shared))
252 ifeq ($(cross-compiling),no)
253 tests: $(objpfx)tst-pathopt.out
254 endif
255 endif
257 $(objpfx)testobj1.so: $(libdl)
258 $(objpfx)testobj1_1.so: $(objpfx)testobj1.so $(libdl)
259 $(objpfx)testobj2.so: $(objpfx)testobj1.so $(libdl)
260 $(objpfx)testobj3.so: $(libdl)
261 $(objpfx)testobj4.so: $(libdl)
262 $(objpfx)testobj5.so: $(libdl)
263 $(objpfx)testobj6.so: $(objpfx)testobj1.so $(objpfx)testobj2.so $(libdl)
264 $(objpfx)failobj.so: $(objpfx)testobj6.so
265 $(objpfx)dep1.so: $(objpfx)dep2.so $(objpfx)dep4.so
266 $(objpfx)dep2.so: $(objpfx)dep3.so $(objpfx)dep4.so
267 $(objpfx)dep4.so: $(objpfx)dep3.so
268 $(objpfx)nodelmod3.so: $(objpfx)nodelmod4.so
269 $(objpfx)nextmod1.so: $(libdl)
270 $(objpfx)neededobj1.so: $(libdl)
271 $(objpfx)neededobj2.so: $(objpfx)neededobj1.so $(libdl)
272 $(objpfx)neededobj3.so: $(objpfx)neededobj1.so $(objpfx)neededobj2.so $(libdl)
273 $(objpfx)neededobj4.so: $(objpfx)neededobj1.so $(objpfx)neededobj2.so \
274 $(objpfx)neededobj3.so $(libdl)
275 $(objpfx)neededobj6.so: $(objpfx)neededobj5.so
276 $(objpfx)unload2mod.so: $(objpfx)unload2dep.so
277 $(objpfx)ltglobmod2.so: $(libdl)
278 $(objpfx)firstobj.so: $(shared-thread-library)
279 $(objpfx)globalmod1.so: $(libdl)
280 $(objpfx)reldep4mod1.so: $(objpfx)reldep4mod3.so
281 $(objpfx)reldep4mod2.so: $(objpfx)reldep4mod4.so
283 # filtmod1.so has a special rule
284 $(filter-out $(objpfx)filtmod1.so, $(test-modules)): $(objpfx)%.so: $(objpfx)%.os
285 $(build-module)
287 $(objpfx)loadtest: $(libdl)
288 LDFLAGS-loadtest = -rdynamic
290 $(objpfx)loadtest.out: $(test-modules)
292 $(objpfx)neededtest: $(libdl)
293 $(objpfx)neededtest.out: $(objpfx)neededobj1.so $(objpfx)neededobj2.so \
294 $(objpfx)neededobj3.so
296 $(objpfx)neededtest2: $(libdl)
297 $(objpfx)neededtest2.out: $(objpfx)neededobj1.so $(objpfx)neededobj2.so \
298 $(objpfx)neededobj3.so
300 $(objpfx)neededtest3: $(libdl)
301 $(objpfx)neededtest3.out: $(objpfx)neededobj1.so $(objpfx)neededobj2.so \
302 $(objpfx)neededobj3.so $(objpfx)neededobj4.so
304 neededtest4-ENV = LC_ALL=C LANGUAGE=C
305 $(objpfx)neededtest4: $(libdl) $(objpfx)neededobj1.so
306 $(objpfx)neededtest4.out: $(objpfx)neededobj5.so $(objpfx)neededobj6.so
308 $(objpfx)restest1: $(objpfx)testobj1.so $(objpfx)testobj1_1.so $(libdl)
309 LDFLAGS-restest1 = -rdynamic
311 $(objpfx)restest2: $(libdl)
312 LDFLAGS-restest2 = -rdynamic
314 $(objpfx)restest1.out: $(test-modules)
316 preloadtest-preloads = testobj1 testobj2 testobj3 testobj4 testobj5
317 $(objpfx)preloadtest: $(objpfx)testobj6.so
318 LDFLAGS-preloadtest = -rdynamic
319 $(objpfx)preloadtest.out: $(preloadtest-preloads:%=$(objpfx)%.so)
320 preloadtest-ENV = \
321 LD_PRELOAD=$(subst $(empty) ,:,$(strip $(preloadtest-preloads:=.so)))
323 $(objpfx)loadfail: $(libdl)
324 LDFLAGS-loadfail = -rdynamic
326 $(objpfx)loadfail.out: $(objpfx)failobj.so
328 $(objpfx)multiload: $(libdl)
329 LDFLAGS-multiload = -rdynamic
330 CFLAGS-multiload.c = -DOBJDIR=\"$(elf-objpfx)\"
332 $(objpfx)multiload.out: $(objpfx)testobj1.so
334 $(objpfx)origtest: $(libdl)
335 LDFLAGS-origtest = -rdynamic
336 $(objpfx)origtest.out: $(objpfx)testobj1.so
338 ifeq ($(have-thread-library),yes)
339 $(objpfx)resolvfail: $(libdl) $(shared-thread-library)
340 else
341 $(objpfx)resolvfail: $(libdl)
342 endif
344 $(objpfx)constload1: $(libdl)
345 $(objpfx)constload1.out: $(objpfx)constload2.so $(objpfx)constload3.so
347 $(objpfx)order: $(addprefix $(objpfx),dep4.so dep3.so dep2.so dep1.so)
349 $(objpfx)order.out: $(objpfx)order
350 $(elf-objpfx)$(rtld-installed-name) \
351 --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)) \
352 $(objpfx)order > $@
353 (echo "0123456789" | cmp $@ -) > /dev/null
355 $(objpfx)vismain: $(addprefix $(objpfx),vismod1.so vismod2.so)
356 $(objpfx)vismain.out: $(addprefix $(objpfx),vismod3.so)
357 vismain-ENV = LD_PRELOAD=$(addprefix $(objpfx),vismod3.so)
359 $(objpfx)noload: $(objpfx)testobj1.so
360 LDFLAGS-noload = -rdynamic
361 $(objpfx)noload.out: $(objpfx)testobj5.so
363 LDFLAGS-nodelete = -rdynamic
364 LDFLAGS-nodelmod1.so = -Wl,--enable-new-dtags,-z,nodelete
365 LDFLAGS-nodelmod4.so = -Wl,--enable-new-dtags,-z,nodelete
366 $(objpfx)nodelete: $(libdl)
367 $(objpfx)nodelete.out: $(objpfx)nodelmod1.so $(objpfx)nodelmod2.so \
368 $(objpfx)nodelmod3.so
370 LDFLAGS-nodlopenmod.so = -Wl,--enable-new-dtags,-z,nodlopen
371 $(objpfx)nodlopen: $(libdl)
372 $(objpfx)nodlopen.out: $(objpfx)nodlopenmod.so
374 $(objpfx)filtmod1.so: $(objpfx)filtmod1.os $(objpfx)filtmod2.so
375 $(LINK.o) -shared -o $@ -B$(csu-objpfx) $(LDFLAGS.so) \
376 -L$(subst :, -L,$(rpath-link)) \
377 -Wl,-rpath-link=$(rpath-link) \
378 $< -Wl,-F,$(objpfx)filtmod2.so
379 $(objpfx)filter: $(objpfx)filtmod1.so
381 $(objpfx)unload: $(libdl)
382 $(objpfx)unload.out: $(objpfx)unloadmod.so
384 $(objpfx)reldep: $(libdl)
385 $(objpfx)reldep.out: $(objpfx)reldepmod1.so $(objpfx)reldepmod2.so
387 $(objpfx)reldep2: $(libdl)
388 $(objpfx)reldep2.out: $(objpfx)reldepmod1.so $(objpfx)reldepmod3.so
390 $(objpfx)reldep3: $(libdl)
391 $(objpfx)reldep3.out: $(objpfx)reldepmod1.so $(objpfx)reldepmod4.so
393 $(objpfx)reldep4: $(libdl)
394 $(objpfx)reldep4.out: $(objpfx)reldep4mod1.so $(objpfx)reldep4mod2.so
396 $(objpfx)next: $(objpfx)nextmod1.so $(objpfx)nextmod2.so $(libdl)
398 $(objpfx)unload2: $(libdl)
399 $(objpfx)unload2.out: $(objpfx)unload2mod.so $(objpfx)unload2dep.so
401 $(objpfx)lateglobal: $(libdl)
402 $(objpfx)lateglobal.out: $(objpfx)ltglobmod1.so $(objpfx)ltglobmod2.so
404 $(objpfx)tst-pathopt: $(libdl)
405 $(objpfx)tst-pathopt.out: tst-pathopt.sh $(objpfx)tst-pathopt \
406 $(objpfx)pathoptobj.so
407 $(SHELL) -e $< $(common-objpfx)
409 $(objpfx)initfirst: $(libdl)
410 $(objpfx)initfirst.out: $(objpfx)firstobj.so
412 $(objpfx)global: $(objpfx)globalmod1.so
413 $(objpfx)global.out: $(objpfx)reldepmod1.so