1 # Copyright (C) 1995, 1996, 1997, 1998, 1999 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 \
31 version profile preinit
)
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
48 before-compile
= $(objpfx
)trusted-dirs.h
50 ifeq ($(versioning
),yes
)
51 ld-map
= $(common-objpfx
)ld.so.map
54 ifeq (yes
,$(build-shared
))
55 extra-objs
= $(rtld-routines
:=.os
) soinit.os sofini.os interp.os
56 generated
= librtld.os dl-allobjs.os
ld.so trusted-dirs.h trusted-dirs.st
57 install-others
= $(inst_slibdir
)/$(rtld-installed-name
)
65 install-rootsbin
= sln
67 ifeq (yes
,$(has-ldconfig
))
68 others-static
+= ldconfig
70 install-rootsbin
+= ldconfig
73 ifeq (yes
,$(build-shared
))
74 tests
= loadtest restest1 preloadtest loadfail multiload origtest resolvfail
76 modules-names
= testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \
78 extra-objs
+= $(modules-names
:=.os
)
82 ifeq (yes
,$(build-shared
))
83 # Make sure these things are built in the `make lib' pass so they can be used
84 # to run programs during the `make others' pass.
85 lib-noranlib
: $(objpfx
)$(rtld-installed-name
) \
86 $(addprefix $(objpfx
),$(extra-objs
))
89 # Command to link into a larger single relocatable object.
90 reloc-link
= $(LINK.o
) -nostdlib
-nostartfiles
-r
-o
$@
92 $(objpfx
)dl-allobjs.os
: $(rtld-routines
:%=$(objpfx
)%.os
)
95 # Link together the dynamic linker into a single relocatable object.
96 $(objpfx
)librtld.os
: $(objpfx
)dl-allobjs.os
$(common-objpfx
)libc_pic.a
97 $(reloc-link
) '-Wl,-(' $^
-lgcc
'-Wl,-)'
99 # Do we need a linker script?
100 rtld-ldscript-in
:= $(firstword $(wildcard $(+sysdep_dirs
:%=%/rtld-ldscript.in
)))
102 ifneq (,$(rtld-ldscript-in
))
103 rtld-ldscript
= $(objpfx
)rtld-ldscript
104 generated
+= rtld-ldscript
106 LDFLAGS-rtld
= -T
$(rtld-ldscript
)
107 before-compile
+= $(rtld-ldscript
)
109 rtld-parms
= $(wildcard $(+sysdep_dirs
:%=%/rtld-parms
))
110 include $(rtld-parms
)
112 $(rtld-ldscript
): $(rtld-ldscript-in
) $(rtld-parms
)
113 sed
-e
's#@@rtld-oformat@@#$(rtld-oformat)#' \
114 -e
's#@@rtld-arch@@#$(rtld-arch)#' \
115 -e
's#@@rtld-entry@@#$(rtld-entry)#' \
116 -e
's#@@rtld-base@@#$(rtld-base)#' $< >$@
119 $(objpfx
)ld.so
: $(objpfx
)librtld.os
$(rtld-ldscript
) $(ld-map
)
120 $(LINK.o
) -nostdlib
-nostartfiles
-shared
-o
$@
$(LDFLAGS-rtld
) \
121 $(filter-out $(rtld-ldscript
) $(map-file
),$^
) \
122 $(load-map-file
) -Wl
,-soname
=$(rtld-installed-name
)
124 # interp.c exists just to get this string into the libraries.
125 CFLAGS-interp.c
= -D
'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
127 ifneq (ld.so
,$(rtld-installed-name
))
128 # Make sure ld.so.1 exists in the build directory so we can link
130 $(objpfx
)$(rtld-installed-name
): $(objpfx
)ld.so
133 generated
+= $(rtld-installed-name
)
136 # Build a file mentioning all trustworthy directories to look for shared
137 # libraries when using LD_LIBRARY_PATH in a setuid program. The user can
138 # add directories to the list by defining $(user-defined-trusted-dirs)
139 # before starting make.
140 $(objpfx
)trusted-dirs.h
: $(objpfx
)trusted-dirs.st
; @
:
141 $(objpfx
)trusted-dirs.st
: Makefile
$(..
)Makeconfig
142 $(make-target-directory
)
143 echo
"$(subst :, ,$(default-rpath) $(user-defined-trusted-dirs))" \
144 |
$(AWK
) -f gen-trusted-dirs.awk
> ${@
:st
=T
};
145 $(move-if-change
) ${@
:st
=T
} ${@
:st
=h
}
147 CPPFLAGS-dl-load.c
= -I
$(objpfx
).
148 CFLAGS-dl-load.c
+= -Wno-uninitialized
150 ifeq (yes
,$(build-shared
))
151 $(inst_slibdir
)/$(rtld-version-installed-name
): $(objpfx
)ld.so
$(+force)
152 $(do-install-program
)
154 $(inst_slibdir
)/$(rtld-installed-name
): \
155 $(inst_slibdir
)/$(rtld-version-installed-name
)
158 # Special target called by parent to install just the dynamic linker.
160 ldso_install
: $(inst_slibdir
)/$(rtld-installed-name
)
164 common-ldd-rewrite
= -e
's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \
165 -e
's%@VERSION@%$(version)%g'
166 sh-ldd-rewrite
= $(common-ldd-rewrite
) -e
's%@BASH@%/bin/sh%g;s/\$$"/"/g'
167 bash-ldd-rewrite
= $(common-ldd-rewrite
) -e
's%@BASH@%$(BASH)%g' \
168 -e
's%@TEXTDOMAINDIR@%$(msgcatdir)%g'
170 ifneq ($(have-bash2
),yes
)
176 ifeq ($(ldd-rewrite-script
),no
)
178 sed
$($(ldd-shell
)-ldd-rewrite
) < $< > $@.new
182 sed
$($(ldd-shell
)-ldd-rewrite
) < $< | sed
-f
$(ldd-rewrite-script
) > $@.new
186 $(objpfx
)ldd
: ldd.bash.in
$(common-objpfx
)soversions.mk \
187 $(common-objpfx
)config.make
192 $(objpfx
)sprof
: $(libdl
)
194 test-modules
= $(addprefix $(objpfx
),$(addsuffix .so
,$(modules-names
)))
195 generated
+= $(addsuffix .so
,$(modules-names
))
197 $(objpfx
)testobj1.so
: $(libdl
)
198 $(objpfx
)testobj1_1.so
: $(objpfx
)testobj1.so
$(libdl
)
199 $(objpfx
)testobj2.so
: $(objpfx
)testobj1.so
$(libdl
)
200 $(objpfx
)testobj3.so
: $(libdl
)
201 $(objpfx
)testobj4.so
: $(libdl
)
202 $(objpfx
)testobj5.so
: $(libdl
)
203 $(objpfx
)testobj6.so
: $(libdl
)
204 $(objpfx
)failobj.so
: $(objpfx
)testobj6.so
206 $(test-modules
): $(objpfx
)%.so
: $(objpfx
)%.os
209 $(objpfx
)loadtest
: $(libdl
)
210 LDFLAGS-loadtest
= -rdynamic
212 $(objpfx
)loadtest.out
: $(test-modules
)
214 $(objpfx
)restest1
: $(objpfx
)testobj1.so
$(objpfx
)testobj1_1.so
$(libdl
)
215 LDFLAGS-restest1
= -rdynamic
217 $(objpfx
)restest1.out
: $(test-modules
)
219 preloadtest-preloads
= testobj1 testobj2 testobj3 testobj4 testobj5
220 $(objpfx
)preloadtest
: $(objpfx
)testobj6.so
221 LDFLAGS-preloadtest
= -rdynamic
222 $(objpfx
)preloadtest.out
: $(preloadtest-preloads
:%=$(objpfx
)%.so
)
224 LD_PRELOAD
=$(subst $(empty
) ,:,$(strip $(preloadtest-preloads
:=.so
)))
226 $(objpfx
)loadfail
: $(libdl
)
227 LDFLAGS-loadfail
= -rdynamic
229 $(objpfx
)loadfail.out
: $(objpfx
)failobj.so
231 $(objpfx
)multiload
: $(libdl
)
232 LDFLAGS-multiload
= -rdynamic
233 CFLAGS-multiload.c
= -DOBJDIR
=\"$(elf-objpfx
)\"
235 $(objpfx
)multiload.out
: $(objpfx
)testobj1.so
237 $(objpfx
)origtest
: $(libdl
)
238 $(objpfx
)origtest.out
: $(objpfx
)testobj1.so
240 ifeq ($(have-thread-library
),yes
)
241 $(objpfx
)resolvfail
: $(libdl
) $(shared-thread-library
)
243 $(objpfx
)resolvfail
: $(libdl
)