From: John Hodge Date: Mon, 26 May 2014 09:45:12 +0000 (+0800) Subject: Usermode/crt0 - Replaced crtbegin/crtend with crti/crtn X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=c3407f035bb2c887fe35d403d52d3bda3f1d5295;p=tpg%2Facess2.git Usermode/crt0 - Replaced crtbegin/crtend with crti/crtn --- diff --git a/Usermode/Libraries/crt0.o_src/Makefile b/Usermode/Libraries/crt0.o_src/Makefile index 3c208960..a68fefa0 100644 --- a/Usermode/Libraries/crt0.o_src/Makefile +++ b/Usermode/Libraries/crt0.o_src/Makefile @@ -4,7 +4,7 @@ -include ../Makefile.cfg -BIN = $(OUTPUTDIR)Libs/crt0.o $(OUTPUTDIR)Libs/crtbegin.o $(OUTPUTDIR)Libs/crtend.o +BIN = $(OUTPUTDIR)Libs/crt0.o $(OUTPUTDIR)Libs/crti.o $(OUTPUTDIR)Libs/crtn.o .PHONY: all clean install utest utest-build generate_exp @@ -22,6 +22,9 @@ utest generate_exp utest-build utest-run: $(OUTPUTDIR)Libs/%.o: %.c @mkdir -p $(dir $@) $(CC) -c $< -o $@ +$(OUTPUTDIR)Libs/%.o: $(ARCHDIR)-%.S + @mkdir -p $(dir $@) + $(CC) -c $< -o $@ #$(OUTPUTDIR)Libs/crt0.o: obj-$(ARCH)/crt0_asm.o obj-$(ARCH)/crt0_c.o # @mkdir -p $(dir $@) diff --git a/Usermode/Libraries/crt0.o_src/crt0.c b/Usermode/Libraries/crt0.o_src/crt0.c index 8363aea9..a87cfbf9 100644 --- a/Usermode/Libraries/crt0.o_src/crt0.c +++ b/Usermode/Libraries/crt0.o_src/crt0.c @@ -10,6 +10,8 @@ constructor_t _crtbegin_ctors[0] __attribute__((section(".ctors"))); exithandler_t _crt0_exit_handler; //extern constructor_t _crtbegin_ctors[]; +extern void _init(void); +extern void _fini(void); extern void _exit(int status) __attribute__((noreturn)); extern int main(int argc, char *argv[], char **envp); @@ -22,11 +24,13 @@ void start(int argc, char *argv[], char **envp) for( i = 0; _crtbegin_ctors[i]; i ++ ) _crtbegin_ctors[i](); + + _init(); rv = main(argc, argv, envp); if( _crt0_exit_handler ) _crt0_exit_handler(); - + _fini(); _exit(rv); } diff --git a/Usermode/Libraries/crt0.o_src/x86-crti.S b/Usermode/Libraries/crt0.o_src/x86-crti.S new file mode 100644 index 00000000..cebea3e9 --- /dev/null +++ b/Usermode/Libraries/crt0.o_src/x86-crti.S @@ -0,0 +1,15 @@ +.section .init +.global _init +.type _init, @function +_init: + push %ebp + movl %esp, %ebp + /* gcc will nicely put the contents of crtbegin.o's .init section here. */ + +.section .fini +.global _fini +.type _fini, @function +_fini: + push %ebp + movl %esp, %ebp + /* gcc will nicely put the contents of crtbegin.o's .fini section here. */ diff --git a/Usermode/Libraries/crt0.o_src/x86-crtn.S b/Usermode/Libraries/crt0.o_src/x86-crtn.S new file mode 100644 index 00000000..33957bfe --- /dev/null +++ b/Usermode/Libraries/crt0.o_src/x86-crtn.S @@ -0,0 +1,9 @@ +.section .init + /* gcc will nicely put the contents of crtend.o's .init section here. */ + popl %ebp + ret + +.section .fini + /* gcc will nicely put the contents of crtend.o's .fini section here. */ + popl %ebp + ret