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