1 # Copyright (C) 1995-1999, 2000, 2001 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 Lesser General Public
6 # License as published by the Free Software Foundation; either
7 # version 2.1 of the 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 # Lesser General Public License for more details.
14 # You should have received a copy of the GNU Lesser General Public
15 # License along with the GNU C Library; if not, write to the Free
16 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
19 # Makefile for elf subdirectory of GNU C Library.
23 headers
= elf.h bits
/elfclass.h link.h
24 routines
= $(dl-routines
) dl-open dl-close dl-support dl-iteratephdr \
25 dl-iteratephdr-static dl-addr enbl-secure dl-profstub \
26 dl-origin dl-libc dl-sym
28 # The core dynamic linking functions are in libc for the static and
30 dl-routines
= $(addprefix dl-
,load cache lookup object reloc deps \
31 runtime error init fini debug misc \
33 all-dl-routines
= $(dl-routines
) $(sysdep-dl-routines
)
34 # But they are absent from the shared libc, because that code is in ld.so.
35 elide-routines.os
= $(all-dl-routines
) dl-support enbl-secure \
38 # ld.so uses those routines, plus some special stuff for being the program
39 # interpreter and operating independent of libc.
40 rtld-routines
:= rtld
$(dl-routines
) dl-sysdep dl-environ dl-minimal
41 all-rtld-routines
= $(rtld-routines
) $(sysdep-rtld-routines
)
43 distribute
:= $(rtld-routines
:=.c
) dynamic-link.h do-rel.h dl-machine.h \
44 dl-cache.h dl-hash.h soinit.c sofini.c ldd.bash.in \
45 genrtldtbl.awk atomicity.h dl-procinfo.h ldsodefs.h \
46 dl-librecon.h interp.c sln.c dl-dst.h hp-timing.h \
47 do-lookup.h dl-lookupcfg.h sprof.c gen-trusted-dirs.awk \
48 testobj1.c testobj2.c testobj3.c testobj4.c testobj5.c \
49 testobj6.c testobj1_1.c failobj.c unloadmod.c \
50 ldconfig.h ldconfig.c cache.c readlib.c readelflib.c \
51 chroot_canon.c gccframe.h \
52 dep1.c dep2.c dep3.c dep4.c dl-dtprocnum.h unsecvars.h \
53 vismain.c vismod1.c vismod2.c vismod3.c \
54 constload2.c constload3.c filtmod1.c filtmod2.c \
55 nodlopenmod.c nodelete.c nodelmod1.c nodelmod2.c \
56 nodelmod3.c nodelmod4.c nodlopen.c dl-osinfo.h \
57 reldepmod1.c reldepmod2.c reldepmod3.c reldepmod4.c \
58 reldep4mod1.c reldep4mod2.c reldep4mod3.c reldep4mod4.c \
59 nextmod1.c nextmod2.c pathoptobj.c tst-pathopt.sh \
60 neededobj1.c neededobj2.c neededobj3.c neededobj4.c \
61 neededobj5.c neededobj6.c firstobj.c \
62 unload2mod.c unload2dep.c ltglobmod1.c ltglobmod2.c \
63 testobj.h vismod.h globalmod1.c
67 before-compile
= $(objpfx
)trusted-dirs.h
68 generated
:= trusted-dirs.h trusted-dirs.st for-renamed
/renamed.so
69 generated-dirs
:= for-renamed
71 ifeq ($(versioning
),yes
)
72 ld-map
= $(common-objpfx
)ld.map
75 ifeq (yes
,$(build-shared
))
76 extra-objs
= $(all-rtld-routines
:%=%.os
) soinit.os sofini.os interp.os
77 generated
+= librtld.os dl-allobjs.os
ld.so ldd
78 install-others
= $(inst_slibdir
)/$(rtld-installed-name
)
85 install-rootsbin
= sln
87 ifeq (yes
,$(use-ldconfig
))
88 ifeq (yes
,$(build-shared
))
89 others-static
+= ldconfig
91 install-rootsbin
+= ldconfig
93 ldconfig-modules
:= cache readlib xmalloc xstrdup chroot_canon
94 extra-objs
+= $(ldconfig-modules
:=.o
)
96 # To find xmalloc.c and xstrdup.c
97 vpath
%.c ..
/locale
/programs
102 ifeq (yes
,$(build-shared
))
103 tests
= loadtest restest1 preloadtest loadfail multiload origtest resolvfail \
104 constload1 order
$(tests-vis-
$(have-protected
)) noload
filter unload \
105 reldep reldep2 reldep3 reldep4 next
$(tests-nodelete-
$(have-z-nodelete
)) \
106 $(tests-nodlopen-
$(have-z-nodlopen
)) neededtest neededtest2 \
107 neededtest3 neededtest4 unload2 lateglobal initfirst global \
109 test-srcs
= tst-pathopt
110 tests-vis-yes
= vismain
111 tests-nodelete-yes
= nodelete
112 tests-nodlopen-yes
= nodlopen
114 modules-names
= testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
115 testobj1_1 failobj constload2 constload3 unloadmod \
116 dep1 dep2 dep3 dep4
$(modules-vis-
$(have-protected
)) \
117 $(modules-nodelete-
$(have-z-nodelete
)) \
118 $(modules-nodlopen-
$(have-z-nodlopen
)) filtmod1 filtmod2 \
119 reldepmod1 reldepmod2 reldepmod3 reldepmod4 nextmod1 nextmod2 \
120 reldep4mod1 reldep4mod2 reldep4mod3 reldep4mod4 \
121 neededobj1 neededobj2 neededobj3 neededobj4 \
122 neededobj5 neededobj6 firstobj globalmod1 \
123 unload2mod unload2dep ltglobmod1 ltglobmod2 pathoptobj
124 modules-vis-yes
= vismod1 vismod2 vismod3
125 modules-nodelete-yes
= nodelmod1 nodelmod2 nodelmod3 nodelmod4
126 modules-nodlopen-yes
= nodlopenmod
127 extra-objs
+= $(addsuffix .os
,$(strip $(modules-names
)))
131 ifeq (yes
,$(build-shared
))
132 # Make sure these things are built in the `make lib' pass so they can be used
133 # to run programs during the `make others' pass.
134 lib-noranlib
: $(objpfx
)$(rtld-installed-name
) \
135 $(addprefix $(objpfx
),$(extra-objs
))
138 # Command to link into a larger single relocatable object.
139 reloc-link
= $(LINK.o
) -nostdlib
-nostartfiles
-r
-o
$@
141 $(objpfx
)dl-allobjs.os
: $(all-rtld-routines
:%=$(objpfx
)%.os
)
144 # Link together the dynamic linker into a single relocatable object.
145 $(objpfx
)librtld.os
: $(objpfx
)dl-allobjs.os
$(common-objpfx
)libc_pic.a
146 $(reloc-link
) '-Wl,-(' $^
-lgcc
'-Wl,-)'
148 # Do we need a linker script?
149 rtld-ldscript-in
:= $(firstword $(wildcard $(+sysdep_dirs
:%=%/rtld-ldscript.in
)))
151 ifneq (,$(rtld-ldscript-in
))
152 rtld-ldscript
= $(objpfx
)rtld-ldscript
153 generated
+= rtld-ldscript
155 LDFLAGS-rtld
= -T
$(rtld-ldscript
)
156 before-compile
+= $(rtld-ldscript
)
158 rtld-parms
= $(wildcard $(+sysdep_dirs
:%=%/rtld-parms
))
159 include $(rtld-parms
)
161 $(rtld-ldscript
): $(rtld-ldscript-in
) $(rtld-parms
)
162 sed
-e
's#@@rtld-oformat@@#$(rtld-oformat)#' \
163 -e
's#@@rtld-arch@@#$(rtld-arch)#' \
164 -e
's#@@rtld-entry@@#$(rtld-entry)#' \
165 -e
's#@@rtld-base@@#$(rtld-base)#' $< >$@
168 $(objpfx
)ld.so
: $(objpfx
)librtld.os
$(rtld-ldscript
) $(ld-map
)
169 $(LINK.o
) -nostdlib
-nostartfiles
-shared
-o
$@
$(LDFLAGS-rtld
) \
170 $(filter-out $(rtld-ldscript
) $(map-file
),$^
) \
171 $(load-map-file
) -Wl
,-soname
=$(rtld-installed-name
)
173 # interp.c exists just to get this string into the libraries.
174 CFLAGS-interp.c
= -D
'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
176 ifneq (ld.so
,$(rtld-installed-name
))
177 # Make sure ld.so.1 exists in the build directory so we can link
179 $(objpfx
)$(rtld-installed-name
): $(objpfx
)ld.so
182 generated
+= $(rtld-installed-name
)
185 # Build a file mentioning all trustworthy directories to look for shared
186 # libraries when using LD_LIBRARY_PATH in a setuid program. The user can
187 # add directories to the list by defining $(user-defined-trusted-dirs)
188 # before starting make.
189 $(objpfx
)trusted-dirs.h
: $(objpfx
)trusted-dirs.st
; @
:
190 $(objpfx
)trusted-dirs.st
: Makefile
$(..
)Makeconfig
191 $(make-target-directory
)
192 echo
"$(subst :, ,$(default-rpath) $(user-defined-trusted-dirs))" \
193 |
$(AWK
) -f gen-trusted-dirs.awk
> ${@
:st
=T
};
194 $(move-if-change
) ${@
:st
=T
} ${@
:st
=h
}
196 CPPFLAGS-dl-load.c
= -I
$(objpfx
).
-I
$(csu-objpfx
).
198 ifeq (yes
,$(build-shared
))
199 $(inst_slibdir
)/$(rtld-version-installed-name
): $(objpfx
)ld.so
$(+force)
200 $(make-target-directory
)
201 $(do-install-program
)
203 $(inst_slibdir
)/$(rtld-installed-name
): \
204 $(inst_slibdir
)/$(rtld-version-installed-name
) \
205 $(inst_slibdir
)/libc-
$(version
).so
208 # Special target called by parent to install just the dynamic linker.
210 ldso_install
: $(inst_slibdir
)/$(rtld-installed-name
)
214 common-ldd-rewrite
= -e
's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \
215 -e
's%@VERSION@%$(version)%g'
216 sh-ldd-rewrite
= $(common-ldd-rewrite
) -e
's%@BASH@%/bin/sh%g;s/\$$"/"/g'
217 bash-ldd-rewrite
= $(common-ldd-rewrite
) -e
's%@BASH@%$(BASH)%g' \
218 -e
's%@TEXTDOMAINDIR@%$(msgcatdir)%g'
220 ifneq ($(have-bash2
),yes
)
226 ifeq ($(ldd-rewrite-script
),no
)
228 sed
$($(ldd-shell
)-ldd-rewrite
) < $< > $@.new
232 sed
$($(ldd-shell
)-ldd-rewrite
) < $< | sed
-f
$(ldd-rewrite-script
) > $@.new
236 $(objpfx
)ldd
: ldd.bash.in
$(common-objpfx
)soversions.mk \
237 $(common-objpfx
)config.make
242 $(objpfx
)sprof
: $(libdl
)
244 $(objpfx
)ldconfig
: $(ldconfig-modules
:%=$(objpfx
)%.o
)
245 SYSCONF-FLAGS
:= -D
'SYSCONFDIR="$(sysconfdir)"'
246 CFLAGS-ldconfig.c
= $(SYSCONF-FLAGS
) -D
'LIBDIR="$(libdir)"' -D
'SLIBDIR="$(slibdir)"'
247 CFLAGS-dl-cache.c
= $(SYSCONF-FLAGS
)
248 CFLAGS-cache.c
= $(SYSCONF-FLAGS
)
250 test-modules
= $(addprefix $(objpfx
),$(addsuffix .so
,$(strip $(modules-names
))))
251 generated
+= $(addsuffix .so
,$(strip $(modules-names
)))
253 ifeq (yes
,$(build-shared
))
254 ifeq ($(cross-compiling
),no
)
255 tests
: $(objpfx
)tst-pathopt.out
259 $(objpfx
)testobj1.so
: $(libdl
)
260 $(objpfx
)testobj1_1.so
: $(objpfx
)testobj1.so
$(libdl
)
261 $(objpfx
)testobj2.so
: $(objpfx
)testobj1.so
$(libdl
)
262 $(objpfx
)testobj3.so
: $(libdl
)
263 $(objpfx
)testobj4.so
: $(libdl
)
264 $(objpfx
)testobj5.so
: $(libdl
)
265 $(objpfx
)testobj6.so
: $(objpfx
)testobj1.so
$(objpfx
)testobj2.so
$(libdl
)
266 $(objpfx
)failobj.so
: $(objpfx
)testobj6.so
267 $(objpfx
)dep1.so
: $(objpfx
)dep2.so
$(objpfx
)dep4.so
268 $(objpfx
)dep2.so
: $(objpfx
)dep3.so
$(objpfx
)dep4.so
269 $(objpfx
)dep4.so
: $(objpfx
)dep3.so
270 $(objpfx
)nodelmod3.so
: $(objpfx
)nodelmod4.so
271 $(objpfx
)nextmod1.so
: $(libdl
)
272 $(objpfx
)neededobj1.so
: $(libdl
)
273 $(objpfx
)neededobj2.so
: $(objpfx
)neededobj1.so
$(libdl
)
274 $(objpfx
)neededobj3.so
: $(objpfx
)neededobj1.so
$(objpfx
)neededobj2.so
$(libdl
)
275 $(objpfx
)neededobj4.so
: $(objpfx
)neededobj1.so
$(objpfx
)neededobj2.so \
276 $(objpfx
)neededobj3.so
$(libdl
)
277 $(objpfx
)neededobj6.so
: $(objpfx
)neededobj5.so
278 $(objpfx
)unload2mod.so
: $(objpfx
)unload2dep.so
279 $(objpfx
)ltglobmod2.so
: $(libdl
)
280 $(objpfx
)firstobj.so
: $(shared-thread-library
)
281 $(objpfx
)globalmod1.so
: $(libdl
)
282 $(objpfx
)reldep4mod1.so
: $(objpfx
)reldep4mod3.so
283 $(objpfx
)reldep4mod2.so
: $(objpfx
)reldep4mod4.so
285 # filtmod1.so has a special rule
286 $(filter-out $(objpfx
)filtmod1.so
, $(test-modules
)): $(objpfx
)%.so
: $(objpfx
)%.os
289 $(objpfx
)loadtest
: $(libdl
)
290 LDFLAGS-loadtest
= -rdynamic
292 $(objpfx
)loadtest.out
: $(test-modules
)
294 $(objpfx
)neededtest
: $(libdl
)
295 $(objpfx
)neededtest.out
: $(objpfx
)neededobj1.so
$(objpfx
)neededobj2.so \
296 $(objpfx
)neededobj3.so
298 $(objpfx
)neededtest2
: $(libdl
)
299 $(objpfx
)neededtest2.out
: $(objpfx
)neededobj1.so
$(objpfx
)neededobj2.so \
300 $(objpfx
)neededobj3.so
302 $(objpfx
)neededtest3
: $(libdl
)
303 $(objpfx
)neededtest3.out
: $(objpfx
)neededobj1.so
$(objpfx
)neededobj2.so \
304 $(objpfx
)neededobj3.so
$(objpfx
)neededobj4.so
306 neededtest4-ENV
= LC_ALL
=C LANGUAGE
=C
307 $(objpfx
)neededtest4
: $(libdl
) $(objpfx
)neededobj1.so
308 $(objpfx
)neededtest4.out
: $(objpfx
)neededobj5.so
$(objpfx
)neededobj6.so
310 $(objpfx
)restest1
: $(objpfx
)testobj1.so
$(objpfx
)testobj1_1.so
$(libdl
)
311 LDFLAGS-restest1
= -rdynamic
313 $(objpfx
)restest2
: $(libdl
)
314 LDFLAGS-restest2
= -rdynamic
316 $(objpfx
)restest1.out
: $(test-modules
)
318 preloadtest-preloads
= testobj1 testobj2 testobj3 testobj4 testobj5
319 $(objpfx
)preloadtest
: $(objpfx
)testobj6.so
320 LDFLAGS-preloadtest
= -rdynamic
321 $(objpfx
)preloadtest.out
: $(preloadtest-preloads
:%=$(objpfx
)%.so
)
323 LD_PRELOAD
=$(subst $(empty
) ,:,$(strip $(preloadtest-preloads
:=.so
)))
325 $(objpfx
)loadfail
: $(libdl
)
326 LDFLAGS-loadfail
= -rdynamic
328 $(objpfx
)loadfail.out
: $(objpfx
)failobj.so
330 $(objpfx
)multiload
: $(libdl
)
331 LDFLAGS-multiload
= -rdynamic
332 CFLAGS-multiload.c
= -DOBJDIR
=\"$(elf-objpfx
)\"
334 $(objpfx
)multiload.out
: $(objpfx
)testobj1.so
336 $(objpfx
)origtest
: $(libdl
)
337 LDFLAGS-origtest
= -rdynamic
338 $(objpfx
)origtest.out
: $(objpfx
)testobj1.so
340 ifeq ($(have-thread-library
),yes
)
341 $(objpfx
)resolvfail
: $(libdl
) $(shared-thread-library
)
343 $(objpfx
)resolvfail
: $(libdl
)
346 $(objpfx
)constload1
: $(libdl
)
347 $(objpfx
)constload1.out
: $(objpfx
)constload2.so
$(objpfx
)constload3.so
349 $(objpfx
)order
: $(addprefix $(objpfx
),dep4.so dep3.so dep2.so dep1.so
)
351 $(objpfx
)order.out
: $(objpfx
)order
352 $(elf-objpfx
)$(rtld-installed-name
) \
353 --library-path
$(rpath-link
)$(patsubst %,:%,$(sysdep-library-path
)) \
355 (echo
"0123456789" | cmp
$@
-) > /dev
/null
357 $(objpfx
)vismain
: $(addprefix $(objpfx
),vismod1.so vismod2.so
)
358 $(objpfx
)vismain.out
: $(addprefix $(objpfx
),vismod3.so
)
359 vismain-ENV
= LD_PRELOAD
=$(addprefix $(objpfx
),vismod3.so
)
361 $(objpfx
)noload
: $(objpfx
)testobj1.so
362 LDFLAGS-noload
= -rdynamic
363 $(objpfx
)noload.out
: $(objpfx
)testobj5.so
365 LDFLAGS-nodelete
= -rdynamic
366 LDFLAGS-nodelmod1.so
= -Wl
,--enable-new-dtags
,-z
,nodelete
367 LDFLAGS-nodelmod4.so
= -Wl
,--enable-new-dtags
,-z
,nodelete
368 $(objpfx
)nodelete
: $(libdl
)
369 $(objpfx
)nodelete.out
: $(objpfx
)nodelmod1.so
$(objpfx
)nodelmod2.so \
370 $(objpfx
)nodelmod3.so
372 LDFLAGS-nodlopenmod.so
= -Wl
,--enable-new-dtags
,-z
,nodlopen
373 $(objpfx
)nodlopen
: $(libdl
)
374 $(objpfx
)nodlopen.out
: $(objpfx
)nodlopenmod.so
376 $(objpfx
)filtmod1.so
: $(objpfx
)filtmod1.os
$(objpfx
)filtmod2.so
377 $(LINK.o
) -shared
-o
$@
-B
$(csu-objpfx
) $(LDFLAGS.so
) \
378 -L
$(subst :, -L
,$(rpath-link
)) \
379 -Wl
,-rpath-link
=$(rpath-link
) \
380 $< -Wl
,-F
,$(objpfx
)filtmod2.so
381 $(objpfx
)filter: $(objpfx
)filtmod1.so
383 $(objpfx
)unload
: $(libdl
)
384 $(objpfx
)unload.out
: $(objpfx
)unloadmod.so
386 $(objpfx
)reldep
: $(libdl
)
387 $(objpfx
)reldep.out
: $(objpfx
)reldepmod1.so
$(objpfx
)reldepmod2.so
389 $(objpfx
)reldep2
: $(libdl
)
390 $(objpfx
)reldep2.out
: $(objpfx
)reldepmod1.so
$(objpfx
)reldepmod3.so
392 $(objpfx
)reldep3
: $(libdl
)
393 $(objpfx
)reldep3.out
: $(objpfx
)reldepmod1.so
$(objpfx
)reldepmod4.so
395 $(objpfx
)reldep4
: $(libdl
)
396 $(objpfx
)reldep4.out
: $(objpfx
)reldep4mod1.so
$(objpfx
)reldep4mod2.so
398 $(objpfx
)next
: $(objpfx
)nextmod1.so
$(objpfx
)nextmod2.so
$(libdl
)
400 $(objpfx
)unload2
: $(libdl
)
401 $(objpfx
)unload2.out
: $(objpfx
)unload2mod.so
$(objpfx
)unload2dep.so
403 $(objpfx
)lateglobal
: $(libdl
)
404 $(objpfx
)lateglobal.out
: $(objpfx
)ltglobmod1.so
$(objpfx
)ltglobmod2.so
406 $(objpfx
)tst-pathopt
: $(libdl
)
407 $(objpfx
)tst-pathopt.out
: tst-pathopt.sh
$(objpfx
)tst-pathopt \
408 $(objpfx
)pathoptobj.so
409 $(SHELL
) -e
$< $(common-objpfx
)
411 $(objpfx
)initfirst
: $(libdl
)
412 $(objpfx
)initfirst.out
: $(objpfx
)firstobj.so
414 $(objpfx
)global
: $(objpfx
)globalmod1.so
415 $(objpfx
)global.out
: $(objpfx
)reldepmod1.so