Update.
[glibc.git] / elf / Makefile
blobd452ee7a06acdf7e9eb738c63665d18413ad59ae
1 # Copyright (C) 1995, 1996, 1997, 1998 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.
21 subdir := elf
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 dl-profstub
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
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-hash.h soinit.c sofini.c ldd.sh.in ldd.bash.in eval.c \
40 genrtldtbl.awk atomicity.h dl-procinfo.h ldsodefs.h \
41 dl-librecon.h interp.c sln.c
43 extra-libs = libdl
44 extra-libs-others = $(extra-libs)
45 libdl-routines := dlopen dlclose dlsym dlvsym dlerror dladdr
47 before-compile = $(objpfx)trusted-dirs.h
50 all: # Make this the default target; it will be defined in Rules.
52 include ../Makeconfig
54 ifeq ($(versioning),yes)
55 ld-map = $(common-objpfx)libc.map
56 endif
58 ifeq (yes,$(build-shared))
59 extra-objs = $(rtld-routines:=.os) soinit.os sofini.os eval.os interp.os
60 generated = librtld.os dl-allobjs.os ld.so trusted-dirs.h trusted-dirs.st
61 install-others = $(inst_slibdir)/$(rtld-installed-name)
62 install-bin = ldd
63 generated += ldd
64 endif
66 others = sprof sln
67 install-bin += sprof
68 others-static = sln
69 install-rootsbin = sln
71 ifeq (yes,$(has-ldconfig))
72 others-static += ldconfig
73 others += ldconfig
74 install-rootsbin += ldconfig
75 endif
77 include ../Rules
80 ifeq (yes,$(build-shared))
81 # Make sure these things are built in the `make lib' pass so they can be used
82 # to run programs during the `make others' pass.
83 lib-noranlib: $(objpfx)$(rtld-installed-name) \
84 $(addprefix $(objpfx),$(extra-objs))
85 endif
87 # Command to link into a larger single relocatable object.
88 reloc-link = $(LINK.o) -nostdlib -nostartfiles -r -o $@
90 $(objpfx)dl-allobjs.os: $(rtld-routines:%=$(objpfx)%.os)
91 $(reloc-link) $^
93 # Link together the dynamic linker into a single relocatable object.
94 $(objpfx)librtld.os: $(objpfx)dl-allobjs.os $(common-objpfx)libc_pic.a
95 $(reloc-link) '-Wl,-(' $^ -lgcc '-Wl,-)'
97 # Do we need a linker script?
98 rtld-ldscript-in := $(firstword $(wildcard $(+sysdep_dirs:%=%/rtld-ldscript.in)))
100 ifneq (,$(rtld-ldscript-in))
101 rtld-ldscript = $(objpfx)rtld-ldscript
102 generated += rtld-ldscript
104 LDFLAGS-rtld = -T $(rtld-ldscript)
105 before-compile += $(rtld-ldscript)
107 rtld-parms = $(wildcard $(+sysdep_dirs:%=%/rtld-parms))
108 include $(rtld-parms)
110 $(rtld-ldscript): $(rtld-ldscript-in) $(rtld-parms)
111 sed -e 's#@@rtld-oformat@@#$(rtld-oformat)#' \
112 -e 's#@@rtld-arch@@#$(rtld-arch)#' \
113 -e 's#@@rtld-entry@@#$(rtld-entry)#' \
114 -e 's#@@rtld-base@@#$(rtld-base)#' $< >$@
115 endif
117 $(objpfx)ld.so: $(objpfx)librtld.os $(addprefix $(objpfx),$(rtld-ldscript)) \
118 $(ld-map)
119 $(LINK.o) -nostdlib -nostartfiles -shared -o $@ \
120 -Wl,-rpath=$(default-rpath) $(LDFLAGS-rtld) \
121 $(filter-out $(rtld-ldscript) $(map-file),$^) \
122 $(load-map-file) -Wl,-soname=$(rtld-installed-name)
124 # The dl code in the static libc needs a default library path.
125 CFLAGS-dl-support.c = -D'DEFAULT_RPATH="$(default-rpath)"'
127 # interp.c exists just to get this string into the libraries.
128 CFLAGS-interp.c = -D'RUNTIME_LINKER="$(slibdir)/$(rtld-installed-name)"'
130 ifneq (ld.so,$(rtld-installed-name))
131 # Make sure ld.so.1 exists in the build directory so we can link
132 # against it.
133 $(objpfx)$(rtld-installed-name): $(objpfx)ld.so
134 rm -f $@
135 ln -s $(<F) $@
136 generated += $(rtld-installed-name)
137 endif
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: $(objpfx)trusted-dirs.st; @:
144 $(objpfx)trusted-dirs.st: Makefile $(..)Makeconfig
145 $(make-target-directory)
146 dirs="$(subst :, ,$(default-rpath) $(user-defined-trusted-dirs))"; \
147 for dir in $$dirs; do \
148 echo " \"$$dir/\","; \
149 done > ${@:st=T}
150 $(move-if-change) ${@:st=T} ${@:st=h}
151 touch $@
152 CPPFLAGS-dl-load.c = -I$(objpfx).
153 CFLAGS-dl-load.c += -Wno-uninitialized
155 # Specify the dependencies of libdl.so; its commands come from the generic
156 # rule to build a shared library.
157 $(objpfx)libdl.so: $(objpfx)libdl_pic.a $(common-objpfx)libc.so $(objpfx)ld.so
159 $(inst_slibdir)/$(rtld-version-installed-name): $(objpfx)ld.so $(+force)
160 $(do-install-program)
162 $(inst_slibdir)/$(rtld-installed-name): \
163 $(inst_slibdir)/$(rtld-version-installed-name)
164 $(make-shlib-link)
166 # Special target called by parent to install just the dynamic linker.
167 .PHONY: ldso_install
168 ldso_install: $(inst_slibdir)/$(rtld-installed-name)
171 common-ldd-rewrite = -e 's%@RTLD@%$(slibdir)/$(rtld-installed-name)%g' \
172 -e 's%@VERSION@%$(version)%g'
173 sh-ldd-rewrite = $(common-ldd-rewrite) -e 's%@BASH@%/bin/sh%g;s/\$$"/"/g'
174 bash-ldd-rewrite = $(common-ldd-rewrite) -e 's%@BASH@%$(BASH)%g' \
175 -e 's%@TEXTDOMAINDIR@%$(localedir)%g'
177 ifneq ($(have-bash2),yes)
178 ldd-shell = sh
179 else
180 ldd-shell = bash
181 endif
183 ifeq ($(ldd-rewrite-script),no)
184 define gen-ldd
185 sed $($(ldd-shell)-ldd-rewrite) < $< > $@.new
186 endef
187 else
188 define gen-ldd
189 sed $($(ldd-shell)-ldd-rewrite) < $< | sed -f $(ldd-rewrite-script) > $@.new
190 endef
191 endif
193 $(objpfx)ldd: ldd.bash.in $(common-objpfx)soversions.mk \
194 $(common-objpfx)config.make
195 $(gen-ldd)
196 chmod 555 $@.new
197 mv -f $@.new $@
200 ifeq ($(build-shared),yes)
201 $(objpfx)sprof: $(objpfx)libdl.so$(libdl.so-version)
202 else
203 $(objpfx)sprof: $(objpfx)libdl.a
204 endif
206 # muwahaha
208 LDFLAGS-dl.so = -Wl,-dynamic-linker,$(slibdir)/$(rtld-installed-name)
209 $(objpfx)libdl.so: $(objpfx)eval.os