Add rules to build and run neededtest2.
[kopensolaris-gnu/glibc.git] / elf / Makefile
1 # Copyright (C) 1995-1999, 2000 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
3
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.
8
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.
13
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.
18
19 # Makefile for elf subdirectory of GNU C Library.
20
21 subdir          := elf
22
23 headers         = elf.h bits/elfclass.h link.h
24 routines        = $(dl-routines) dl-open dl-close dl-symbol dl-support \
25                   dl-addr enbl-secure dl-profstub dl-origin dl-libc dl-sym
26
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
35
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)
40
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                    nextmod1.c nextmod2.c \
57                    neededobj1.c neededobj2.c neededobj3.c \
58                    unload2mod.c unload2dep.c ltglobmod1.c ltglobmod2.c
59
60 include ../Makeconfig
61
62 before-compile  = $(objpfx)trusted-dirs.h
63 generated       := trusted-dirs.h trusted-dirs.st
64
65 ifeq ($(versioning),yes)
66 ld-map          = $(common-objpfx)ld.map
67 endif
68
69 ifeq (yes,$(build-shared))
70 extra-objs      = $(all-rtld-routines:%=%.os) soinit.os sofini.os interp.os
71 generated       += librtld.os dl-allobjs.os ld.so ldd
72 install-others  = $(inst_slibdir)/$(rtld-installed-name)
73 install-bin     = ldd
74 endif
75
76 others          = sprof sln
77 install-bin     += sprof
78 others-static   = sln
79 install-rootsbin = sln
80
81 ifeq (yes,$(use-ldconfig))
82 ifeq (yes,$(build-shared))
83 others-static   += ldconfig
84 others          += ldconfig
85 install-rootsbin += ldconfig
86
87 ldconfig-modules := cache readlib xmalloc xstrdup chroot_canon
88 extra-objs      += $(ldconfig-modules:=.o)
89
90 # To find xmalloc.c and xstrdup.c
91 vpath %.c ../locale/programs
92
93 endif
94 endif
95
96 ifeq (yes,$(build-shared))
97 tests = loadtest restest1 preloadtest loadfail multiload origtest resolvfail \
98         constload1 order $(tests-vis-$(have-protected)) noload filter unload \
99         reldep reldep2 reldep3 next $(tests-nodelete-$(have-z-nodelete)) \
100         $(tests-nodlopen-$(have-z-nodlopen)) neededtest neededtest2 \
101         unload2 lateglobal
102 tests-vis-yes = vismain
103 tests-nodelete-yes = nodelete
104 tests-nodlopen-yes = nodlopen
105 endif
106 modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
107                 testobj1_1 failobj constload2 constload3 unloadmod \
108                 dep1 dep2 dep3 dep4 $(modules-vis-$(have-protected)) \
109                 $(modules-nodelete-$(have-z-nodelete)) \
110                 $(modules-nodlopen-$(have-z-nodlopen)) filtmod1 filtmod2 \
111                 reldepmod1 reldepmod2 reldepmod3 reldepmod4 nextmod1 nextmod2 \
112                 neededobj1 neededobj2 neededobj3 unload2mod unload2dep \
113                 ltglobmod1 ltglobmod2
114 modules-vis-yes = vismod1 vismod2 vismod3
115 modules-nodelete-yes = nodelmod1 nodelmod2 nodelmod3 nodelmod4
116 modules-nodlopen-yes = nodlopenmod
117 extra-objs += $(addsuffix .os,$(strip $(modules-names)))
118
119 include ../Rules
120
121 ifeq (yes,$(build-shared))
122 # Make sure these things are built in the `make lib' pass so they can be used
123 # to run programs during the `make others' pass.
124 lib-noranlib: $(objpfx)$(rtld-installed-name) \
125               $(addprefix $(objpfx),$(extra-objs))
126 endif
127
128 # Command to link into a larger single relocatable object.
129 reloc-link = $(LINK.o) -nostdlib -nostartfiles -r -o $@
130
131 $(objpfx)dl-allobjs.os: $(all-rtld-routines:%=$(objpfx)%.os)
132         $(reloc-link) $^
133
134 # Link together the dynamic linker into a single relocatable object.
135 $(objpfx)librtld.os: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
136         $(reloc-link) '-Wl,-(' $^ -lgcc '-Wl,-)'
137
138 # Do we need a linker script?
139 rtld-ldscript-in := $(firstword $(wildcard $(+sysdep_dirs:%=%/rtld-ldscript.in)))
140
141 ifneq (,$(rtld-ldscript-in))
142 rtld-ldscript = $(objpfx)rtld-ldscript
143 generated += rtld-ldscript
144
145 LDFLAGS-rtld = -T $(rtld-ldscript)
146 before-compile += $(rtld-ldscript)
147
148 rtld-parms = $(wildcard $(+sysdep_dirs:%=%/rtld-parms))
149 include $(rtld-parms)
150
151 $(rtld-ldscript): $(rtld-ldscript-in) $(rtld-parms)
152         sed -e 's#@@rtld-oformat@@#$(rtld-oformat)#' \
153             -e 's#@@rtld-arch@@#$(rtld-arch)#' \
154             -e 's#@@rtld-entry@@#$(rtld-entry)#' \
155             -e 's#@@rtld-base@@#$(rtld-base)#' $< >$@
156 endif
157
158 $(objpfx)ld.so: $(objpfx)librtld.os $(rtld-ldscript) $(ld-map)
159         $(LINK.o) -nostdlib -nostartfiles -shared -o $@ $(LDFLAGS-rtld) \
160                   $(filter-out $(rtld-ldscript) $(map-file),$^)         \
161                   $(load-map-file) -Wl,-soname=$(rtld-installed-name)
162
163 # interp.c exists just to get this string into the libraries.
164 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
165
166 ifneq (ld.so,$(rtld-installed-name))
167 # Make sure ld.so.1 exists in the build directory so we can link
168 # against it.
169 $(objpfx)$(rtld-installed-name): $(objpfx)ld.so
170         rm -f $@
171         ln -s $(<F) $@
172 generated += $(rtld-installed-name)
173 endif
174
175 # Build a file mentioning all trustworthy directories to look for shared
176 # libraries when using LD_LIBRARY_PATH in a setuid program.  The user can
177 # add directories to the list by defining $(user-defined-trusted-dirs)
178 # before starting make.
179 $(objpfx)trusted-dirs.h: $(objpfx)trusted-dirs.st; @:
180 $(objpfx)trusted-dirs.st: Makefile $(..)Makeconfig
181         $(make-target-directory)
182         echo "$(subst :, ,$(default-rpath) $(user-defined-trusted-dirs))"    \
183         | $(AWK) -f gen-trusted-dirs.awk > ${@:st=T};
184         $(move-if-change) ${@:st=T} ${@:st=h}
185         touch $@
186 CPPFLAGS-dl-load.c = -I$(objpfx).
187
188 ifeq (yes,$(build-shared))
189 $(inst_slibdir)/$(rtld-version-installed-name): $(objpfx)ld.so $(+force)
190         $(make-target-directory)
191         $(do-install-program)
192
193 $(inst_slibdir)/$(rtld-installed-name): \
194   $(inst_slibdir)/$(rtld-version-installed-name) \
195   $(inst_slibdir)/libc-$(version).so
196         $(make-shlib-link)
197
198 # Special target called by parent to install just the dynamic linker.
199 .PHONY: ldso_install
200 ldso_install: $(inst_slibdir)/$(rtld-installed-name)
201 endif
202
203
204 common-ldd-rewrite = -e 's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \
205                      -e 's%@VERSION@%$(version)%g'
206 sh-ldd-rewrite = $(common-ldd-rewrite) -e 's%@BASH@%/bin/sh%g;s/\$$"/"/g'
207 bash-ldd-rewrite = $(common-ldd-rewrite) -e 's%@BASH@%$(BASH)%g' \
208                    -e 's%@TEXTDOMAINDIR@%$(msgcatdir)%g'
209
210 ifneq ($(have-bash2),yes)
211 ldd-shell = sh
212 else
213 ldd-shell = bash
214 endif
215
216 ifeq ($(ldd-rewrite-script),no)
217 define gen-ldd
218 sed $($(ldd-shell)-ldd-rewrite) < $< > $@.new
219 endef
220 else
221 define gen-ldd
222 sed $($(ldd-shell)-ldd-rewrite) < $< | sed -f $(ldd-rewrite-script) > $@.new
223 endef
224 endif
225
226 $(objpfx)ldd: ldd.bash.in $(common-objpfx)soversions.mk \
227               $(common-objpfx)config.make
228         $(gen-ldd)
229         chmod 555 $@.new
230         mv -f $@.new $@
231
232 $(objpfx)sprof: $(libdl)
233
234 $(objpfx)ldconfig: $(ldconfig-modules:%=$(objpfx)%.o)
235 SYSCONF-FLAGS := -D'SYSCONFDIR="$(sysconfdir)"'
236 CFLAGS-ldconfig.c = $(SYSCONF-FLAGS) -D'LIBDIR="$(libdir)"' -D'SLIBDIR="$(slibdir)"'
237 CFLAGS-dl-cache.c = $(SYSCONF-FLAGS)
238 CFLAGS-cache.c = $(SYSCONF-FLAGS)
239
240 test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(strip $(modules-names))))
241 generated += $(addsuffix .so,$(strip $(modules-names)))
242
243 $(objpfx)testobj1.so: $(libdl)
244 $(objpfx)testobj1_1.so: $(objpfx)testobj1.so $(libdl)
245 $(objpfx)testobj2.so: $(objpfx)testobj1.so $(libdl)
246 $(objpfx)testobj3.so: $(libdl)
247 $(objpfx)testobj4.so: $(libdl)
248 $(objpfx)testobj5.so: $(libdl)
249 $(objpfx)testobj6.so: $(libdl)
250 $(objpfx)failobj.so: $(objpfx)testobj6.so
251 $(objpfx)dep1.so: $(objpfx)dep2.so $(objpfx)dep4.so
252 $(objpfx)dep2.so: $(objpfx)dep3.so $(objpfx)dep4.so
253 $(objpfx)dep4.so: $(objpfx)dep3.so
254 $(objpfx)nodelmod3.so: $(objpfx)nodelmod4.so
255 $(objpfx)nextmod1.so: $(libdl)
256 $(objpfx)neededobj1.so: $(libdl)
257 $(objpfx)neededobj2.so: $(objpfx)neededobj1.so $(libdl)
258 $(objpfx)neededobj3.so: $(objpfx)neededobj1.so $(objpfx)neededobj2.so $(libdl)
259 $(objpfx)unload2mod.so: $(objpfx)unload2dep.so
260 $(objpfx)ltglobmod2.so: $(libdl)
261
262 # filtmod1.so has a special rule
263 $(filter-out $(objpfx)filtmod1.so, $(test-modules)): $(objpfx)%.so: $(objpfx)%.os
264         $(build-module)
265
266 $(objpfx)loadtest: $(libdl)
267 LDFLAGS-loadtest = -rdynamic
268
269 $(objpfx)loadtest.out: $(test-modules)
270
271 $(objpfx)neededtest: $(libdl)
272 $(objpfx)neededtest.out: $(objpfx)neededobj1.so $(objpfx)neededobj2.so \
273                      $(objpfx)neededobj3.so
274
275 $(objpfx)neededtest2: $(libdl)
276 $(objpfx)neededtest2.out: $(objpfx)neededobj1.so $(objpfx)neededobj2.so \
277                      $(objpfx)neededobj3.so
278
279 $(objpfx)restest1: $(objpfx)testobj1.so $(objpfx)testobj1_1.so $(libdl)
280 LDFLAGS-restest1 = -rdynamic
281
282 $(objpfx)restest1.out: $(test-modules)
283
284 preloadtest-preloads = testobj1 testobj2 testobj3 testobj4 testobj5
285 $(objpfx)preloadtest: $(objpfx)testobj6.so
286 LDFLAGS-preloadtest = -rdynamic
287 $(objpfx)preloadtest.out: $(preloadtest-preloads:%=$(objpfx)%.so)
288 preloadtest-ENV = \
289   LD_PRELOAD=$(subst $(empty) ,:,$(strip $(preloadtest-preloads:=.so)))
290
291 $(objpfx)loadfail: $(libdl)
292 LDFLAGS-loadfail = -rdynamic
293
294 $(objpfx)loadfail.out: $(objpfx)failobj.so
295
296 $(objpfx)multiload: $(libdl)
297 LDFLAGS-multiload = -rdynamic
298 CFLAGS-multiload.c = -DOBJDIR=\"$(elf-objpfx)\"
299
300 $(objpfx)multiload.out: $(objpfx)testobj1.so
301
302 $(objpfx)origtest: $(libdl)
303 LDFLAGS-origtest = -rdynamic
304 $(objpfx)origtest.out: $(objpfx)testobj1.so
305
306 ifeq ($(have-thread-library),yes)
307 $(objpfx)resolvfail: $(libdl) $(shared-thread-library)
308 else
309 $(objpfx)resolvfail: $(libdl)
310 endif
311
312 $(objpfx)constload1: $(libdl)
313 $(objpfx)constload1.out: $(objpfx)constload2.so $(objpfx)constload3.so
314
315 $(objpfx)order: $(addprefix $(objpfx),dep4.so dep3.so dep2.so dep1.so)
316
317 $(objpfx)order.out: $(objpfx)order
318         $(elf-objpfx)$(rtld-installed-name) \
319           --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)) \
320           $(objpfx)order > $@
321         (echo "0123456789" | cmp $@ -) > /dev/null
322
323 $(objpfx)vismain: $(addprefix $(objpfx),vismod1.so vismod2.so)
324 $(objpfx)vismain.out: $(addprefix $(objpfx),vismod3.so)
325 vismain-ENV = LD_PRELOAD=$(addprefix $(objpfx),vismod3.so)
326
327 $(objpfx)noload: $(objpfx)testobj1.so
328 LDFLAGS-noload = -rdynamic
329 $(objpfx)noload.out: $(objpfx)testobj5.so
330
331 LDFLAGS-nodelete = -rdynamic
332 LDFLAGS-nodelmod1.so = -Wl,--enable-new-dtags,-z,nodelete
333 LDFLAGS-nodelmod4.so = -Wl,--enable-new-dtags,-z,nodelete
334 $(objpfx)nodelete: $(libdl)
335 $(objpfx)nodelete.out: $(objpfx)nodelmod1.so $(objpfx)nodelmod2.so \
336                        $(objpfx)nodelmod3.so
337
338 LDFLAGS-nodlopenmod.so = -Wl,--enable-new-dtags,-z,nodlopen
339 $(objpfx)nodlopen: $(libdl)
340 $(objpfx)nodlopen.out: $(objpfx)nodlopenmod.so
341
342 $(objpfx)filtmod1.so: $(objpfx)filtmod1.os $(objpfx)filtmod2.so
343         $(LINK.o) -shared -o $@ -B$(csu-objpfx) $(LDFLAGS.so) \
344                   -L$(subst :, -L,$(rpath-link)) \
345                   -Wl,-rpath-link=$(rpath-link) \
346                   $< -Wl,-F,$(objpfx)filtmod2.so
347 $(objpfx)filter: $(objpfx)filtmod1.so
348
349 $(objpfx)unload: $(libdl)
350 $(objpfx)unload.out: $(objpfx)unloadmod.so
351
352 $(objpfx)reldep: $(libdl)
353 $(objpfx)reldep.out: $(objpfx)reldepmod1.so $(objpfx)reldepmod2.so
354
355 $(objpfx)reldep2: $(libdl)
356 $(objpfx)reldep2.out: $(objpfx)reldepmod1.so $(objpfx)reldepmod3.so
357
358 $(objpfx)reldep3: $(libdl)
359 $(objpfx)reldep3.out: $(objpfx)reldepmod1.so $(objpfx)reldepmod4.so
360
361 $(objpfx)next: $(objpfx)nextmod1.so $(objpfx)nextmod2.so $(libdl)
362
363 $(objpfx)unload2: $(libdl)
364 $(objpfx)unload2.out: $(objpfx)unload2mod.so $(objpfx)unload2dep.so
365
366 $(objpfx)lateglobal: $(libdl)
367 $(objpfx)lateglobal.out: $(objpfx)ltglobmod1.so $(objpfx)ltglobmod2.so