]>
Commit | Line | Data |
---|---|---|
d66e34cd RM |
1 | # Makefile for elf subdirectory of GNU C Library. |
2 | ||
da2d1bc5 | 3 | # Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc. |
01cc0be6 RM |
4 | # This file is part of the GNU C Library. |
5 | ||
6 | # The GNU C Library is free software; you can redistribute it and/or | |
7 | # modify it under the terms of the GNU Library General Public License as | |
8 | # published by the Free Software Foundation; either version 2 of the | |
9 | # License, or (at your option) any later version. | |
10 | ||
11 | # The GNU C Library is distributed in the hope that it will be useful, | |
12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 | # Library General Public License for more details. | |
15 | ||
16 | # You should have received a copy of the GNU Library General Public | |
afd4eb37 UD |
17 | # License along with the GNU C Library; see the file COPYING.LIB. If not, |
18 | # write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
19 | # Boston, MA 02111-1307, USA. | |
01cc0be6 | 20 | |
d66e34cd RM |
21 | subdir := elf |
22 | ||
f21acc89 | 23 | headers = elf.h bits/elfclass.h bits/dlfcn.h link.h dlfcn.h |
cddcfecf | 24 | routines = $(dl-routines) dl-open dl-close dl-symbol dl-support \ |
a2b08ee5 | 25 | dl-addr enbl-secure |
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 \ |
ca34d7a7 | 31 | version profile) |
266180eb | 32 | # But they are absent from the shared libc, because that code is in ld.so. |
40a55d20 | 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. | |
37 | rtld-routines := rtld $(dl-routines) dl-sysdep dl-minimal | |
880f421f | 38 | ld-map = $(libc-map) |
266180eb | 39 | distribute = $(rtld-routines:=.c) dynamic-link.h do-rel.h dl-machine.h \ |
0a54e401 | 40 | dl-hash.h soinit.c sofini.c ldd.sh.in ldd.bash.in eval.c \ |
566efee2 | 41 | genrtldtbl.awk atomicity.h dl-procinfo.h |
d66e34cd | 42 | |
f0f1bf85 UD |
43 | extra-libs = libdl |
44 | extra-libs-others = $(extra-libs) | |
c84142e8 | 45 | libdl-routines := dlopen dlclose dlsym dlvsym dlerror dladdr |
714a562f | 46 | libdl-map := libdl.map |
d66e34cd | 47 | |
0a54e401 | 48 | before-compile = $(objpfx)trusted-dirs.h $(objpfx)rtldtbl.h |
fd26970f | 49 | |
01cc0be6 | 50 | |
bfc04a9f RM |
51 | all: # Make this the default target; it will be defined in Rules. |
52 | ||
d66e34cd RM |
53 | include ../Makeconfig |
54 | ||
55 | ifeq (yes,$(build-shared)) | |
40a55d20 | 56 | extra-objs = $(rtld-routines:=.os) soinit.os sofini.os eval.os |
da2d1bc5 | 57 | generated = librtld.os dl-allobjs.os ld.so trusted-dirs.h rtldtbl.h |
8d57beea | 58 | install-others = $(inst_slibdir)/$(rtld-installed-name) |
b122c703 | 59 | install-bin = ldd |
da2d1bc5 | 60 | generated += ldd |
f49bc43f | 61 | endif |
86d2c878 | 62 | |
ae828bc6 UD |
63 | others = sprof |
64 | install-bin = sprof | |
65 | ||
1ef32c3d | 66 | ifeq (yes,$(has-ldconfig)) |
e1586792 | 67 | others-static += ldconfig |
da2d1bc5 | 68 | others += ldconfig |
1ef32c3d | 69 | install-rootsbin = ldconfig |
1ef32c3d UD |
70 | endif |
71 | ||
01cc0be6 | 72 | include ../Rules |
d66e34cd | 73 | |
86d2c878 | 74 | |
1ef32c3d | 75 | ifeq (yes,$(build-shared)) |
a89d30d4 RM |
76 | # Make sure these things are built in the `make lib' pass so they can be used |
77 | # to run programs during the `make others' pass. | |
78 | lib-noranlib: $(objpfx)$(rtld-installed-name) \ | |
79 | $(addprefix $(objpfx),$(extra-objs)) | |
80 | endif | |
81 | ||
db2286f6 RM |
82 | # Command to link into a larger single relocatable object. |
83 | reloc-link = $(LINK.o) -nostdlib -nostartfiles -r -o $@ | |
84 | ||
40a55d20 | 85 | $(objpfx)dl-allobjs.os: $(rtld-routines:%=$(objpfx)%.os) |
db2286f6 RM |
86 | $(reloc-link) $^ |
87 | ||
86d2c878 | 88 | # Link together the dynamic linker into a single relocatable object. |
40a55d20 | 89 | $(objpfx)librtld.os: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a |
db2286f6 | 90 | $(reloc-link) '-Wl,-(' $^ -lgcc '-Wl,-)' |
d66e34cd | 91 | |
f21acc89 UD |
92 | # Do we need a linker script? |
93 | rtld-ldscript-in := $(firstword $(wildcard $(+sysdep_dirs:%=%/rtld-ldscript.in))) | |
14ea22e9 | 94 | |
f21acc89 | 95 | ifneq (,$(rtld-ldscript-in)) |
880f421f UD |
96 | rtld-ldscript = $(objpfx)rtld-ldscript |
97 | generated += rtld-ldscript | |
98 | ||
99 | LDFLAGS-rtld = -T $(rtld-ldscript) | |
100 | before-compile += $(rtld-ldscript) | |
f21acc89 | 101 | |
f21acc89 UD |
102 | rtld-parms = $(wildcard $(+sysdep_dirs:%=%/rtld-parms)) |
103 | include $(rtld-parms) | |
880f421f UD |
104 | |
105 | $(rtld-ldscript): $(rtld-ldscript-in) $(rtld-parms) | |
f21acc89 UD |
106 | sed -e 's#@@rtld-oformat@@#$(rtld-oformat)#' \ |
107 | -e 's#@@rtld-arch@@#$(rtld-arch)#' \ | |
108 | -e 's#@@rtld-entry@@#$(rtld-entry)#' \ | |
109 | -e 's#@@rtld-base@@#$(rtld-base)#' $< >$@ | |
880f421f | 110 | endif |
f21acc89 | 111 | |
3858abff | 112 | $(objpfx)ld.so: $(objpfx)librtld.os $(addprefix $(objpfx),$(rtld-ldscript)) |
f21acc89 UD |
113 | $(rtld-link) -Wl,-soname=$(rtld-installed-name) |
114 | ||
115 | define rtld-link | |
116 | $(LINK.o) -nostdlib -nostartfiles -shared -o $@ \ | |
117 | -Wl,-rpath=$(default-rpath) $(LDFLAGS-rtld) \ | |
880f421f UD |
118 | $(filter-out $(rtld-ldscript) $($(@F:.so=)-map),$^) \ |
119 | $(load-map-file:%=-Wl,--version-script=%) | |
f21acc89 | 120 | endef |
86d2c878 | 121 | |
266180eb RM |
122 | # The dl code in the static libc needs a default library path. |
123 | CFLAGS-dl-support.c = -D'DEFAULT_RPATH="$(default-rpath)"' | |
124 | ||
1ef32c3d | 125 | ifneq (ld.so,$(rtld-installed-name)) |
afd4eb37 | 126 | # Make sure ld.so.1 exists in the build directory so we can link |
852fc4b9 RM |
127 | # against it. |
128 | $(objpfx)$(rtld-installed-name): $(objpfx)ld.so | |
129 | rm -f $@ | |
f332db02 | 130 | ln -s $(<F) $@ |
da2d1bc5 | 131 | generated += $(rtld-installed-name) |
852fc4b9 RM |
132 | endif |
133 | ||
fd26970f UD |
134 | # Build a file mentioning all trustworthy directories to look for shared |
135 | # libraries when using LD_LIBRARY_PATH in a setuid program. The user can | |
136 | # add directories to the list by defining $(user-defined-trusted-dirs) | |
137 | # before starting make. | |
138 | $(objpfx)trusted-dirs.h: Makefile | |
1ef32c3d | 139 | $(make-target-directory) |
fd26970f UD |
140 | (for dir in `echo "$(default-rpath) $(user-defined-trusted-dirs)" | \ |
141 | sed 's/:/ /g'`; do \ | |
142 | echo " \"$$dir\","; \ | |
143 | done;) > $@T | |
144 | mv -f $@T $@ | |
0a54e401 UD |
145 | $(objpfx)rtldtbl.h: Makefile |
146 | $(make-target-directory) | |
f43ce637 | 147 | echo "$(default-rpath)" | awk -f genrtldtbl.awk > $@T |
0a54e401 | 148 | mv -f $@T $@ |
1ef32c3d | 149 | CPPFLAGS-dl-load.c = -I$(objdir)/$(subdir) |
56552e42 | 150 | CFLAGS-dl-load.c += -Wno-uninitialized |
86d2c878 | 151 | |
266180eb RM |
152 | # Specify the dependencies of libdl.so; its commands come from the generic |
153 | # rule to build a shared library. | |
7e0e6f50 | 154 | $(objpfx)libdl.so: $(objpfx)libdl_pic.a $(common-objpfx)libc.so $(objpfx)ld.so |
b122c703 | 155 | |
8d57beea | 156 | $(inst_slibdir)/$(rtld-version-installed-name): $(objpfx)ld.so |
1ef32c3d UD |
157 | $(do-install-program) |
158 | ||
8d57beea UD |
159 | $(inst_slibdir)/$(rtld-installed-name): \ |
160 | $(inst_slibdir)/$(rtld-version-installed-name) | |
1ef32c3d | 161 | $(make-shlib-link) |
b122c703 | 162 | |
da2d1bc5 UD |
163 | # Special target called by parent to install just the dynamic linker. |
164 | .PHONY: ldso_install | |
165 | ldso_install: $(inst_slibdir)/$(rtld-installed-name) | |
166 | ||
84384f5b | 167 | ifneq ($(have-bash2),yes) |
5290baf0 UD |
168 | $(objpfx)ldd: ldd.sh.in $(common-objpfx)version.mk \ |
169 | $(common-objpfx)soversions.mk $(common-objpfx)config.make | |
f0e44959 UD |
170 | sed -e 's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \ |
171 | -e 's%@VERSION@%$(version)%g' < $< > $@.new | |
094bacdb | 172 | chmod 555 $@.new |
b122c703 | 173 | mv -f $@.new $@ |
84384f5b | 174 | else |
5290baf0 UD |
175 | $(objpfx)ldd: ldd.bash.in $(common-objpfx)version.mk \ |
176 | $(common-objpfx)soversions.mk $(common-objpfx)config.make | |
84384f5b UD |
177 | sed -e 's%@BASH@%$(BASH)%g' \ |
178 | -e 's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \ | |
179 | -e 's%@VERSION@%$(version)%g' \ | |
180 | -e 's%@TEXTDOMAINDIR@%$(localedir)%g' < $< > $@.new | |
181 | chmod 555 $@.new | |
182 | mv -f $@.new $@ | |
183 | endif | |
ae828bc6 UD |
184 | |
185 | ifeq ($(build-shared),yes) | |
186 | $(objpfx)sprof: $(objpfx)libdl.so$(libdl.so-version) | |
187 | else | |
188 | $(objpfx)sprof: $(objpfx)libdl.a | |
189 | endif | |
96bda0ea RM |
190 | \f |
191 | # muwahaha | |
192 | ||
175b633d | 193 | LDFLAGS-dl.so = -Wl,-dynamic-linker,$(slibdir)/$(rtld-installed-name) |
40a55d20 | 194 | $(objpfx)libdl.so: $(objpfx)eval.os |