Merge linker Makefile and prettify

This commit is contained in:
Kevin Lange 2016-12-15 19:49:10 +09:00
parent 9013bc16f5
commit 5512124119
6 changed files with 38 additions and 90 deletions

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -1,11 +0,0 @@
#include <stdio.h>
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;
}

View File

@ -1,6 +0,0 @@
#include <stdio.h>
int main(int argc, char * argv[]) {
puts("Hello, world!");
return 0;
}

View File

@ -1,15 +0,0 @@
#include <stdio.h>
#include <string.h>
__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;
}