summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2016-01-25 19:29:55 -0500
committerRich Felker <dalias@aerifal.cx>2016-01-25 19:29:55 -0500
commit5552ce52000855906a5cb4f08f2e456573cca51f (patch)
tree7a6bd7fb987116843bfa9bd985dfb51f726cdd01 /Makefile
parent16f70388d4a876c216cbf1d829782ace41a07634 (diff)
downloadmusl-5552ce52000855906a5cb4f08f2e456573cca51f.tar.gz
move dynamic linker to its own top-level directory, ldso
this eliminates the last need for the SHARED macro to control how files in the src tree are compiled. the same code is used for both libc.a and libc.so, with additional code for the dynamic linker (from the new ldso tree) being added to libc.so but not libc.a. separate .o and .lo object files still exist for the src tree, but the only difference is that the .lo files are built as PIC. in the future, if/when we add dlopen support for static-linked programs, much of the code in dynlink.c may be moved back into the src tree, but properly factored into separate source files. in that case, the code in the ldso tree will be reduced to just the dynamic linker entry point, self-relocation, and loading of libraries needed by the main application.
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile18
1 files changed, 10 insertions, 8 deletions
diff --git a/Makefile b/Makefile
index 3a60cfc0..7c2cd77b 100644
--- a/Makefile
+++ b/Makefile
@@ -22,6 +22,8 @@ BASE_OBJS = $(patsubst $(srcdir)/%,%.o,$(basename $(BASE_SRCS)))
ARCH_SRCS = $(wildcard $(srcdir)/src/*/$(ARCH)/*.[csS])
ARCH_OBJS = $(patsubst $(srcdir)/%,%.o,$(basename $(ARCH_SRCS)))
REPLACED_OBJS = $(sort $(subst /$(ARCH)/,/,$(ARCH_OBJS)))
+LDSO_SRCS = $(sort $(wildcard $(srcdir)/ldso/*.c))
+LDSO_OBJS = $(patsubst $(srcdir)/%,obj/%.lo,$(basename $(LDSO_SRCS)))
OBJS = $(addprefix obj/, $(filter-out $(REPLACED_OBJS), $(sort $(BASE_OBJS) $(ARCH_OBJS))))
LOBJS = $(OBJS:.o=.lo)
GENH = obj/include/bits/alltypes.h
@@ -72,7 +74,7 @@ endif
all: $(ALL_LIBS) $(ALL_TOOLS)
-OBJ_DIRS = $(sort $(patsubst %/,%,$(dir $(ALL_LIBS) $(ALL_TOOLS) $(OBJS) $(GENH) $(GENH_INT))) $(addprefix obj/, crt crt/$(ARCH) include))
+OBJ_DIRS = $(sort $(patsubst %/,%,$(dir $(ALL_LIBS) $(ALL_TOOLS) $(OBJS) $(LDSO_OBJS) $(GENH) $(GENH_INT))) $(addprefix obj/, crt crt/$(ARCH) include))
$(ALL_LIBS) $(ALL_TOOLS) $(CRT_LIBS:lib/%=obj/crt/%) $(OBJS) $(LOBJS) $(GENH) $(GENH_INT): | $(OBJ_DIRS)
@@ -95,11 +97,11 @@ obj/src/internal/version.h: $(wildcard $(srcdir)/VERSION $(srcdir)/.git)
obj/src/internal/version.o obj/src/internal/version.lo: obj/src/internal/version.h
-obj/crt/rcrt1.o obj/src/ldso/dlstart.lo obj/src/ldso/dynlink.lo: $(srcdir)/src/internal/dynlink.h $(srcdir)/arch/$(ARCH)/reloc.h
+obj/crt/rcrt1.o obj/ldso/dlstart.lo obj/ldso/dynlink.lo: $(srcdir)/src/internal/dynlink.h $(srcdir)/arch/$(ARCH)/reloc.h
-obj/crt/crt1.o obj/crt/scrt1.o obj/crt/rcrt1.o obj/src/ldso/dlstart.lo: $(srcdir)/arch/$(ARCH)/crt_arch.h
+obj/crt/crt1.o obj/crt/scrt1.o obj/crt/rcrt1.o obj/ldso/dlstart.lo: $(srcdir)/arch/$(ARCH)/crt_arch.h
-obj/crt/rcrt1.o: $(srcdir)/src/ldso/dlstart.c
+obj/crt/rcrt1.o: $(srcdir)/ldso/dlstart.c
obj/crt/Scrt1.o obj/crt/rcrt1.o: CFLAGS_ALL += -fPIC
@@ -117,12 +119,12 @@ NOSSP_SRCS = $(wildcard crt/*.c) \
src/env/__libc_start_main.c src/env/__init_tls.c \
src/thread/__set_thread_area.c src/env/__stack_chk_fail.c \
src/string/memset.c src/string/memcpy.c \
- src/ldso/dlstart.c src/ldso/dynlink.c
+ ldso/dlstart.c ldso/dynlink.c
$(NOSSP_SRCS:%.c=obj/%.o) $(NOSSP_SRCS:%.c=obj/%.lo): CFLAGS_ALL += $(CFLAGS_NOSSP)
$(CRT_LIBS:lib/%=obj/crt/%): CFLAGS_ALL += -DCRT
-$(LOBJS): CFLAGS_ALL += -fPIC -DSHARED
+$(LOBJS) $(LDSO_OBJS): CFLAGS_ALL += -fPIC
CC_CMD = $(CC) $(CFLAGS_ALL) -c -o $@ $<
@@ -151,10 +153,10 @@ obj/%.lo: $(srcdir)/%.S
obj/%.lo: $(srcdir)/%.c $(GENH) $(IMPH)
$(CC_CMD)
-lib/libc.so: $(LOBJS)
+lib/libc.so: $(LOBJS) $(LDSO_OBJS)
$(CC) $(CFLAGS_ALL) $(LDFLAGS_ALL) -nostdlib -shared \
-Wl,-e,_dlstart -Wl,-Bsymbolic-functions \
- -o $@ $(LOBJS) $(LIBCC)
+ -o $@ $(LOBJS) $(LDSO_OBJS) $(LIBCC)
lib/libc.a: $(OBJS)
rm -f $@