Update.
[glibc.git] / elf / Makefile
blob75edf83d4c247d7d7d5d1a6732b363d1c0b85af0
1 # Copyright (C) 1995-1999, 2000 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-symbol 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 # But they are absent from the shared libc, because that code is in ld.so.
33 elide-routines.os = $(dl-routines) dl-support enbl-secure
35 # ld.so uses those routines, plus some special stuff for being the program
36 # interpreter and operating independent of libc.
37 rtld-routines := rtld $(dl-routines) dl-sysdep dl-environ dl-minimal
38 distribute := $(rtld-routines:=.c) dynamic-link.h do-rel.h dl-machine.h \
39 dl-cache.h dl-hash.h soinit.c sofini.c ldd.bash.in \
40 genrtldtbl.awk atomicity.h dl-procinfo.h ldsodefs.h \
41 dl-librecon.h interp.c sln.c dl-dst.h hp-timing.h \
42 do-lookup.h dl-lookupcfg.h sprof.c gen-trusted-dirs.awk \
43 testobj1.c testobj2.c testobj3.c testobj4.c testobj5.c \
44 testobj6.c testobj1_1.c failobj.c \
45 ldconfig.h ldconfig.c cache.c readlib.c readelflib.c \
46 dep1.c dep2.c dep3.c dep4.c dl-dtprocnum.h \
47 vismain.c vismod1.c vismod2.c vismod3.c \
48 constload2.c constload3.c
50 include ../Makeconfig
52 before-compile = $(objpfx)trusted-dirs.h
53 generated := trusted-dirs.h trusted-dirs.st
55 ifeq ($(versioning),yes)
56 ld-map = $(common-objpfx)ld.map
57 endif
59 ifeq (yes,$(build-shared))
60 extra-objs = $(rtld-routines:=.os) soinit.os sofini.os interp.os
61 generated += librtld.os dl-allobjs.os ld.so ldd
62 install-others = $(inst_slibdir)/$(rtld-installed-name)
63 install-bin = ldd
64 endif
66 others = sprof sln
67 install-bin += sprof
68 others-static = sln
69 install-rootsbin = sln
71 ifeq (yes,$(use-ldconfig))
72 ifeq (yes,$(build-shared))
73 others-static += ldconfig
74 others += ldconfig
75 install-rootsbin += ldconfig
77 ldconfig-modules := cache readlib xmalloc xstrdup
78 extra-objs += $(ldconfig-modules:=.o)
80 # To find xmalloc.c and xstrdup.c
81 vpath %.c ../locale/programs
83 endif
84 endif
86 ifeq (yes,$(build-shared))
87 tests = loadtest restest1 preloadtest loadfail multiload origtest resolvfail \
88 constload1 order $(tests-vis-$(have-protected)) noload filter \
89 $(tests-nodelete-$(have-z-nodelete)) \
90 $(tests-nodlopen-$(have-z-nodlopen))
91 tests-vis-yes = vismain
92 tests-nodelete-yes = nodelete
93 tests-nodlopen-yes = nodlopen
94 endif
95 modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
96 testobj1_1 failobj constload2 constload3 \
97 dep1 dep2 dep3 dep4 $(modules-vis-$(have-protected)) \
98 $(modules-nodelete-$(have-z-nodelete)) \
99 $(modules-nodlopen-$(have-z-nodlopen)) filtmod1 filtmod2
100 modules-vis-yes = vismod1 vismod2 vismod3
101 modules-nodelete-yes = nodelmod1 nodelmod2 nodelmod3 nodelmod4
102 modules-nodlopen-yes = nodlopenmod
103 extra-objs += $(addsuffix .os,$(strip $(modules-names)))
105 include ../Rules
107 ifeq (yes,$(build-shared))
108 # Make sure these things are built in the `make lib' pass so they can be used
109 # to run programs during the `make others' pass.
110 lib-noranlib: $(objpfx)$(rtld-installed-name) \
111 $(addprefix $(objpfx),$(extra-objs))
112 endif
114 # Command to link into a larger single relocatable object.
115 reloc-link = $(LINK.o) -nostdlib -nostartfiles -r -o $@
117 $(objpfx)dl-allobjs.os: $(rtld-routines:%=$(objpfx)%.os)
118 $(reloc-link) $^
120 # Link together the dynamic linker into a single relocatable object.
121 $(objpfx)librtld.os: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
122 $(reloc-link) '-Wl,-(' $^ -lgcc '-Wl,-)'
124 # Do we need a linker script?
125 rtld-ldscript-in := $(firstword $(wildcard $(+sysdep_dirs:%=%/rtld-ldscript.in)))
127 ifneq (,$(rtld-ldscript-in))
128 rtld-ldscript = $(objpfx)rtld-ldscript
129 generated += rtld-ldscript
131 LDFLAGS-rtld = -T $(rtld-ldscript)
132 before-compile += $(rtld-ldscript)
134 rtld-parms = $(wildcard $(+sysdep_dirs:%=%/rtld-parms))
135 include $(rtld-parms)
137 $(rtld-ldscript): $(rtld-ldscript-in) $(rtld-parms)
138 sed -e 's#@@rtld-oformat@@#$(rtld-oformat)#' \
139 -e 's#@@rtld-arch@@#$(rtld-arch)#' \
140 -e 's#@@rtld-entry@@#$(rtld-entry)#' \
141 -e 's#@@rtld-base@@#$(rtld-base)#' $< >$@
142 endif
144 $(objpfx)ld.so: $(objpfx)librtld.os $(rtld-ldscript) $(ld-map)
145 $(LINK.o) -nostdlib -nostartfiles -shared -o $@ $(LDFLAGS-rtld) \
146 $(filter-out $(rtld-ldscript) $(map-file),$^) \
147 $(load-map-file) -Wl,-soname=$(rtld-installed-name)
149 # interp.c exists just to get this string into the libraries.
150 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
152 ifneq (ld.so,$(rtld-installed-name))
153 # Make sure ld.so.1 exists in the build directory so we can link
154 # against it.
155 $(objpfx)$(rtld-installed-name): $(objpfx)ld.so
156 rm -f $@
157 ln -s $(<F) $@
158 generated += $(rtld-installed-name)
159 endif
161 # Build a file mentioning all trustworthy directories to look for shared
162 # libraries when using LD_LIBRARY_PATH in a setuid program. The user can
163 # add directories to the list by defining $(user-defined-trusted-dirs)
164 # before starting make.
165 $(objpfx)trusted-dirs.h: $(objpfx)trusted-dirs.st; @:
166 $(objpfx)trusted-dirs.st: Makefile $(..)Makeconfig
167 $(make-target-directory)
168 echo "$(subst :, ,$(default-rpath) $(user-defined-trusted-dirs))" \
169 | $(AWK) -f gen-trusted-dirs.awk > ${@:st=T};
170 $(move-if-change) ${@:st=T} ${@:st=h}
171 touch $@
172 CPPFLAGS-dl-load.c = -I$(objpfx).
174 ifeq (yes,$(build-shared))
175 $(inst_slibdir)/$(rtld-version-installed-name): $(objpfx)ld.so $(+force)
176 $(make-target-directory)
177 $(INSTALL_PROGRAM) $< $@.new
179 $(inst_slibdir)/$(rtld-installed-name): \
180 $(inst_slibdir)/$(rtld-version-installed-name) \
181 $(inst_slibdir)/libc-$(version).so
182 rm -f $@ $<
183 $(symbolic-link-prog) $<.new $@
184 ln $<.new $<
185 rm -f $@
186 $(symbolic-link-prog) $(<F) $@
187 rm -f $<.new
189 # Special target called by parent to install just the dynamic linker.
190 .PHONY: ldso_install
191 ldso_install: $(inst_slibdir)/$(rtld-installed-name)
192 endif
195 common-ldd-rewrite = -e 's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \
196 -e 's%@VERSION@%$(version)%g'
197 sh-ldd-rewrite = $(common-ldd-rewrite) -e 's%@BASH@%/bin/sh%g;s/\$$"/"/g'
198 bash-ldd-rewrite = $(common-ldd-rewrite) -e 's%@BASH@%$(BASH)%g' \
199 -e 's%@TEXTDOMAINDIR@%$(msgcatdir)%g'
201 ifneq ($(have-bash2),yes)
202 ldd-shell = sh
203 else
204 ldd-shell = bash
205 endif
207 ifeq ($(ldd-rewrite-script),no)
208 define gen-ldd
209 sed $($(ldd-shell)-ldd-rewrite) < $< > $@.new
210 endef
211 else
212 define gen-ldd
213 sed $($(ldd-shell)-ldd-rewrite) < $< | sed -f $(ldd-rewrite-script) > $@.new
214 endef
215 endif
217 $(objpfx)ldd: ldd.bash.in $(common-objpfx)soversions.mk \
218 $(common-objpfx)config.make
219 $(gen-ldd)
220 chmod 555 $@.new
221 mv -f $@.new $@
223 $(objpfx)sprof: $(libdl)
225 $(objpfx)ldconfig: $(ldconfig-modules:%=$(objpfx)%.o)
226 SYSCONF-FLAGS := -D'SYSCONFDIR="$(sysconfdir)"'
227 CFLAGS-ldconfig.c = $(SYSCONF-FLAGS) -D'LIBDIR="$(libdir)"' -D'SLIBDIR="$(slibdir)"'
228 CFLAGS-dl-cache.c = $(SYSCONF-FLAGS)
229 CFLAGS-cache.c = $(SYSCONF-FLAGS)
231 test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(strip $(modules-names))))
232 generated += $(addsuffix .so,$(strip $(modules-names)))
234 $(objpfx)testobj1.so: $(libdl)
235 $(objpfx)testobj1_1.so: $(objpfx)testobj1.so $(libdl)
236 $(objpfx)testobj2.so: $(objpfx)testobj1.so $(libdl)
237 $(objpfx)testobj3.so: $(libdl)
238 $(objpfx)testobj4.so: $(libdl)
239 $(objpfx)testobj5.so: $(libdl)
240 $(objpfx)testobj6.so: $(libdl)
241 $(objpfx)failobj.so: $(objpfx)testobj6.so
242 $(objpfx)dep1.so: $(objpfx)dep2.so $(objpfx)dep4.so
243 $(objpfx)dep2.so: $(objpfx)dep3.so $(objpfx)dep4.so
244 $(objpfx)dep4.so: $(objpfx)dep3.so
245 $(objpfx)nodelmod3.so: $(objpfx)nodelmod4.so
247 # filtmod1.so has a special rule
248 $(filter-out $(objpfx)filtmod1.so, $(test-modules)): $(objpfx)%.so: $(objpfx)%.os
249 $(build-module)
251 $(objpfx)loadtest: $(libdl)
252 LDFLAGS-loadtest = -rdynamic
254 $(objpfx)loadtest.out: $(test-modules)
256 $(objpfx)restest1: $(objpfx)testobj1.so $(objpfx)testobj1_1.so $(libdl)
257 LDFLAGS-restest1 = -rdynamic
259 $(objpfx)restest1.out: $(test-modules)
261 preloadtest-preloads = testobj1 testobj2 testobj3 testobj4 testobj5
262 $(objpfx)preloadtest: $(objpfx)testobj6.so
263 LDFLAGS-preloadtest = -rdynamic
264 $(objpfx)preloadtest.out: $(preloadtest-preloads:%=$(objpfx)%.so)
265 preloadtest-ENV = \
266 LD_PRELOAD=$(subst $(empty) ,:,$(strip $(preloadtest-preloads:=.so)))
268 $(objpfx)loadfail: $(libdl)
269 LDFLAGS-loadfail = -rdynamic
271 $(objpfx)loadfail.out: $(objpfx)failobj.so
273 $(objpfx)multiload: $(libdl)
274 LDFLAGS-multiload = -rdynamic
275 CFLAGS-multiload.c = -DOBJDIR=\"$(elf-objpfx)\"
277 $(objpfx)multiload.out: $(objpfx)testobj1.so
279 $(objpfx)origtest: $(libdl)
280 LDFLAGS-origtest = -rdynamic
281 $(objpfx)origtest.out: $(objpfx)testobj1.so
283 ifeq ($(have-thread-library),yes)
284 $(objpfx)resolvfail: $(libdl) $(shared-thread-library)
285 else
286 $(objpfx)resolvfail: $(libdl)
287 endif
289 $(objpfx)constload1: $(libdl)
290 $(objpfx)constload1.out: $(objpfx)constload2.so $(objpfx)constload3.so
292 $(objpfx)order: $(addprefix $(objpfx),dep4.so dep3.so dep2.so dep1.so)
294 $(objpfx)order.out: $(objpfx)order
295 $(elf-objpfx)$(rtld-installed-name) \
296 --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)) \
297 $(objpfx)order > $@
298 (echo "0123456789" | cmp $@ -) > /dev/null
300 $(objpfx)vismain: $(addprefix $(objpfx),vismod1.so vismod2.so)
301 $(objpfx)vismain.out: $(addprefix $(objpfx),vismod3.so)
302 vismain-ENV = LD_PRELOAD=$(addprefix $(objpfx),vismod3.so)
304 $(objpfx)noload: $(objpfx)testobj1.so
305 LDFLAGS-noload = -rdynamic
306 $(objpfx)noload.out: $(objpfx)testobj5.so
308 LDFLAGS-nodelmod1.so = -Wl,--enable-new-dtags,-z,nodelete
309 LDFLAGS-nodelmod4.so = -Wl,--enable-new-dtags,-z,nodelete
310 $(objpfx)nodelete: $(libdl)
311 $(objpfx)nodelete.out: $(objpfx)nodelmod1.so $(objpfx)nodelmod2.so \
312 $(objpfx)nodelmod3.so
314 LDFLAGS-nodlopenmod.so = -Wl,--enable-new-dtags,-z,nodlopen
315 $(objpfx)nodlopen: $(libdl)
316 $(objpfx)nodlopen.out: $(objpfx)nodlopenmod.so
318 $(objpfx)filtmod1.so: $(objpfx)filtmod1.os $(objpfx)filtmod2.so
319 $(LINK.o) -shared -o $@ -B$(csu-objpfx) $(LDFLAGS.so) \
320 -L$(subst :, -L,$(rpath-link)) \
321 -Wl,-rpath-link=$(rpath-link) \
322 $< -Wl,-F,$(objpfx)filtmod2.so
323 $(objpfx)filter: $(objpfx)filtmod1.so