From 5512124119b5d17824a29ec3ceec5e85b34eb932 Mon Sep 17 00:00:00 2001 From: Kevin Lange Date: Thu, 15 Dec 2016 19:49:10 +0900 Subject: [PATCH] Merge linker Makefile and prettify --- Makefile | 49 +++++++++++++++++++++++++++++++++++++----------- linker/Makefile | 41 ---------------------------------------- linker/README.md | 6 ------ linker/demo.c | 11 ----------- linker/demob.c | 6 ------ linker/libdemo.c | 15 --------------- 6 files changed, 38 insertions(+), 90 deletions(-) delete mode 100644 linker/Makefile delete mode 100644 linker/README.md delete mode 100644 linker/demo.c delete mode 100644 linker/demob.c delete mode 100644 linker/libdemo.c diff --git a/Makefile b/Makefile index d0092b42..333bf1c8 100644 --- a/Makefile +++ b/Makefile @@ -183,9 +183,9 @@ KERNEL_ASMOBJS = $(filter-out kernel/symbols.o,$(patsubst %.S,%.o,$(wildcard ker # Kernel # ################ toaruos-kernel: ${KERNEL_ASMOBJS} ${KERNEL_OBJS} kernel/symbols.o - @${BEG} "CC" "$<" + @${BEG} "CC" "$@" @${CC} -T kernel/link.ld ${CFLAGS} -nostdlib -o toaruos-kernel ${KERNEL_ASMOBJS} ${KERNEL_OBJS} kernel/symbols.o -lgcc ${ERRORS} - @${END} "CC" "$<" + @${END} "CC" "$@" @${INFO} "--" "Kernel is ready!" kernel/symbols.o: ${KERNEL_ASMOBJS} ${KERNEL_OBJS} util/generate_symbols.py @@ -265,16 +265,43 @@ hdd/usr/lib/libnetwork.a: userspace/lib/network.o @${AR} rcs $@ ${CORE_LIBS} @${END} "AR" "$@" -# Bad implementations of shared libraries -hdd/usr/lib/libc.so: ${TOOLCHAIN}/lib/libc.a - cd linker; make libc.so - mkdir -p hdd/usr/lib - cp linker/libc.so hdd/usr/lib/ +hdd/usr/lib: + @mkidr -p hdd/usr/lib -hdd/lib/ld.so: linker/linker.c - cd linker; make ld.so - mkdir -p hdd/lib - cp linker/ld.so hdd/lib/ +# Bad implementations of shared libraries +hdd/usr/lib/libc.so: ${TOOLCHAIN}/lib/libc.a | hdd/usr/lib + @${BEG} "SO" "$@" + @cp ${TOARU_SYSROOT}/usr/lib/libc.a libc.a + @# init and fini don't belong in our shared object + @${AR} d libc.a lib_a-init.o + @${AR} d libc.a lib_a-fini.o + @# Remove references to newlib's reentrant malloc + @${AR} d libc.a lib_a-calloc.o + @${AR} d libc.a lib_a-callocr.o + @${AR} d libc.a lib_a-cfreer.o + @${AR} d libc.a lib_a-freer.o + @${AR} d libc.a lib_a-malignr.o + @${AR} d libc.a lib_a-mallinfor.o + @${AR} d libc.a lib_a-mallocr.o + @${AR} d libc.a lib_a-malloptr.o + @${AR} d libc.a lib_a-mallstatsr.o + @${AR} d libc.a lib_a-msizer.o + @${AR} d libc.a lib_a-pvallocr.o + @${AR} d libc.a lib_a-realloc.o + @${AR} d libc.a lib_a-reallocr.o + @${AR} d libc.a lib_a-vallocr.o + @${CC} -shared -o $@ -Wl,--whole-archive libc.a -Wl,--no-whole-archive ${ERRORS} + @rm libc.a + @${END} "SO" "$@" + + +hdd/lib: + @mkdir -p hdd/lib + +hdd/lib/ld.so: linker/linker.c | hdd/lib + @${BEG} "CC" "$<" + @${CC} -static -Wl,-static -std=c99 -g -U__STRICT_ANSI__ -o $@ -Os -T linker/link.ld $< ${ERRORS} + @${END} "CC" "$<" define basic-so-wrapper hdd/usr/lib/lib$(1).so: ${TOOLCHAIN}/lib/lib$(1).a diff --git a/linker/Makefile b/linker/Makefile deleted file mode 100644 index 62a6845c..00000000 --- a/linker/Makefile +++ /dev/null @@ -1,41 +0,0 @@ -CC=i686-pc-toaru-gcc -AR=i686-pc-toaru-ar - -.PHONY: all go -all: ld.so libdemo.so demo demob libc.so - -ld.so: linker.c link.ld - i686-pc-toaru-gcc -static -Wl,-static -std=c99 -g -U__STRICT_ANSI__ -o ld.so -Os -T link.ld linker.c - -demo: demo.c libc.so libdemo.so - i686-pc-toaru-gcc -o demo -g demo.c -L. -ldemo -lc - -demob: demob.c libc.so - i686-pc-toaru-gcc -o demob demob.c -L. -lc - -libdemo.so: libdemo.c libc.so - i686-pc-toaru-gcc -shared -fPIC -Wl,-soname,libdemo.so -o libdemo.so libdemo.c -lc - -libc.so: ${TOARU_SYSROOT}/usr/lib/libc.a - cp ${TOARU_SYSROOT}/usr/lib/libc.a libc.a - # init and fini don't belong in our shared object - ${AR} d libc.a lib_a-init.o - ${AR} d libc.a lib_a-fini.o - # Remove references to newlib's reentrant malloc - ${AR} d libc.a lib_a-calloc.o - ${AR} d libc.a lib_a-callocr.o - ${AR} d libc.a lib_a-cfreer.o - ${AR} d libc.a lib_a-freer.o - ${AR} d libc.a lib_a-malignr.o - ${AR} d libc.a lib_a-mallinfor.o - ${AR} d libc.a lib_a-mallocr.o - ${AR} d libc.a lib_a-malloptr.o - ${AR} d libc.a lib_a-mallstatsr.o - ${AR} d libc.a lib_a-msizer.o - ${AR} d libc.a lib_a-pvallocr.o - ${AR} d libc.a lib_a-realloc.o - ${AR} d libc.a lib_a-reallocr.o - ${AR} d libc.a lib_a-vallocr.o - ${CC} -shared -o libc.so -Wl,--whole-archive libc.a -Wl,--no-whole-archive - rm libc.a - diff --git a/linker/README.md b/linker/README.md deleted file mode 100644 index 33ed8225..00000000 --- a/linker/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# ToaruOS ld.so - -This is a (work-in-progress) dynamic ELF linker/loader for ToaruOS. - -This is a mostly-working loader capable of at least loading basic binaries that depend on a shared libc. There are still some bugs to work out, and it is not capable of loading some more complicated binaries. - diff --git a/linker/demo.c b/linker/demo.c deleted file mode 100644 index 704305bc..00000000 --- a/linker/demo.c +++ /dev/null @@ -1,11 +0,0 @@ -#include - -extern int return_42(void); - -int main(int argc, char * argv[]) { - fprintf(stderr, "Hello world!\n"); - - fprintf(stderr, "Hello, dynamic world: %d\n", return_42()); - - return 0; -} diff --git a/linker/demob.c b/linker/demob.c deleted file mode 100644 index 9cc7c022..00000000 --- a/linker/demob.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main(int argc, char * argv[]) { - puts("Hello, world!"); - return 0; -} diff --git a/linker/libdemo.c b/linker/libdemo.c deleted file mode 100644 index f2655f8c..00000000 --- a/linker/libdemo.c +++ /dev/null @@ -1,15 +0,0 @@ -#include -#include - - -__attribute__((constructor)) -static void butts(void) { - fprintf(stderr, "I'm a constructor!\n"); -} - -extern char * _username; - -int return_42(void) { - fprintf(stderr, "I am a dynamically loaded shared object. pid = %d\n", getpid()); - return 42; -}