Update.
[platform/upstream/glibc.git] / elf / Makefile
1 # Copyright (C) 1995, 1996, 1997, 1998, 1999 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 preinit)
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
34
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 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
46 include ../Makeconfig
47
48 before-compile = $(objpfx)trusted-dirs.h
49
50 ifeq ($(versioning),yes)
51 ld-map          = $(common-objpfx)ld.so.map
52 endif
53
54 ifeq (yes,$(build-shared))
55 extra-objs      = $(rtld-routines:=.os) soinit.os sofini.os interp.os
56 generated       = librtld.os dl-allobjs.os ld.so trusted-dirs.h trusted-dirs.st
57 install-others  = $(inst_slibdir)/$(rtld-installed-name)
58 install-bin     = ldd
59 generated      += ldd
60 endif
61
62 others          = sprof sln
63 install-bin     += sprof
64 others-static   = sln
65 install-rootsbin = sln
66
67 ifeq (yes,$(has-ldconfig))
68 others-static   += ldconfig
69 others          += ldconfig
70 install-rootsbin += ldconfig
71 endif
72
73 ifeq (yes,$(build-shared))
74 tests = loadtest restest1 preloadtest loadfail multiload origtest resolvfail
75 endif
76 modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
77                 testobj1_1 failobj
78 extra-objs += $(modules-names:=.os)
79
80 include ../Rules
81
82 ifeq (yes,$(build-shared))
83 # Make sure these things are built in the `make lib' pass so they can be used
84 # to run programs during the `make others' pass.
85 lib-noranlib: $(objpfx)$(rtld-installed-name) \
86               $(addprefix $(objpfx),$(extra-objs))
87 endif
88
89 # Command to link into a larger single relocatable object.
90 reloc-link = $(LINK.o) -nostdlib -nostartfiles -r -o $@
91
92 $(objpfx)dl-allobjs.os: $(rtld-routines:%=$(objpfx)%.os)
93         $(reloc-link) $^
94
95 # Link together the dynamic linker into a single relocatable object.
96 $(objpfx)librtld.os: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
97         $(reloc-link) '-Wl,-(' $^ -lgcc '-Wl,-)'
98
99 # Do we need a linker script?
100 rtld-ldscript-in := $(firstword $(wildcard $(+sysdep_dirs:%=%/rtld-ldscript.in)))
101
102 ifneq (,$(rtld-ldscript-in))
103 rtld-ldscript = $(objpfx)rtld-ldscript
104 generated += rtld-ldscript
105
106 LDFLAGS-rtld = -T $(rtld-ldscript)
107 before-compile += $(rtld-ldscript)
108
109 rtld-parms = $(wildcard $(+sysdep_dirs:%=%/rtld-parms))
110 include $(rtld-parms)
111
112 $(rtld-ldscript): $(rtld-ldscript-in) $(rtld-parms)
113         sed -e 's#@@rtld-oformat@@#$(rtld-oformat)#' \
114             -e 's#@@rtld-arch@@#$(rtld-arch)#' \
115             -e 's#@@rtld-entry@@#$(rtld-entry)#' \
116             -e 's#@@rtld-base@@#$(rtld-base)#' $< >$@
117 endif
118
119 $(objpfx)ld.so: $(objpfx)librtld.os $(rtld-ldscript) $(ld-map)
120         $(LINK.o) -nostdlib -nostartfiles -shared -o $@ $(LDFLAGS-rtld) \
121                   $(filter-out $(rtld-ldscript) $(map-file),$^)         \
122                   $(load-map-file) -Wl,-soname=$(rtld-installed-name)
123
124 # interp.c exists just to get this string into the libraries.
125 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
126
127 ifneq (ld.so,$(rtld-installed-name))
128 # Make sure ld.so.1 exists in the build directory so we can link
129 # against it.
130 $(objpfx)$(rtld-installed-name): $(objpfx)ld.so
131         rm -f $@
132         ln -s $(<F) $@
133 generated += $(rtld-installed-name)
134 endif
135
136 # Build a file mentioning all trustworthy directories to look for shared
137 # libraries when using LD_LIBRARY_PATH in a setuid program.  The user can
138 # add directories to the list by defining $(user-defined-trusted-dirs)
139 # before starting make.
140 $(objpfx)trusted-dirs.h: $(objpfx)trusted-dirs.st; @:
141 $(objpfx)trusted-dirs.st: Makefile $(..)Makeconfig
142         $(make-target-directory)
143         echo "$(subst :, ,$(default-rpath) $(user-defined-trusted-dirs))"    \
144         | $(AWK) -f gen-trusted-dirs.awk > ${@:st=T};
145         $(move-if-change) ${@:st=T} ${@:st=h}
146         touch $@
147 CPPFLAGS-dl-load.c = -I$(objpfx).
148 CFLAGS-dl-load.c += -Wno-uninitialized
149
150 ifeq (yes,$(build-shared))
151 $(inst_slibdir)/$(rtld-version-installed-name): $(objpfx)ld.so $(+force)
152         $(do-install-program)
153
154 $(inst_slibdir)/$(rtld-installed-name): \
155   $(inst_slibdir)/$(rtld-version-installed-name)
156         $(make-shlib-link)
157
158 # Special target called by parent to install just the dynamic linker.
159 .PHONY: ldso_install
160 ldso_install: $(inst_slibdir)/$(rtld-installed-name)
161 endif
162
163
164 common-ldd-rewrite = -e 's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \
165                      -e 's%@VERSION@%$(version)%g'
166 sh-ldd-rewrite = $(common-ldd-rewrite) -e 's%@BASH@%/bin/sh%g;s/\$$"/"/g'
167 bash-ldd-rewrite = $(common-ldd-rewrite) -e 's%@BASH@%$(BASH)%g' \
168                    -e 's%@TEXTDOMAINDIR@%$(msgcatdir)%g'
169
170 ifneq ($(have-bash2),yes)
171 ldd-shell = sh
172 else
173 ldd-shell = bash
174 endif
175
176 ifeq ($(ldd-rewrite-script),no)
177 define gen-ldd
178 sed $($(ldd-shell)-ldd-rewrite) < $< > $@.new
179 endef
180 else
181 define gen-ldd
182 sed $($(ldd-shell)-ldd-rewrite) < $< | sed -f $(ldd-rewrite-script) > $@.new
183 endef
184 endif
185
186 $(objpfx)ldd: ldd.bash.in $(common-objpfx)soversions.mk \
187               $(common-objpfx)config.make
188         $(gen-ldd)
189         chmod 555 $@.new
190         mv -f $@.new $@
191
192 $(objpfx)sprof: $(libdl)
193
194 test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(modules-names)))
195 generated += $(addsuffix .so,$(modules-names))
196
197 $(objpfx)testobj1.so: $(libdl)
198 $(objpfx)testobj1_1.so: $(objpfx)testobj1.so $(libdl)
199 $(objpfx)testobj2.so: $(objpfx)testobj1.so $(libdl)
200 $(objpfx)testobj3.so: $(libdl)
201 $(objpfx)testobj4.so: $(libdl)
202 $(objpfx)testobj5.so: $(libdl)
203 $(objpfx)testobj6.so: $(libdl)
204 $(objpfx)failobj.so: $(objpfx)testobj6.so
205
206 $(test-modules): $(objpfx)%.so: $(objpfx)%.os
207         $(build-module)
208
209 $(objpfx)loadtest: $(libdl)
210 LDFLAGS-loadtest = -rdynamic
211
212 $(objpfx)loadtest.out: $(test-modules)
213
214 $(objpfx)restest1: $(objpfx)testobj1.so $(objpfx)testobj1_1.so $(libdl)
215 LDFLAGS-restest1 = -rdynamic
216
217 $(objpfx)restest1.out: $(test-modules)
218
219 preloadtest-preloads = testobj1 testobj2 testobj3 testobj4 testobj5
220 $(objpfx)preloadtest: $(objpfx)testobj6.so
221 LDFLAGS-preloadtest = -rdynamic
222 $(objpfx)preloadtest.out: $(preloadtest-preloads:%=$(objpfx)%.so)
223 preloadtest-ENV = \
224   LD_PRELOAD=$(subst $(empty) ,:,$(strip $(preloadtest-preloads:=.so)))
225
226 $(objpfx)loadfail: $(libdl)
227 LDFLAGS-loadfail = -rdynamic
228
229 $(objpfx)loadfail.out: $(objpfx)failobj.so
230
231 $(objpfx)multiload: $(libdl)
232 LDFLAGS-multiload = -rdynamic
233 CFLAGS-multiload.c = -DOBJDIR=\"$(objpfx)\"
234
235 $(objpfx)multiload.out: $(objpfx)testobj1.so
236
237 $(objpfx)origtest: $(libdl)
238 $(objpfx)origtest.out: $(objpfx)testobj1.so
239
240 ifeq ($(have-thread-library),yes)
241 $(objpfx)resolvfail: $(libdl) $(shared-thread-library)
242 else
243 $(objpfx)resolvfail: $(libdl)
244 endif