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