-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
$(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 $@)
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);
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);
}
--- /dev/null
+.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. */
--- /dev/null
+.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