]>
Commit | Line | Data |
---|---|---|
d66e34cd RM |
1 | # Makefile for elf subdirectory of GNU C Library. |
2 | ||
5290baf0 | 3 | # Copyright (C) 1995, 1996, 1997 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 \ |
ca34d7a7 | 25 | 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 | |
38 | distribute = $(rtld-routines:=.c) dynamic-link.h do-rel.h dl-machine.h \ | |
0a54e401 UD |
39 | dl-hash.h soinit.c sofini.c ldd.sh.in ldd.bash.in eval.c \ |
40 | genrtldtbl.awk | |
d66e34cd | 41 | |
f0f1bf85 UD |
42 | extra-libs = libdl |
43 | extra-libs-others = $(extra-libs) | |
c84142e8 | 44 | libdl-routines := dlopen dlclose dlsym dlvsym dlerror dladdr |
714a562f | 45 | libdl-map := libdl.map |
d66e34cd | 46 | |
0a54e401 | 47 | before-compile = $(objpfx)trusted-dirs.h $(objpfx)rtldtbl.h |
fd26970f | 48 | |
0a54e401 UD |
49 | # We need GNU awk for the genrtldtbl.awk script. |
50 | GAWK = gawk | |
01cc0be6 | 51 | |
bfc04a9f RM |
52 | all: # Make this the default target; it will be defined in Rules. |
53 | ||
d66e34cd RM |
54 | include ../Makeconfig |
55 | ||
56 | ifeq (yes,$(build-shared)) | |
40a55d20 UD |
57 | extra-objs = $(rtld-routines:=.os) soinit.os sofini.os eval.os |
58 | generated = librtld.os dl-allobjs.os trusted-dirs.h rtldtbl.h | |
8d57beea | 59 | install-others = $(inst_slibdir)/$(rtld-installed-name) |
b122c703 | 60 | install-bin = ldd |
f49bc43f | 61 | endif |
86d2c878 | 62 | |
1ef32c3d | 63 | ifeq (yes,$(has-ldconfig)) |
7cc27f44 | 64 | extra-objs += ldconfig.o |
1ef32c3d UD |
65 | install-rootsbin = ldconfig |
66 | ||
8d57beea | 67 | $(objpfx)ldconfig: $(objpfx)ldconfig.o |
1ef32c3d UD |
68 | $(CC) -nostdlib -nostartfiles -o $@ $(sysdep-LDFLAGS) -static \ |
69 | $(addprefix $(csu-objpfx),start.o) $(+preinit) \ | |
70 | $(filter-out $(addprefix $(csu-objpfx),start.o) $(+preinit) \ | |
71 | $(link-extra-libs) $(common-objpfx)libc% $(+postinit),$^) \ | |
72 | $(link-extra-libs) $(common-objpfx)libc.a $(gnulib) $(+postinit) | |
73 | endif | |
74 | ||
01cc0be6 | 75 | include ../Rules |
d66e34cd | 76 | |
86d2c878 | 77 | |
1ef32c3d | 78 | ifeq (yes,$(build-shared)) |
a89d30d4 RM |
79 | # Make sure these things are built in the `make lib' pass so they can be used |
80 | # to run programs during the `make others' pass. | |
81 | lib-noranlib: $(objpfx)$(rtld-installed-name) \ | |
82 | $(addprefix $(objpfx),$(extra-objs)) | |
83 | endif | |
84 | ||
db2286f6 RM |
85 | # Command to link into a larger single relocatable object. |
86 | reloc-link = $(LINK.o) -nostdlib -nostartfiles -r -o $@ | |
87 | ||
40a55d20 | 88 | $(objpfx)dl-allobjs.os: $(rtld-routines:%=$(objpfx)%.os) |
db2286f6 RM |
89 | $(reloc-link) $^ |
90 | ||
86d2c878 | 91 | # Link together the dynamic linker into a single relocatable object. |
40a55d20 | 92 | $(objpfx)librtld.os: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a |
db2286f6 | 93 | $(reloc-link) '-Wl,-(' $^ -lgcc '-Wl,-)' |
d66e34cd | 94 | |
f21acc89 UD |
95 | # Do we need a linker script? |
96 | rtld-ldscript-in := $(firstword $(wildcard $(+sysdep_dirs:%=%/rtld-ldscript.in))) | |
97 | ifneq (,$(rtld-ldscript-in)) | |
98 | LDFLAGS-rtld = -T $(objpfx)rtld-ldscript | |
99 | ||
100 | before-compile += $(objpfx)rtld-ldscript | |
101 | rtld-parms = $(wildcard $(+sysdep_dirs:%=%/rtld-parms)) | |
102 | include $(rtld-parms) | |
103 | generated += rtld-ldscript | |
104 | $(objpfx)rtld-ldscript: $(rtld-ldscript-in) $(rtld-parms) | |
105 | sed -e 's#@@rtld-oformat@@#$(rtld-oformat)#' \ | |
106 | -e 's#@@rtld-arch@@#$(rtld-arch)#' \ | |
107 | -e 's#@@rtld-entry@@#$(rtld-entry)#' \ | |
108 | -e 's#@@rtld-base@@#$(rtld-base)#' $< >$@ | |
109 | ||
40a55d20 | 110 | $(objpfx)ld.so: $(objpfx)librtld.os $(objpfx)rtld-ldscript |
f21acc89 UD |
111 | $(rtld-link) -Wl,-soname=$(rtld-installed-name) |
112 | ||
113 | define rtld-link | |
114 | $(LINK.o) -nostdlib -nostartfiles -shared -o $@ \ | |
115 | -Wl,-rpath=$(default-rpath) $(LDFLAGS-rtld) \ | |
116 | $(filter-out $(objpfx)rtld-ldscript,$^) | |
117 | endef | |
118 | else | |
40a55d20 | 119 | $(objpfx)ld.so: $(objpfx)librtld.os |
e3845371 | 120 | $(rtld-link) -Wl,-soname=$(rtld-installed-name) |
e3845371 RM |
121 | |
122 | define rtld-link | |
123 | $(LINK.o) -nostdlib -nostartfiles -shared -o $@ \ | |
124 | -Wl,-rpath=$(default-rpath) $^ | |
125 | endef | |
f21acc89 | 126 | endif |
86d2c878 | 127 | |
266180eb RM |
128 | # The dl code in the static libc needs a default library path. |
129 | CFLAGS-dl-support.c = -D'DEFAULT_RPATH="$(default-rpath)"' | |
130 | ||
1ef32c3d | 131 | ifneq (ld.so,$(rtld-installed-name)) |
afd4eb37 | 132 | # Make sure ld.so.1 exists in the build directory so we can link |
852fc4b9 RM |
133 | # against it. |
134 | $(objpfx)$(rtld-installed-name): $(objpfx)ld.so | |
135 | rm -f $@ | |
f332db02 | 136 | ln -s $(<F) $@ |
852fc4b9 RM |
137 | endif |
138 | ||
fd26970f UD |
139 | # Build a file mentioning all trustworthy directories to look for shared |
140 | # libraries when using LD_LIBRARY_PATH in a setuid program. The user can | |
141 | # add directories to the list by defining $(user-defined-trusted-dirs) | |
142 | # before starting make. | |
143 | $(objpfx)trusted-dirs.h: Makefile | |
1ef32c3d | 144 | $(make-target-directory) |
fd26970f UD |
145 | (for dir in `echo "$(default-rpath) $(user-defined-trusted-dirs)" | \ |
146 | sed 's/:/ /g'`; do \ | |
147 | echo " \"$$dir\","; \ | |
148 | done;) > $@T | |
149 | mv -f $@T $@ | |
0a54e401 UD |
150 | $(objpfx)rtldtbl.h: Makefile |
151 | $(make-target-directory) | |
152 | echo "$(default-rpath)" | $(GAWK) -f genrtldtbl.awk > $@T | |
153 | mv -f $@T $@ | |
1ef32c3d | 154 | CPPFLAGS-dl-load.c = -I$(objdir)/$(subdir) |
56552e42 | 155 | CFLAGS-dl-load.c += -Wno-uninitialized |
86d2c878 | 156 | |
266180eb RM |
157 | # Specify the dependencies of libdl.so; its commands come from the generic |
158 | # rule to build a shared library. | |
7e0e6f50 | 159 | $(objpfx)libdl.so: $(objpfx)libdl_pic.a $(common-objpfx)libc.so $(objpfx)ld.so |
b122c703 | 160 | |
8d57beea | 161 | $(inst_slibdir)/$(rtld-version-installed-name): $(objpfx)ld.so |
1ef32c3d UD |
162 | $(do-install-program) |
163 | ||
8d57beea UD |
164 | $(inst_slibdir)/$(rtld-installed-name): \ |
165 | $(inst_slibdir)/$(rtld-version-installed-name) | |
1ef32c3d | 166 | $(make-shlib-link) |
b122c703 | 167 | |
84384f5b | 168 | ifneq ($(have-bash2),yes) |
5290baf0 UD |
169 | $(objpfx)ldd: ldd.sh.in $(common-objpfx)version.mk \ |
170 | $(common-objpfx)soversions.mk $(common-objpfx)config.make | |
f0e44959 UD |
171 | sed -e 's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \ |
172 | -e 's%@VERSION@%$(version)%g' < $< > $@.new | |
094bacdb | 173 | chmod 555 $@.new |
b122c703 | 174 | mv -f $@.new $@ |
84384f5b | 175 | else |
5290baf0 UD |
176 | $(objpfx)ldd: ldd.bash.in $(common-objpfx)version.mk \ |
177 | $(common-objpfx)soversions.mk $(common-objpfx)config.make | |
84384f5b UD |
178 | sed -e 's%@BASH@%$(BASH)%g' \ |
179 | -e 's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \ | |
180 | -e 's%@VERSION@%$(version)%g' \ | |
181 | -e 's%@TEXTDOMAINDIR@%$(localedir)%g' < $< > $@.new | |
182 | chmod 555 $@.new | |
183 | mv -f $@.new $@ | |
184 | endif | |
96bda0ea RM |
185 | \f |
186 | # muwahaha | |
187 | ||
175b633d | 188 | LDFLAGS-dl.so = -Wl,-dynamic-linker,$(slibdir)/$(rtld-installed-name) |
40a55d20 | 189 | $(objpfx)libdl.so: $(objpfx)eval.os |