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