diff options
| author | grischka <grischka> | 2009-12-19 22:22:43 +0100 |
|---|---|---|
| committer | grischka <grischka> | 2009-12-19 22:22:43 +0100 |
| commit | 7fa712e00c5221d9373e8f8fa073e9e6fa064da1 (patch) | |
| tree | 21c5acbfcb4ddaa6d61d30fe79cfaece3ff7b5d9 /tccelf.c | |
| parent | 8bbde91f62291cb0383c2406ae6123be903c944b (diff) | |
| download | tinycc-7fa712e00c5221d9373e8f8fa073e9e6fa064da1.tar.gz tinycc-7fa712e00c5221d9373e8f8fa073e9e6fa064da1.tar.bz2 | |
win32: enable bounds checker & exception handler
exception handler borrowed from k1w1. Thanks.
Diffstat (limited to 'tccelf.c')
| -rw-r--r-- | tccelf.c | 75 |
1 files changed, 42 insertions, 33 deletions
@@ -1186,50 +1186,59 @@ static void add_init_array_defines(TCCState *s1, const char *section_name) s->sh_num, sym_end); } -/* add tcc runtime libraries */ -static void tcc_add_runtime(TCCState *s1) +static void tcc_add_bcheck(TCCState *s1) { -#if defined(CONFIG_TCC_BCHECK) || !defined(CONFIG_USE_LIBGCC) - char buf[1024]; -#endif - #ifdef CONFIG_TCC_BCHECK - if (s1->do_bounds_check) { - unsigned long *ptr; - Section *init_section; - unsigned char *pinit; - int sym_index; + unsigned long *ptr; + Section *init_section; + unsigned char *pinit; + int sym_index; - /* XXX: add an object file to do that */ - ptr = section_ptr_add(bounds_section, sizeof(unsigned long)); - *ptr = 0; - add_elf_sym(symtab_section, 0, 0, - ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, - bounds_section->sh_num, "__bounds_start"); - /* add bound check code */ - snprintf(buf, sizeof(buf), "%s/%s", s1->tcc_lib_path, "bcheck.o"); - tcc_add_file(s1, buf); -#ifdef TCC_TARGET_I386 - if (s1->output_type != TCC_OUTPUT_MEMORY) { - /* add 'call __bound_init()' in .init section */ - init_section = find_section(s1, ".init"); - pinit = section_ptr_add(init_section, 5); - pinit[0] = 0xe8; - put32(pinit + 1, -4); - sym_index = find_elf_sym(symtab_section, "__bound_init"); - put_elf_reloc(symtab_section, init_section, - init_section->data_offset - 4, R_386_PC32, sym_index); - } + if (0 == s1->do_bounds_check) + return; + + /* XXX: add an object file to do that */ + ptr = section_ptr_add(bounds_section, sizeof(unsigned long)); + *ptr = 0; + add_elf_sym(symtab_section, 0, 0, + ELFW(ST_INFO)(STB_GLOBAL, STT_NOTYPE), 0, + bounds_section->sh_num, "__bounds_start"); + /* add bound check code */ +#ifndef TCC_TARGET_PE + { + char buf[1024]; + snprintf(buf, sizeof(buf), "%s/%s", s1->tcc_lib_path, "bcheck.o"); + tcc_add_file(s1, buf); + } #endif +#ifdef TCC_TARGET_I386 + if (s1->output_type != TCC_OUTPUT_MEMORY) { + /* add 'call __bound_init()' in .init section */ + init_section = find_section(s1, ".init"); + pinit = section_ptr_add(init_section, 5); + pinit[0] = 0xe8; + put32(pinit + 1, -4); + sym_index = find_elf_sym(symtab_section, "__bound_init"); + put_elf_reloc(symtab_section, init_section, + init_section->data_offset - 4, R_386_PC32, sym_index); } #endif +#endif +} + +/* add tcc runtime libraries */ +static void tcc_add_runtime(TCCState *s1) +{ + tcc_add_bcheck(s1); + /* add libc */ if (!s1->nostdlib) { - tcc_add_library(s1, "c"); - #ifdef CONFIG_USE_LIBGCC + tcc_add_library(s1, "c"); tcc_add_file(s1, CONFIG_SYSROOT "/lib/libgcc_s.so.1"); #else + char buf[1024]; + tcc_add_library(s1, "c"); snprintf(buf, sizeof(buf), "%s/%s", s1->tcc_lib_path, "libtcc1.a"); tcc_add_file(s1, buf); #endif |
