diff options
Diffstat (limited to 'LibC')
-rw-r--r-- | LibC/.gitignore | 1 | ||||
-rw-r--r-- | LibC/Makefile | 18 | ||||
-rw-r--r-- | LibC/SharedBuffer.cpp | 1 | ||||
-rw-r--r-- | LibC/crt0.cpp | 28 | ||||
-rw-r--r-- | LibC/crti.S | 9 | ||||
-rw-r--r-- | LibC/crtn.S | 7 | ||||
-rwxr-xr-x | LibC/install.sh | 2 |
7 files changed, 56 insertions, 10 deletions
diff --git a/LibC/.gitignore b/LibC/.gitignore index 34cdcf1531..e10af1241f 100644 --- a/LibC/.gitignore +++ b/LibC/.gitignore @@ -1,4 +1,5 @@ *.o *.no +*.ao *.d libc.a diff --git a/LibC/Makefile b/LibC/Makefile index 471e70c205..d75ef1f585 100644 --- a/LibC/Makefile +++ b/LibC/Makefile @@ -40,17 +40,16 @@ LIBC_OBJS = \ poll.o \ locale.o \ arpa/inet.o \ - netdb.o \ - crt0.o + netdb.o -ASM_OBJS = setjmp.no +ASM_OBJS = setjmp.no crti.ao crtn.ao CPP_OBJS = $(AK_OBJS) $(WIDGETS_OBJS) $(LIBC_OBJS) LIBRARY = libc.a STANDARD_FLAGS = -std=c++17 WARNING_FLAGS = -Wextra -Wall -Wundef -Wcast-qual -Wwrite-strings -Wimplicit-fallthrough -FLAVOR_FLAGS = -fno-exceptions -fno-rtti +FLAVOR_FLAGS = -fno-exceptions -fno-rtti -fno-sized-deallocation OPTIMIZATION_FLAGS = -Os INCLUDE_FLAGS = -I.. -I. @@ -60,8 +59,14 @@ CXXFLAGS = -MMD -MP $(WARNING_FLAGS) $(OPTIMIZATION_FLAGS) $(FLAVOR_FLAGS) $(STA CXX = i686-pc-serenity-g++ LD = i686-pc-serenity-ld AR = i686-pc-serenity-ar +AS = i686-pc-serenity-as -all: $(LIBRARY) +all: $(LIBRARY) startfiles + +startfiles: + @echo "CXX $<"; $(CXX) $(CXXFLAGS) -o crt0.o -c crt0.cpp + cp crti.ao crti.o + cp crtn.ao crtn.o $(LIBRARY): $(CPP_OBJS) $(ASM_OBJS) @echo "LIB $@"; $(AR) rcs $@ $(CPP_OBJS) $(ASM_OBJS) @@ -72,6 +77,9 @@ $(LIBRARY): $(CPP_OBJS) $(ASM_OBJS) %.no: %.asm @echo "NASM $@"; nasm -f elf -o $@ $< +%.ao: %.S + @echo "AS $@"; $(AS) -o $@ $< + -include $(OBJS:%.o=%.d) clean: diff --git a/LibC/SharedBuffer.cpp b/LibC/SharedBuffer.cpp index dad0841499..3df9a3b239 100644 --- a/LibC/SharedBuffer.cpp +++ b/LibC/SharedBuffer.cpp @@ -1,6 +1,7 @@ #include <LibC/SharedBuffer.h> #include <unistd.h> #include <stdio.h> +#include <AK/kmalloc.h> RetainPtr<SharedBuffer> SharedBuffer::create(pid_t peer, int size) { diff --git a/LibC/crt0.cpp b/LibC/crt0.cpp index a607390e14..10176515d3 100644 --- a/LibC/crt0.cpp +++ b/LibC/crt0.cpp @@ -10,17 +10,31 @@ int errno; char** environ; //bool __environ_is_malloced; -void __malloc_init(); -void __stdio_init(); +void __libc_init() +{ + void __malloc_init(); + __malloc_init(); + + void __stdio_init(); + __stdio_init(); +} int _start(int argc, char** argv, char** env) { - errno = 0; environ = env; //__environ_is_malloced = false; - __stdio_init(); - __malloc_init(); + __libc_init(); + + extern void _init(); + _init(); + + extern void (*__init_array_start[])(int, char**, char**) __attribute__((visibility("hidden"))); + extern void (*__init_array_end[])(int, char**, char**) __attribute__((visibility("hidden"))); + + const size_t size = __init_array_end - __init_array_start; + for (size_t i = 0; i < size; i++) + (*__init_array_start[i])(argc, argv, env); int status = main(argc, argv); @@ -37,4 +51,8 @@ int _start(int argc, char** argv, char** env) assert(false); } +void __cxa_atexit() +{ +} + } diff --git a/LibC/crti.S b/LibC/crti.S new file mode 100644 index 0000000000..a67c77c71c --- /dev/null +++ b/LibC/crti.S @@ -0,0 +1,9 @@ +.global _init +.section .init +_init: + push %ebp + +.global _fini +.section .fini +_fini: + push %ebp diff --git a/LibC/crtn.S b/LibC/crtn.S new file mode 100644 index 0000000000..5fdc3d08a0 --- /dev/null +++ b/LibC/crtn.S @@ -0,0 +1,7 @@ +.section .init + pop %ebp + ret + +.section .fini + pop %ebp + ret diff --git a/LibC/install.sh b/LibC/install.sh index f2d52755dd..8b78656ecf 100755 --- a/LibC/install.sh +++ b/LibC/install.sh @@ -10,3 +10,5 @@ cp arpa/*.h ../Root/usr/include/arpa/ cp netinet/*.h ../Root/usr/include/netinet/ cp libc.a ../Root/usr/lib/ cp crt0.o ../Root/usr/lib/ +cp crti.ao ../Root/usr/lib/crti.o +cp crtn.ao ../Root/usr/lib/crtn.o |