Update.
[glibc.git] / elf / Makefile
blobfd3faef0a7d23e656e01203eff53f481692d57e4
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
48 include ../Makeconfig
50 before-compile = $(objpfx)trusted-dirs.h
52 ifeq ($(versioning),yes)
53 ld-map = $(common-objpfx)ld.map
54 endif
56 ifeq (yes,$(build-shared))
57 extra-objs = $(rtld-routines:=.os) soinit.os sofini.os interp.os
58 generated = librtld.os dl-allobjs.os ld.so trusted-dirs.h trusted-dirs.st
59 install-others = $(inst_slibdir)/$(rtld-installed-name)
60 install-bin = ldd
61 generated += ldd
62 endif
64 others = sprof sln
65 install-bin += sprof
66 others-static = sln
67 install-rootsbin = sln
69 ifeq (yes,$(use-ldconfig))
70 others-static += ldconfig
71 others += ldconfig
72 install-rootsbin += ldconfig
74 ldconfig-modules := cache readlib xmalloc xstrdup
75 extra-objs += $(ldconfig-modules:=.o)
77 # To find xmalloc.c and xstrdup.c
78 vpath %.c ../locale/programs
80 endif
82 ifeq (yes,$(build-shared))
83 tests = loadtest restest1 preloadtest loadfail multiload origtest resolvfail \
84 constload1 order $(tests-vis-$(have-protected))
85 tests-vis-yes = vismain
86 endif
87 modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
88 testobj1_1 failobj constload2 constload3 \
89 dep1 dep2 dep3 dep4 $(modules-vis-$(have-protected))
90 modules-vis-yes = vismod1 vismod2 vismod3
91 extra-objs += $(modules-names:=.os)
93 include ../Rules
95 ifeq (yes,$(build-shared))
96 # Make sure these things are built in the `make lib' pass so they can be used
97 # to run programs during the `make others' pass.
98 lib-noranlib: $(objpfx)$(rtld-installed-name) \
99 $(addprefix $(objpfx),$(extra-objs))
100 endif
102 # Command to link into a larger single relocatable object.
103 reloc-link = $(LINK.o) -nostdlib -nostartfiles -r -o $@
105 $(objpfx)dl-allobjs.os: $(rtld-routines:%=$(objpfx)%.os)
106 $(reloc-link) $^
108 # Link together the dynamic linker into a single relocatable object.
109 $(objpfx)librtld.os: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
110 $(reloc-link) '-Wl,-(' $^ -lgcc '-Wl,-)'
112 # Do we need a linker script?
113 rtld-ldscript-in := $(firstword $(wildcard $(+sysdep_dirs:%=%/rtld-ldscript.in)))
115 ifneq (,$(rtld-ldscript-in))
116 rtld-ldscript = $(objpfx)rtld-ldscript
117 generated += rtld-ldscript
119 LDFLAGS-rtld = -T $(rtld-ldscript)
120 before-compile += $(rtld-ldscript)
122 rtld-parms = $(wildcard $(+sysdep_dirs:%=%/rtld-parms))
123 include $(rtld-parms)
125 $(rtld-ldscript): $(rtld-ldscript-in) $(rtld-parms)
126 sed -e 's#@@rtld-oformat@@#$(rtld-oformat)#' \
127 -e 's#@@rtld-arch@@#$(rtld-arch)#' \
128 -e 's#@@rtld-entry@@#$(rtld-entry)#' \
129 -e 's#@@rtld-base@@#$(rtld-base)#' $< >$@
130 endif
132 $(objpfx)ld.so: $(objpfx)librtld.os $(rtld-ldscript) $(ld-map)
133 $(LINK.o) -nostdlib -nostartfiles -shared -o $@ $(LDFLAGS-rtld) \
134 $(filter-out $(rtld-ldscript) $(map-file),$^) \
135 $(load-map-file) -Wl,-soname=$(rtld-installed-name)
137 # interp.c exists just to get this string into the libraries.
138 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
140 ifneq (ld.so,$(rtld-installed-name))
141 # Make sure ld.so.1 exists in the build directory so we can link
142 # against it.
143 $(objpfx)$(rtld-installed-name): $(objpfx)ld.so
144 rm -f $@
145 ln -s $(<F) $@
146 generated += $(rtld-installed-name)
147 endif
149 # Build a file mentioning all trustworthy directories to look for shared
150 # libraries when using LD_LIBRARY_PATH in a setuid program. The user can
151 # add directories to the list by defining $(user-defined-trusted-dirs)
152 # before starting make.
153 $(objpfx)trusted-dirs.h: $(objpfx)trusted-dirs.st; @:
154 $(objpfx)trusted-dirs.st: Makefile $(..)Makeconfig
155 $(make-target-directory)
156 echo "$(subst :, ,$(default-rpath) $(user-defined-trusted-dirs))" \
157 | $(AWK) -f gen-trusted-dirs.awk > ${@:st=T};
158 $(move-if-change) ${@:st=T} ${@:st=h}
159 touch $@
160 CPPFLAGS-dl-load.c = -I$(objpfx).
162 ifeq (yes,$(build-shared))
163 $(inst_slibdir)/$(rtld-version-installed-name): $(objpfx)ld.so $(+force)
164 $(make-target-directory)
165 $(INSTALL_PROGRAM) $< $@.new
167 $(inst_slibdir)/$(rtld-installed-name): \
168 $(inst_slibdir)/$(rtld-version-installed-name) \
169 $(inst_slibdir)/libc-$(version).so
170 rm -f $@ $<
171 $(symbolic-link-prog) $<.new $@
172 ln $<.new $<
173 rm -f $@
174 $(symbolic-link-prog) $(<F) $@
175 rm -f $<.new
177 # Special target called by parent to install just the dynamic linker.
178 .PHONY: ldso_install
179 ldso_install: $(inst_slibdir)/$(rtld-installed-name)
180 endif
183 common-ldd-rewrite = -e 's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \
184 -e 's%@VERSION@%$(version)%g'
185 sh-ldd-rewrite = $(common-ldd-rewrite) -e 's%@BASH@%/bin/sh%g;s/\$$"/"/g'
186 bash-ldd-rewrite = $(common-ldd-rewrite) -e 's%@BASH@%$(BASH)%g' \
187 -e 's%@TEXTDOMAINDIR@%$(msgcatdir)%g'
189 ifneq ($(have-bash2),yes)
190 ldd-shell = sh
191 else
192 ldd-shell = bash
193 endif
195 ifeq ($(ldd-rewrite-script),no)
196 define gen-ldd
197 sed $($(ldd-shell)-ldd-rewrite) < $< > $@.new
198 endef
199 else
200 define gen-ldd
201 sed $($(ldd-shell)-ldd-rewrite) < $< | sed -f $(ldd-rewrite-script) > $@.new
202 endef
203 endif
205 $(objpfx)ldd: ldd.bash.in $(common-objpfx)soversions.mk \
206 $(common-objpfx)config.make
207 $(gen-ldd)
208 chmod 555 $@.new
209 mv -f $@.new $@
211 $(objpfx)sprof: $(libdl)
213 $(objpfx)ldconfig: $(ldconfig-modules:%=$(objpfx)%.o)
215 test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(modules-names)))
216 generated += $(addsuffix .so,$(modules-names))
218 $(objpfx)testobj1.so: $(libdl)
219 $(objpfx)testobj1_1.so: $(objpfx)testobj1.so $(libdl)
220 $(objpfx)testobj2.so: $(objpfx)testobj1.so $(libdl)
221 $(objpfx)testobj3.so: $(libdl)
222 $(objpfx)testobj4.so: $(libdl)
223 $(objpfx)testobj5.so: $(libdl)
224 $(objpfx)testobj6.so: $(libdl)
225 $(objpfx)failobj.so: $(objpfx)testobj6.so
226 $(objpfx)dep1.so: $(objpfx)dep2.so $(objpfx)dep4.so
227 $(objpfx)dep2.so: $(objpfx)dep3.so $(objpfx)dep4.so
228 $(objpfx)dep4.so: $(objpfx)dep3.so
230 $(test-modules): $(objpfx)%.so: $(objpfx)%.os
231 $(build-module)
233 $(objpfx)loadtest: $(libdl)
234 LDFLAGS-loadtest = -rdynamic
236 $(objpfx)loadtest.out: $(test-modules)
238 $(objpfx)restest1: $(objpfx)testobj1.so $(objpfx)testobj1_1.so $(libdl)
239 LDFLAGS-restest1 = -rdynamic
241 $(objpfx)restest1.out: $(test-modules)
243 preloadtest-preloads = testobj1 testobj2 testobj3 testobj4 testobj5
244 $(objpfx)preloadtest: $(objpfx)testobj6.so
245 LDFLAGS-preloadtest = -rdynamic
246 $(objpfx)preloadtest.out: $(preloadtest-preloads:%=$(objpfx)%.so)
247 preloadtest-ENV = \
248 LD_PRELOAD=$(subst $(empty) ,:,$(strip $(preloadtest-preloads:=.so)))
250 $(objpfx)loadfail: $(libdl)
251 LDFLAGS-loadfail = -rdynamic
253 $(objpfx)loadfail.out: $(objpfx)failobj.so
255 $(objpfx)multiload: $(libdl)
256 LDFLAGS-multiload = -rdynamic
257 CFLAGS-multiload.c = -DOBJDIR=\"$(elf-objpfx)\"
259 $(objpfx)multiload.out: $(objpfx)testobj1.so
261 $(objpfx)origtest: $(libdl)
262 $(objpfx)origtest.out: $(objpfx)testobj1.so
264 ifeq ($(have-thread-library),yes)
265 $(objpfx)resolvfail: $(libdl) $(shared-thread-library)
266 else
267 $(objpfx)resolvfail: $(libdl)
268 endif
270 $(objpfx)constload1: $(libdl)
271 $(objpfx)constload1.out: $(objpfx)constload2.so $(objpfx)constload3.so
273 $(objpfx)order: $(addprefix $(objpfx),dep4.so dep3.so dep2.so dep1.so)
275 $(objpfx)order.out: $(objpfx)order
276 $(elf-objpfx)$(rtld-installed-name) \
277 --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)) \
278 $(objpfx)order > $@
279 (echo "0123456789" | cmp $@ -) > /dev/null
281 $(objpfx)vismain: $(addprefix $(objpfx),vismod1.so vismod2.so)
282 $(objpfx)vismain.out: $(addprefix $(objpfx),vismod3.so)
283 vismain-ENV = LD_PRELOAD=$(addprefix $(objpfx),vismod3.so)