b2ea241808cba3db4d42f9d66c597c9702fe817e
[platform/upstream/glibc.git] / elf / Makefile
1 # Copyright (C) 1995, 1996, 1997, 1998 Free Software Foundation, Inc.
2 # This file is part of the GNU C Library.
3
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.
8
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.
13
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.
18
19 # Makefile for elf subdirectory of GNU C Library.
20
21 subdir          := elf
22
23 headers         = elf.h bits/elfclass.h bits/dlfcn.h link.h dlfcn.h
24 routines        = $(dl-routines) dl-open dl-close dl-symbol dl-support \
25                   dl-addr enbl-secure
26
27 # The core dynamic linking functions are in libc for the static and
28 # profiled libraries.
29 dl-routines     = $(addprefix dl-,load cache lookup object reloc deps \
30                                   runtime error init fini debug misc \
31                                   version profile)
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
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 ld-map          = $(..)libc.map
39 distribute      = $(rtld-routines:=.c) dynamic-link.h do-rel.h dl-machine.h \
40                   dl-hash.h soinit.c sofini.c ldd.sh.in ldd.bash.in eval.c \
41                   genrtldtbl.awk atomicity.h dl-procinfo.h ldsodefs.h \
42                   dl-librecon.h interp.c
43
44 extra-libs       = libdl
45 extra-libs-others = $(extra-libs)
46 libdl-routines  := dlopen dlclose dlsym dlvsym dlerror dladdr
47
48 before-compile = $(objpfx)trusted-dirs.h
49
50
51 all: # Make this the default target; it will be defined in Rules.
52
53 include ../Makeconfig
54
55 ifeq (yes,$(build-shared))
56 extra-objs      = $(rtld-routines:=.os) soinit.os sofini.os eval.os interp.os
57 generated       = librtld.os dl-allobjs.os ld.so trusted-dirs.h trusted-dirs.st
58 install-others  = $(inst_slibdir)/$(rtld-installed-name)
59 install-bin     = ldd
60 generated      += ldd
61 endif
62
63 others          = sprof
64 install-bin     += sprof
65
66 ifeq (yes,$(has-ldconfig))
67 others-static   += ldconfig
68 others          += ldconfig
69 install-rootsbin = ldconfig
70 endif
71
72 include ../Rules
73
74
75 ifeq (yes,$(build-shared))
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
82 # Command to link into a larger single relocatable object.
83 reloc-link = $(LINK.o) -nostdlib -nostartfiles -r -o $@
84
85 $(objpfx)dl-allobjs.os: $(rtld-routines:%=$(objpfx)%.os)
86         $(reloc-link) $^
87
88 # Link together the dynamic linker into a single relocatable object.
89 $(objpfx)librtld.os: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
90         $(reloc-link) '-Wl,-(' $^ -lgcc '-Wl,-)'
91
92 # Do we need a linker script?
93 rtld-ldscript-in := $(firstword $(wildcard $(+sysdep_dirs:%=%/rtld-ldscript.in)))
94
95 ifneq (,$(rtld-ldscript-in))
96 rtld-ldscript = $(objpfx)rtld-ldscript
97 generated += rtld-ldscript
98
99 LDFLAGS-rtld = -T $(rtld-ldscript)
100 before-compile += $(rtld-ldscript)
101
102 rtld-parms = $(wildcard $(+sysdep_dirs:%=%/rtld-parms))
103 include $(rtld-parms)
104
105 $(rtld-ldscript): $(rtld-ldscript-in) $(rtld-parms)
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)#' $< >$@
110 endif
111
112 $(objpfx)ld.so: $(objpfx)librtld.os $(addprefix $(objpfx),$(rtld-ldscript)) \
113                 $(ld-map)
114         $(LINK.o) -nostdlib -nostartfiles -shared -o $@         \
115                 -Wl,-rpath=$(default-rpath) $(LDFLAGS-rtld)     \
116                 $(filter-out $(rtld-ldscript) $(map-file),$^)   \
117                 $(load-map-file) -Wl,-soname=$(rtld-installed-name)
118
119 # The dl code in the static libc needs a default library path.
120 CFLAGS-dl-support.c = -D'DEFAULT_RPATH="$(default-rpath)"'
121
122 # interp.c exists just to get this string into the libraries.
123 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
124
125 ifneq (ld.so,$(rtld-installed-name))
126 # Make sure ld.so.1 exists in the build directory so we can link
127 # against it.
128 $(objpfx)$(rtld-installed-name): $(objpfx)ld.so
129         rm -f $@
130         ln -s $(<F) $@
131 generated += $(rtld-installed-name)
132 endif
133
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: $(objpfx)trusted-dirs.st; @:
139 $(objpfx)trusted-dirs.st: Makefile $(..)Makeconfig
140         $(make-target-directory)
141         dirs="$(subst :, ,$(default-rpath) $(user-defined-trusted-dirs))";   \
142         for dir in $$dirs; do                                                \
143           echo "  \"$$dir/\",";                                              \
144         done > ${@:st=T}
145         $(move-if-change) ${@:st=T} ${@:st=h}
146         touch $@
147 CPPFLAGS-dl-load.c = -I$(objpfx).
148 CFLAGS-dl-load.c += -Wno-uninitialized
149
150 # Specify the dependencies of libdl.so; its commands come from the generic
151 # rule to build a shared library.
152 $(objpfx)libdl.so: $(objpfx)libdl_pic.a $(common-objpfx)libc.so $(objpfx)ld.so
153
154 $(inst_slibdir)/$(rtld-version-installed-name): $(objpfx)ld.so $(+force)
155         $(do-install-program)
156
157 $(inst_slibdir)/$(rtld-installed-name): \
158   $(inst_slibdir)/$(rtld-version-installed-name)
159         $(make-shlib-link)
160
161 # Special target called by parent to install just the dynamic linker.
162 .PHONY: ldso_install
163 ldso_install: $(inst_slibdir)/$(rtld-installed-name)
164
165
166 sh-ldd-rewrite = -e 's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \
167                  -e 's%@VERSION@%$(version)%g'
168 bash-ldd-rewrite = $(sh-ldd-rewrite) -e 's%@BASH@%$(BASH)%g' \
169                    -e 's%@TEXTDOMAINDIR@%$(localedir)%g'
170
171 ifneq ($(have-bash2),yes)
172 ldd-shell = sh
173 else
174 ldd-shell = bash
175 endif
176
177 ifeq ($(ldd-rewrite-script),no)
178 define gen-ldd
179 sed $($(ldd-shell)-ldd-rewrite) < $< > $@.new
180 endef
181 else
182 define gen-ldd
183 sed $($(ldd-shell)-ldd-rewrite) < $< | sed -f $(ldd-rewrite-script) > $@.new
184 endef
185 endif
186
187 $(objpfx)ldd: ldd.$(ldd-shell).in $(common-objpfx)soversions.mk \
188               $(common-objpfx)config.make
189         $(gen-ldd)
190         chmod 555 $@.new
191         mv -f $@.new $@
192
193
194 ifeq ($(build-shared),yes)
195 $(objpfx)sprof: $(objpfx)libdl.so$(libdl.so-version)
196 else
197 $(objpfx)sprof: $(objpfx)libdl.a
198 endif
199 \f
200 # muwahaha
201
202 LDFLAGS-dl.so = -Wl,-dynamic-linker,$(slibdir)/$(rtld-installed-name)
203 $(objpfx)libdl.so: $(objpfx)eval.os