diff options
author | Rich Felker <dalias@aerifal.cx> | 2016-01-25 19:29:55 -0500 |
---|---|---|
committer | Rich Felker <dalias@aerifal.cx> | 2016-01-25 19:29:55 -0500 |
commit | 5552ce52000855906a5cb4f08f2e456573cca51f (patch) | |
tree | 7a6bd7fb987116843bfa9bd985dfb51f726cdd01 | |
parent | 16f70388d4a876c216cbf1d829782ace41a07634 (diff) | |
download | musl-5552ce52000855906a5cb4f08f2e456573cca51f.tar.gz musl-5552ce52000855906a5cb4f08f2e456573cca51f.tar.xz musl-5552ce52000855906a5cb4f08f2e456573cca51f.zip |
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.
-rw-r--r-- | Makefile | 18 | ||||
-rw-r--r-- | crt/rcrt1.c | 2 | ||||
-rw-r--r-- | ldso/dlstart.c (renamed from src/ldso/dlstart.c) | 4 | ||||
-rw-r--r-- | ldso/dynlink.c (renamed from src/ldso/dynlink.c) | 2 | ||||
-rw-r--r-- | src/ldso/tlsdesc.c | 4 |
5 files changed, 11 insertions, 19 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 $@ diff --git a/crt/rcrt1.c b/crt/rcrt1.c index 9be117fd..e763d0ab 100644 --- a/crt/rcrt1.c +++ b/crt/rcrt1.c @@ -1,7 +1,7 @@ #define SHARED #define START "_start" #define _dlstart_c _start_c -#include "../src/ldso/dlstart.c" +#include "../ldso/dlstart.c" int main(); void _init() __attribute__((weak)); diff --git a/src/ldso/dlstart.c b/ldso/dlstart.c index 46f50114..4482d525 100644 --- a/src/ldso/dlstart.c +++ b/ldso/dlstart.c @@ -1,8 +1,6 @@ #include <stddef.h> #include "dynlink.h" -#ifdef SHARED - #ifndef START #define START "_dlstart" #endif @@ -146,5 +144,3 @@ void _dlstart_c(size_t *sp, size_t *dynv) GETFUNCSYM(&dls2, __dls2, base+dyn[DT_PLTGOT]); dls2((void *)base, sp); } - -#endif diff --git a/src/ldso/dynlink.c b/ldso/dynlink.c index e328679b..26a60b4c 100644 --- a/src/ldso/dynlink.c +++ b/ldso/dynlink.c @@ -1,4 +1,3 @@ -#ifdef SHARED #define _GNU_SOURCE #include <stdio.h> #include <stdlib.h> @@ -1930,4 +1929,3 @@ static void error(const char *fmt, ...) __dl_vseterr(fmt, ap); va_end(ap); } -#endif diff --git a/src/ldso/tlsdesc.c b/src/ldso/tlsdesc.c index 4bc654fa..a2985cb6 100644 --- a/src/ldso/tlsdesc.c +++ b/src/ldso/tlsdesc.c @@ -1,5 +1,3 @@ -#ifdef SHARED - #include <stddef.h> #include "libc.h" @@ -12,5 +10,3 @@ ptrdiff_t __tlsdesc_static() } weak_alias(__tlsdesc_static, __tlsdesc_dynamic); - -#endif |