]>
Commit | Line | Data |
---|---|---|
19cf43be | 1 | # Copyright (C) 1995-1999, 2000 Free Software Foundation, Inc. |
01cc0be6 RM |
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 | |
afd4eb37 UD |
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. | |
01cc0be6 | 18 | |
3db52d94 UD |
19 | # Makefile for elf subdirectory of GNU C Library. |
20 | ||
d66e34cd RM |
21 | subdir := elf |
22 | ||
019e7a64 | 23 | headers = elf.h bits/elfclass.h link.h |
cddcfecf | 24 | routines = $(dl-routines) dl-open dl-close dl-symbol dl-support \ |
94e365c6 | 25 | dl-addr enbl-secure dl-profstub dl-origin dl-libc dl-sym |
266180eb RM |
26 | |
27 | # The core dynamic linking functions are in libc for the static and | |
28 | # profiled libraries. | |
f18edac3 | 29 | dl-routines = $(addprefix dl-,load cache lookup object reloc deps \ |
3996f34b | 30 | runtime error init fini debug misc \ |
d7926ed9 | 31 | version profile) |
b79f74cd | 32 | all-dl-routines = $(dl-routines) $(sysdep-dl-routines) |
266180eb | 33 | # But they are absent from the shared libc, because that code is in ld.so. |
b79f74cd | 34 | elide-routines.os = $(all-dl-routines) dl-support enbl-secure |
266180eb RM |
35 | |
36 | # ld.so uses those routines, plus some special stuff for being the program | |
37 | # interpreter and operating independent of libc. | |
e27b79d3 | 38 | rtld-routines := rtld $(dl-routines) dl-sysdep dl-environ dl-minimal |
e39e6956 | 39 | all-rtld-routines = $(rtld-routines) $(sysdep-rtld-routines) |
b79f74cd | 40 | |
94e365c6 | 41 | distribute := $(rtld-routines:=.c) dynamic-link.h do-rel.h dl-machine.h \ |
b3ed8219 | 42 | dl-cache.h dl-hash.h soinit.c sofini.c ldd.bash.in \ |
94e365c6 UD |
43 | genrtldtbl.awk atomicity.h dl-procinfo.h ldsodefs.h \ |
44 | dl-librecon.h interp.c sln.c dl-dst.h hp-timing.h \ | |
c77ec56d | 45 | do-lookup.h dl-lookupcfg.h sprof.c gen-trusted-dirs.awk \ |
94e365c6 | 46 | testobj1.c testobj2.c testobj3.c testobj4.c testobj5.c \ |
2b7238dd | 47 | testobj6.c testobj1_1.c failobj.c unloadmod.c \ |
84ddc586 | 48 | ldconfig.h ldconfig.c cache.c readlib.c readelflib.c \ |
afa0569f UD |
49 | dep1.c dep2.c dep3.c dep4.c dl-dtprocnum.h \ |
50 | vismain.c vismod1.c vismod2.c vismod3.c \ | |
74dd1fee UD |
51 | constload2.c constload3.c filtmod1.c filtmod2.c \ |
52 | nodlopenmod.c nodelete.c nodelmod1.c nodelmod2.c \ | |
2b7238dd UD |
53 | nodelmod3.c nodelmod4.c nodlopen.c dl-osinfo.h \ |
54 | reldepmod1.c reldepmod2.c reldepmod3.c reldepmod4.c | |
d66e34cd | 55 | |
05f732b3 UD |
56 | include ../Makeconfig |
57 | ||
40c4c9b5 UD |
58 | before-compile = $(objpfx)trusted-dirs.h |
59 | generated := trusted-dirs.h trusted-dirs.st | |
fd26970f | 60 | |
bdd421cc | 61 | ifeq ($(versioning),yes) |
a0edd63e | 62 | ld-map = $(common-objpfx)ld.map |
bdd421cc UD |
63 | endif |
64 | ||
d66e34cd | 65 | ifeq (yes,$(build-shared)) |
b79f74cd | 66 | extra-objs = $(all-rtld-routines:%=%.os) soinit.os sofini.os interp.os |
40c4c9b5 | 67 | generated += librtld.os dl-allobjs.os ld.so ldd |
8d57beea | 68 | install-others = $(inst_slibdir)/$(rtld-installed-name) |
b122c703 | 69 | install-bin = ldd |
f49bc43f | 70 | endif |
86d2c878 | 71 | |
9d141cae | 72 | others = sprof sln |
ea278354 | 73 | install-bin += sprof |
9d141cae UD |
74 | others-static = sln |
75 | install-rootsbin = sln | |
ae828bc6 | 76 | |
591e1ffb | 77 | ifeq (yes,$(use-ldconfig)) |
99ac5e47 | 78 | ifeq (yes,$(build-shared)) |
e1586792 | 79 | others-static += ldconfig |
da2d1bc5 | 80 | others += ldconfig |
9d141cae | 81 | install-rootsbin += ldconfig |
591e1ffb UD |
82 | |
83 | ldconfig-modules := cache readlib xmalloc xstrdup | |
84 | extra-objs += $(ldconfig-modules:=.o) | |
85 | ||
86 | # To find xmalloc.c and xstrdup.c | |
87 | vpath %.c ../locale/programs | |
88 | ||
99ac5e47 | 89 | endif |
1ef32c3d UD |
90 | endif |
91 | ||
2f512715 | 92 | ifeq (yes,$(build-shared)) |
19cf43be | 93 | tests = loadtest restest1 preloadtest loadfail multiload origtest resolvfail \ |
2b7238dd UD |
94 | constload1 order $(tests-vis-$(have-protected)) noload filter unload \ |
95 | reldep reldep2 reldep3 $(tests-nodelete-$(have-z-nodelete)) \ | |
2f54c82d | 96 | $(tests-nodlopen-$(have-z-nodlopen)) |
c1025c19 | 97 | tests-vis-yes = vismain |
0fb7851f | 98 | tests-nodelete-yes = nodelete |
2f54c82d | 99 | tests-nodlopen-yes = nodlopen |
2f512715 | 100 | endif |
a25f2023 | 101 | modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \ |
2b7238dd | 102 | testobj1_1 failobj constload2 constload3 unloadmod \ |
0fb7851f | 103 | dep1 dep2 dep3 dep4 $(modules-vis-$(have-protected)) \ |
2f54c82d | 104 | $(modules-nodelete-$(have-z-nodelete)) \ |
2b7238dd UD |
105 | $(modules-nodlopen-$(have-z-nodlopen)) filtmod1 filtmod2 \ |
106 | reldepmod1 reldepmod2 reldepmod3 reldepmod4 | |
c1025c19 | 107 | modules-vis-yes = vismod1 vismod2 vismod3 |
2cb8cefb | 108 | modules-nodelete-yes = nodelmod1 nodelmod2 nodelmod3 nodelmod4 |
2f54c82d | 109 | modules-nodlopen-yes = nodlopenmod |
9b014809 | 110 | extra-objs += $(addsuffix .os,$(strip $(modules-names))) |
482eec0d | 111 | |
01cc0be6 | 112 | include ../Rules |
d66e34cd | 113 | |
1ef32c3d | 114 | ifeq (yes,$(build-shared)) |
a89d30d4 RM |
115 | # Make sure these things are built in the `make lib' pass so they can be used |
116 | # to run programs during the `make others' pass. | |
117 | lib-noranlib: $(objpfx)$(rtld-installed-name) \ | |
118 | $(addprefix $(objpfx),$(extra-objs)) | |
119 | endif | |
120 | ||
db2286f6 RM |
121 | # Command to link into a larger single relocatable object. |
122 | reloc-link = $(LINK.o) -nostdlib -nostartfiles -r -o $@ | |
123 | ||
b79f74cd | 124 | $(objpfx)dl-allobjs.os: $(all-rtld-routines:%=$(objpfx)%.os) |
db2286f6 RM |
125 | $(reloc-link) $^ |
126 | ||
86d2c878 | 127 | # Link together the dynamic linker into a single relocatable object. |
40a55d20 | 128 | $(objpfx)librtld.os: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a |
db2286f6 | 129 | $(reloc-link) '-Wl,-(' $^ -lgcc '-Wl,-)' |
d66e34cd | 130 | |
f21acc89 UD |
131 | # Do we need a linker script? |
132 | rtld-ldscript-in := $(firstword $(wildcard $(+sysdep_dirs:%=%/rtld-ldscript.in))) | |
14ea22e9 | 133 | |
f21acc89 | 134 | ifneq (,$(rtld-ldscript-in)) |
880f421f UD |
135 | rtld-ldscript = $(objpfx)rtld-ldscript |
136 | generated += rtld-ldscript | |
137 | ||
138 | LDFLAGS-rtld = -T $(rtld-ldscript) | |
139 | before-compile += $(rtld-ldscript) | |
f21acc89 | 140 | |
f21acc89 UD |
141 | rtld-parms = $(wildcard $(+sysdep_dirs:%=%/rtld-parms)) |
142 | include $(rtld-parms) | |
880f421f UD |
143 | |
144 | $(rtld-ldscript): $(rtld-ldscript-in) $(rtld-parms) | |
f21acc89 UD |
145 | sed -e 's#@@rtld-oformat@@#$(rtld-oformat)#' \ |
146 | -e 's#@@rtld-arch@@#$(rtld-arch)#' \ | |
147 | -e 's#@@rtld-entry@@#$(rtld-entry)#' \ | |
148 | -e 's#@@rtld-base@@#$(rtld-base)#' $< >$@ | |
880f421f | 149 | endif |
f21acc89 | 150 | |
2f444823 | 151 | $(objpfx)ld.so: $(objpfx)librtld.os $(rtld-ldscript) $(ld-map) |
7ef90c15 UD |
152 | $(LINK.o) -nostdlib -nostartfiles -shared -o $@ $(LDFLAGS-rtld) \ |
153 | $(filter-out $(rtld-ldscript) $(map-file),$^) \ | |
154 | $(load-map-file) -Wl,-soname=$(rtld-installed-name) | |
266180eb | 155 | |
c7562c74 UD |
156 | # interp.c exists just to get this string into the libraries. |
157 | CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"' | |
158 | ||
1ef32c3d | 159 | ifneq (ld.so,$(rtld-installed-name)) |
afd4eb37 | 160 | # Make sure ld.so.1 exists in the build directory so we can link |
852fc4b9 RM |
161 | # against it. |
162 | $(objpfx)$(rtld-installed-name): $(objpfx)ld.so | |
163 | rm -f $@ | |
f332db02 | 164 | ln -s $(<F) $@ |
da2d1bc5 | 165 | generated += $(rtld-installed-name) |
852fc4b9 RM |
166 | endif |
167 | ||
fd26970f UD |
168 | # Build a file mentioning all trustworthy directories to look for shared |
169 | # libraries when using LD_LIBRARY_PATH in a setuid program. The user can | |
170 | # add directories to the list by defining $(user-defined-trusted-dirs) | |
171 | # before starting make. | |
6598ac30 UD |
172 | $(objpfx)trusted-dirs.h: $(objpfx)trusted-dirs.st; @: |
173 | $(objpfx)trusted-dirs.st: Makefile $(..)Makeconfig | |
1ef32c3d | 174 | $(make-target-directory) |
ab7eb292 UD |
175 | echo "$(subst :, ,$(default-rpath) $(user-defined-trusted-dirs))" \ |
176 | | $(AWK) -f gen-trusted-dirs.awk > ${@:st=T}; | |
6598ac30 UD |
177 | $(move-if-change) ${@:st=T} ${@:st=h} |
178 | touch $@ | |
9afc8a59 | 179 | CPPFLAGS-dl-load.c = -I$(objpfx). |
86d2c878 | 180 | |
9f2a9248 | 181 | ifeq (yes,$(build-shared)) |
73237de3 | 182 | $(inst_slibdir)/$(rtld-version-installed-name): $(objpfx)ld.so $(+force) |
460adbb8 | 183 | $(make-target-directory) |
925e31d9 | 184 | $(do-install-program) |
1ef32c3d | 185 | |
8d57beea | 186 | $(inst_slibdir)/$(rtld-installed-name): \ |
460adbb8 UD |
187 | $(inst_slibdir)/$(rtld-version-installed-name) \ |
188 | $(inst_slibdir)/libc-$(version).so | |
925e31d9 | 189 | $(make-shlib-link) |
b122c703 | 190 | |
5148d49f UD |
191 | # Special target called by parent to install just the dynamic linker. |
192 | .PHONY: ldso_install | |
193 | ldso_install: $(inst_slibdir)/$(rtld-installed-name) | |
9f2a9248 | 194 | endif |
5148d49f | 195 | |
cb343854 | 196 | |
926e512f RM |
197 | common-ldd-rewrite = -e 's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \ |
198 | -e 's%@VERSION@%$(version)%g' | |
1ddf537f | 199 | sh-ldd-rewrite = $(common-ldd-rewrite) -e 's%@BASH@%/bin/sh%g;s/\$$"/"/g' |
926e512f | 200 | bash-ldd-rewrite = $(common-ldd-rewrite) -e 's%@BASH@%$(BASH)%g' \ |
4a33c2f5 | 201 | -e 's%@TEXTDOMAINDIR@%$(msgcatdir)%g' |
cb343854 | 202 | |
84384f5b | 203 | ifneq ($(have-bash2),yes) |
cb343854 | 204 | ldd-shell = sh |
e2102c14 UD |
205 | else |
206 | ldd-shell = bash | |
cb343854 UD |
207 | endif |
208 | ||
209 | ifeq ($(ldd-rewrite-script),no) | |
210 | define gen-ldd | |
211 | sed $($(ldd-shell)-ldd-rewrite) < $< > $@.new | |
212 | endef | |
84384f5b | 213 | else |
cb343854 UD |
214 | define gen-ldd |
215 | sed $($(ldd-shell)-ldd-rewrite) < $< | sed -f $(ldd-rewrite-script) > $@.new | |
216 | endef | |
217 | endif | |
218 | ||
926e512f | 219 | $(objpfx)ldd: ldd.bash.in $(common-objpfx)soversions.mk \ |
ee74a442 | 220 | $(common-objpfx)config.make |
cb343854 | 221 | $(gen-ldd) |
84384f5b UD |
222 | chmod 555 $@.new |
223 | mv -f $@.new $@ | |
cb343854 | 224 | |
aaff4ba9 | 225 | $(objpfx)sprof: $(libdl) |
94e365c6 | 226 | |
591e1ffb | 227 | $(objpfx)ldconfig: $(ldconfig-modules:%=$(objpfx)%.o) |
8ca91b36 UD |
228 | SYSCONF-FLAGS := -D'SYSCONFDIR="$(sysconfdir)"' |
229 | CFLAGS-ldconfig.c = $(SYSCONF-FLAGS) -D'LIBDIR="$(libdir)"' -D'SLIBDIR="$(slibdir)"' | |
230 | CFLAGS-dl-cache.c = $(SYSCONF-FLAGS) | |
231 | CFLAGS-cache.c = $(SYSCONF-FLAGS) | |
591e1ffb | 232 | |
9b014809 UD |
233 | test-modules = $(addprefix $(objpfx),$(addsuffix .so,$(strip $(modules-names)))) |
234 | generated += $(addsuffix .so,$(strip $(modules-names))) | |
482eec0d | 235 | |
aaff4ba9 UD |
236 | $(objpfx)testobj1.so: $(libdl) |
237 | $(objpfx)testobj1_1.so: $(objpfx)testobj1.so $(libdl) | |
238 | $(objpfx)testobj2.so: $(objpfx)testobj1.so $(libdl) | |
239 | $(objpfx)testobj3.so: $(libdl) | |
240 | $(objpfx)testobj4.so: $(libdl) | |
241 | $(objpfx)testobj5.so: $(libdl) | |
242 | $(objpfx)testobj6.so: $(libdl) | |
e18db2b0 | 243 | $(objpfx)failobj.so: $(objpfx)testobj6.so |
84ddc586 UD |
244 | $(objpfx)dep1.so: $(objpfx)dep2.so $(objpfx)dep4.so |
245 | $(objpfx)dep2.so: $(objpfx)dep3.so $(objpfx)dep4.so | |
246 | $(objpfx)dep4.so: $(objpfx)dep3.so | |
2cb8cefb | 247 | $(objpfx)nodelmod3.so: $(objpfx)nodelmod4.so |
482eec0d | 248 | |
10b36b41 AJ |
249 | # filtmod1.so has a special rule |
250 | $(filter-out $(objpfx)filtmod1.so, $(test-modules)): $(objpfx)%.so: $(objpfx)%.os | |
482eec0d UD |
251 | $(build-module) |
252 | ||
aaff4ba9 | 253 | $(objpfx)loadtest: $(libdl) |
482eec0d UD |
254 | LDFLAGS-loadtest = -rdynamic |
255 | ||
256 | $(objpfx)loadtest.out: $(test-modules) | |
6bd06384 | 257 | |
aaff4ba9 | 258 | $(objpfx)restest1: $(objpfx)testobj1.so $(objpfx)testobj1_1.so $(libdl) |
e18db2b0 | 259 | LDFLAGS-restest1 = -rdynamic |
6bd06384 UD |
260 | |
261 | $(objpfx)restest1.out: $(test-modules) | |
3d91edb2 | 262 | |
e18db2b0 | 263 | preloadtest-preloads = testobj1 testobj2 testobj3 testobj4 testobj5 |
10584d2e | 264 | $(objpfx)preloadtest: $(objpfx)testobj6.so |
10584d2e | 265 | LDFLAGS-preloadtest = -rdynamic |
e18db2b0 UD |
266 | $(objpfx)preloadtest.out: $(preloadtest-preloads:%=$(objpfx)%.so) |
267 | preloadtest-ENV = \ | |
268 | LD_PRELOAD=$(subst $(empty) ,:,$(strip $(preloadtest-preloads:=.so))) | |
1e262312 | 269 | |
aaff4ba9 | 270 | $(objpfx)loadfail: $(libdl) |
1e262312 UD |
271 | LDFLAGS-loadfail = -rdynamic |
272 | ||
61e0617a UD |
273 | $(objpfx)loadfail.out: $(objpfx)failobj.so |
274 | ||
275 | $(objpfx)multiload: $(libdl) | |
276 | LDFLAGS-multiload = -rdynamic | |
9df54168 | 277 | CFLAGS-multiload.c = -DOBJDIR=\"$(elf-objpfx)\" |
61e0617a UD |
278 | |
279 | $(objpfx)multiload.out: $(objpfx)testobj1.so | |
dc5efe83 UD |
280 | |
281 | $(objpfx)origtest: $(libdl) | |
394679eb | 282 | LDFLAGS-origtest = -rdynamic |
dc5efe83 | 283 | $(objpfx)origtest.out: $(objpfx)testobj1.so |
ff5fad16 UD |
284 | |
285 | ifeq ($(have-thread-library),yes) | |
286 | $(objpfx)resolvfail: $(libdl) $(shared-thread-library) | |
287 | else | |
288 | $(objpfx)resolvfail: $(libdl) | |
289 | endif | |
19cf43be UD |
290 | |
291 | $(objpfx)constload1: $(libdl) | |
292 | $(objpfx)constload1.out: $(objpfx)constload2.so $(objpfx)constload3.so | |
84ddc586 UD |
293 | |
294 | $(objpfx)order: $(addprefix $(objpfx),dep4.so dep3.so dep2.so dep1.so) | |
295 | ||
296 | $(objpfx)order.out: $(objpfx)order | |
297 | $(elf-objpfx)$(rtld-installed-name) \ | |
298 | --library-path $(rpath-link)$(patsubst %,:%,$(sysdep-library-path)) \ | |
299 | $(objpfx)order > $@ | |
300 | (echo "0123456789" | cmp $@ -) > /dev/null | |
c1025c19 UD |
301 | |
302 | $(objpfx)vismain: $(addprefix $(objpfx),vismod1.so vismod2.so) | |
303 | $(objpfx)vismain.out: $(addprefix $(objpfx),vismod3.so) | |
304 | vismain-ENV = LD_PRELOAD=$(addprefix $(objpfx),vismod3.so) | |
5e61ef88 UD |
305 | |
306 | $(objpfx)noload: $(objpfx)testobj1.so | |
307 | LDFLAGS-noload = -rdynamic | |
308 | $(objpfx)noload.out: $(objpfx)testobj5.so | |
0fb7851f | 309 | |
ad7534c8 | 310 | LDFLAGS-nodelete = -rdynamic |
0fb7851f | 311 | LDFLAGS-nodelmod1.so = -Wl,--enable-new-dtags,-z,nodelete |
2cb8cefb | 312 | LDFLAGS-nodelmod4.so = -Wl,--enable-new-dtags,-z,nodelete |
0fb7851f | 313 | $(objpfx)nodelete: $(libdl) |
2cb8cefb UD |
314 | $(objpfx)nodelete.out: $(objpfx)nodelmod1.so $(objpfx)nodelmod2.so \ |
315 | $(objpfx)nodelmod3.so | |
2f54c82d UD |
316 | |
317 | LDFLAGS-nodlopenmod.so = -Wl,--enable-new-dtags,-z,nodlopen | |
318 | $(objpfx)nodlopen: $(libdl) | |
319 | $(objpfx)nodlopen.out: $(objpfx)nodlopenmod.so | |
fcacb36a | 320 | |
137bca87 UD |
321 | $(objpfx)filtmod1.so: $(objpfx)filtmod1.os $(objpfx)filtmod2.so |
322 | $(LINK.o) -shared -o $@ -B$(csu-objpfx) $(LDFLAGS.so) \ | |
323 | -L$(subst :, -L,$(rpath-link)) \ | |
324 | -Wl,-rpath-link=$(rpath-link) \ | |
325 | $< -Wl,-F,$(objpfx)filtmod2.so | |
fcacb36a | 326 | $(objpfx)filter: $(objpfx)filtmod1.so |
2b7238dd UD |
327 | |
328 | $(objpfx)unload: $(libdl) | |
329 | $(objpfx)unload.out: $(objpfx)unloadmod.so | |
330 | ||
331 | $(objpfx)reldep: $(libdl) | |
332 | $(objpfx)reldep.out: $(objpfx)reldepmod1.so $(objpfx)reldepmod2.so | |
333 | ||
334 | $(objpfx)reldep2: $(libdl) | |
335 | $(objpfx)reldep2.out: $(objpfx)reldepmod1.so $(objpfx)reldepmod3.so | |
336 | ||
337 | $(objpfx)reldep3: $(libdl) | |
338 | $(objpfx)reldep3.out: $(objpfx)reldepmod1.so $(objpfx)reldepmod4.so |