1 # Copyright (C) 1995-1999, 2000 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 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.
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.
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.
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-symbol dl-support \
25 dl-addr enbl-secure dl-profstub dl-origin dl-libc dl-sym
27 # The core dynamic linking functions are in libc for the static and
29 dl-routines
= $(addprefix dl-
,load cache lookup object reloc deps \
30 runtime error init fini debug misc \
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
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 ldconfig.h ldconfig.c cache.c readlib.c readelflib.c \
46 dep1.c dep2.c dep3.c dep4.c
50 before-compile
= $(objpfx
)trusted-dirs.h
52 ifeq ($(versioning
),yes
)
53 ld-map
= $(common-objpfx
)ld.so.map
56 ifeq (yes
,$(build-shared
))
57 extra-objs
= $(rtld-routines
:=.os
) soinit.os sofini.os interp.os
58 generated
= librtld.os dl-allobjs.os
ld.so trusted-dirs.h trusted-dirs.st
59 install-others
= $(inst_slibdir
)/$(rtld-installed-name
)
67 install-rootsbin
= sln
69 ifeq (yes
,$(use-ldconfig
))
70 others-static
+= ldconfig
72 install-rootsbin
+= ldconfig
74 ldconfig-modules
:= cache readlib xmalloc xstrdup
75 extra-objs
+= $(ldconfig-modules
:=.o
)
77 # To find xmalloc.c and xstrdup.c
78 vpath
%.c ..
/locale
/programs
82 ifeq (yes
,$(build-shared
))
83 tests
= loadtest restest1 preloadtest loadfail multiload origtest resolvfail \
86 modules-names
= testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
87 testobj1_1 failobj constload2 constload3 \
89 extra-objs
+= $(modules-names
:=.os
)
93 ifeq (yes
,$(build-shared
))
94 # Make sure these things are built in the `make lib' pass so they can be used
95 # to run programs during the `make others' pass.
96 lib-noranlib
: $(objpfx
)$(rtld-installed-name
) \
97 $(addprefix $(objpfx
),$(extra-objs
))
100 # Command to link into a larger single relocatable object.
101 reloc-link
= $(LINK.o
) -nostdlib
-nostartfiles
-r
-o
$@
103 $(objpfx
)dl-allobjs.os
: $(rtld-routines
:%=$(objpfx
)%.os
)
106 # Link together the dynamic linker into a single relocatable object.
107 $(objpfx
)librtld.os
: $(objpfx
)dl-allobjs.os
$(common-objpfx
)libc_pic.a
108 $(reloc-link
) '-Wl,-(' $^
-lgcc
'-Wl,-)'
110 # Do we need a linker script?
111 rtld-ldscript-in
:= $(firstword $(wildcard $(+sysdep_dirs
:%=%/rtld-ldscript.in
)))
113 ifneq (,$(rtld-ldscript-in
))
114 rtld-ldscript
= $(objpfx
)rtld-ldscript
115 generated
+= rtld-ldscript
117 LDFLAGS-rtld
= -T
$(rtld-ldscript
)
118 before-compile
+= $(rtld-ldscript
)
120 rtld-parms
= $(wildcard $(+sysdep_dirs
:%=%/rtld-parms
))
121 include $(rtld-parms
)
123 $(rtld-ldscript
): $(rtld-ldscript-in
) $(rtld-parms
)
124 sed
-e
's#@@rtld-oformat@@#$(rtld-oformat)#' \
125 -e
's#@@rtld-arch@@#$(rtld-arch)#' \
126 -e
's#@@rtld-entry@@#$(rtld-entry)#' \
127 -e
's#@@rtld-base@@#$(rtld-base)#' $< >$@
130 $(objpfx
)ld.so
: $(objpfx
)librtld.os
$(rtld-ldscript
) $(ld-map
)
131 $(LINK.o
) -nostdlib
-nostartfiles
-shared
-o
$@
$(LDFLAGS-rtld
) \
132 $(filter-out $(rtld-ldscript
) $(map-file
),$^
) \
133 $(load-map-file
) -Wl
,-soname
=$(rtld-installed-name
)
135 # interp.c exists just to get this string into the libraries.
136 CFLAGS-interp.c
= -D
'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
138 ifneq (ld.so
,$(rtld-installed-name
))
139 # Make sure ld.so.1 exists in the build directory so we can link
141 $(objpfx
)$(rtld-installed-name
): $(objpfx
)ld.so
144 generated
+= $(rtld-installed-name
)
147 # Build a file mentioning all trustworthy directories to look for shared
148 # libraries when using LD_LIBRARY_PATH in a setuid program. The user can
149 # add directories to the list by defining $(user-defined-trusted-dirs)
150 # before starting make.
151 $(objpfx
)trusted-dirs.h
: $(objpfx
)trusted-dirs.st
; @
:
152 $(objpfx
)trusted-dirs.st
: Makefile
$(..
)Makeconfig
153 $(make-target-directory
)
154 echo
"$(subst :, ,$(default-rpath) $(user-defined-trusted-dirs))" \
155 |
$(AWK
) -f gen-trusted-dirs.awk
> ${@
:st
=T
};
156 $(move-if-change
) ${@
:st
=T
} ${@
:st
=h
}
158 CPPFLAGS-dl-load.c
= -I
$(objpfx
).
160 ifeq (yes
,$(build-shared
))
161 $(inst_slibdir
)/$(rtld-version-installed-name
): $(objpfx
)ld.so
$(+force)
162 $(make-target-directory
)
163 $(INSTALL_PROGRAM
) $< $@.new
165 $(inst_slibdir
)/$(rtld-installed-name
): \
166 $(inst_slibdir
)/$(rtld-version-installed-name
) \
167 $(inst_slibdir
)/libc-
$(version
).so
169 $(symbolic-link-prog
) $<.new
$@
172 $(symbolic-link-prog
) $(<F
) $@
175 # Special target called by parent to install just the dynamic linker.
177 ldso_install
: $(inst_slibdir
)/$(rtld-installed-name
)
181 common-ldd-rewrite
= -e
's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \
182 -e
's%@VERSION@%$(version)%g'
183 sh-ldd-rewrite
= $(common-ldd-rewrite
) -e
's%@BASH@%/bin/sh%g;s/\$$"/"/g'
184 bash-ldd-rewrite
= $(common-ldd-rewrite
) -e
's%@BASH@%$(BASH)%g' \
185 -e
's%@TEXTDOMAINDIR@%$(msgcatdir)%g'
187 ifneq ($(have-bash2
),yes
)
193 ifeq ($(ldd-rewrite-script
),no
)
195 sed
$($(ldd-shell
)-ldd-rewrite
) < $< > $@.new
199 sed
$($(ldd-shell
)-ldd-rewrite
) < $< | sed
-f
$(ldd-rewrite-script
) > $@.new
203 $(objpfx
)ldd
: ldd.bash.in
$(common-objpfx
)soversions.mk \
204 $(common-objpfx
)config.make
209 $(objpfx
)sprof
: $(libdl
)
211 $(objpfx
)ldconfig
: $(ldconfig-modules
:%=$(objpfx
)%.o
)
213 test-modules
= $(addprefix $(objpfx
),$(addsuffix .so
,$(modules-names
)))
214 generated
+= $(addsuffix .so
,$(modules-names
))
216 $(objpfx
)testobj1.so
: $(libdl
)
217 $(objpfx
)testobj1_1.so
: $(objpfx
)testobj1.so
$(libdl
)
218 $(objpfx
)testobj2.so
: $(objpfx
)testobj1.so
$(libdl
)
219 $(objpfx
)testobj3.so
: $(libdl
)
220 $(objpfx
)testobj4.so
: $(libdl
)
221 $(objpfx
)testobj5.so
: $(libdl
)
222 $(objpfx
)testobj6.so
: $(libdl
)
223 $(objpfx
)failobj.so
: $(objpfx
)testobj6.so
224 $(objpfx
)dep1.so
: $(objpfx
)dep2.so
$(objpfx
)dep4.so
225 $(objpfx
)dep2.so
: $(objpfx
)dep3.so
$(objpfx
)dep4.so
226 $(objpfx
)dep4.so
: $(objpfx
)dep3.so
228 $(test-modules
): $(objpfx
)%.so
: $(objpfx
)%.os
231 $(objpfx
)loadtest
: $(libdl
)
232 LDFLAGS-loadtest
= -rdynamic
234 $(objpfx
)loadtest.out
: $(test-modules
)
236 $(objpfx
)restest1
: $(objpfx
)testobj1.so
$(objpfx
)testobj1_1.so
$(libdl
)
237 LDFLAGS-restest1
= -rdynamic
239 $(objpfx
)restest1.out
: $(test-modules
)
241 preloadtest-preloads
= testobj1 testobj2 testobj3 testobj4 testobj5
242 $(objpfx
)preloadtest
: $(objpfx
)testobj6.so
243 LDFLAGS-preloadtest
= -rdynamic
244 $(objpfx
)preloadtest.out
: $(preloadtest-preloads
:%=$(objpfx
)%.so
)
246 LD_PRELOAD
=$(subst $(empty
) ,:,$(strip $(preloadtest-preloads
:=.so
)))
248 $(objpfx
)loadfail
: $(libdl
)
249 LDFLAGS-loadfail
= -rdynamic
251 $(objpfx
)loadfail.out
: $(objpfx
)failobj.so
253 $(objpfx
)multiload
: $(libdl
)
254 LDFLAGS-multiload
= -rdynamic
255 CFLAGS-multiload.c
= -DOBJDIR
=\"$(elf-objpfx
)\"
257 $(objpfx
)multiload.out
: $(objpfx
)testobj1.so
259 $(objpfx
)origtest
: $(libdl
)
260 $(objpfx
)origtest.out
: $(objpfx
)testobj1.so
262 ifeq ($(have-thread-library
),yes
)
263 $(objpfx
)resolvfail
: $(libdl
) $(shared-thread-library
)
265 $(objpfx
)resolvfail
: $(libdl
)
268 $(objpfx
)constload1
: $(libdl
)
269 $(objpfx
)constload1.out
: $(objpfx
)constload2.so
$(objpfx
)constload3.so
271 $(objpfx
)order
: $(addprefix $(objpfx
),dep4.so dep3.so dep2.so dep1.so
)
273 $(objpfx
)order.out
: $(objpfx
)order
274 $(elf-objpfx
)$(rtld-installed-name
) \
275 --library-path
$(rpath-link
)$(patsubst %,:%,$(sysdep-library-path
)) \
277 (echo
"0123456789" | cmp
$@
-) > /dev
/null