/* 0 = .text rwx other rw (memory: min 2 pages) */ /* 1 = .text rx other rw (memory: min 3 pages) */ /* 2 = .text rx .rdata ro .data/.bss rw (memory: min 4 pages) */ tcc -vv -run ... shows some info. Also when compiled with -DMEM_DEBUG: tcc -bench -run ... shows some memory usage
Unified · Split
| @@ -491,7 +491,7 @@ test-install: tccdefs_.h · 490 unmodified lines | ||
| 491 | 491 | @$(MAKE) -C tests TESTINSTALL=yes #_all |
| 492 | 492 | |
| 493 | 493 | clean: |
| 494 | − @rm -f tcc$(EXESUF) tcc_c$(EXESUF) tcc_p$(EXESUF) *-tcc$(EXESUF) | |
| 494 | + @rm -f tcc *-tcc tcc_p tcc_c | |
| 495 | 495 | @rm -f tags ETAGS *.o *.a *.so* *.out *.log lib*.def *.exe *.dll |
| 496 | 496 | @rm -f a.out *.dylib *_.h *.pod *.tcov |
| 497 | 497 | @$(MAKE) -s -C lib $@ |
| @@ -2203,9 +2203,10 @@ PUB_FUNC void tcc_print_stats(TCCState *s1, unsigned total_time) · 2202 unmodified lines | ||
| 2203 | 2203 | #ifdef TCC_IS_NATIVE |
| 2204 | 2204 | if (s1->run_size) { |
| 2205 | 2205 | Section *s = s1->symtab; |
| 2206 | − int ms = s->data_offset + s->link->data_offset + s->hash->data_offset; | |
| 2206 | + unsigned ms = s->data_offset + s->link->data_offset + s->hash->data_offset; | |
| 2207 | + unsigned rs = s1->run_size; | |
| 2207 | 2208 | fprintf(stderr, ": %d to run, %d symbols, %d other,", |
| 2208 | − s1->run_size, ms, mem_cur_size - s1->run_size - ms); | |
| 2209 | + rs, ms, mem_cur_size - rs - ms); | |
| 2209 | 2210 | } |
| 2210 | 2211 | #endif |
| 2211 | 2212 | fprintf(stderr, " %d max (bytes)\n", mem_max_size); |
| @@ -135,7 +135,7 @@ extern long double strtold (const char *__nptr, char **__endptr); · 134 unmodified lines | ||
| 135 | 135 | /* include file debug */ |
| 136 | 136 | /* #define INC_DEBUG */ |
| 137 | 137 | /* memory leak debug (only for single threaded usage) */ |
| 138 | −/* #define MEM_DEBUG */ | |
| 138 | +/* #define MEM_DEBUG 1,2,3 */ | |
| 139 | 139 | /* assembler debug */ |
| 140 | 140 | /* #define ASM_DEBUG */ |
| 141 | 141 | |
| @@ -987,8 +987,7 @@ struct TCCState { · 845 unmodified lines | ||
| 987 | 987 | |
| 988 | 988 | #ifdef TCC_IS_NATIVE |
| 989 | 989 | const char *run_main; /* entry for tcc_run() */ |
| 990 | − void *run_mem; /* runtime_memory */ | |
| 991 | − void *run_ptr; /* ptr to runtime_memory (aligned) */ | |
| 990 | + void *run_ptr; /* runtime_memory */ | |
| 992 | 991 | unsigned run_size; /* size of runtime_memory */ |
| 993 | 992 | #ifdef _WIN64 |
| 994 | 993 | void *run_function_table; /* unwind data */ |
| @@ -732,7 +732,7 @@ static int pe_write(struct pe_info *pe) · 731 unmodified lines | ||
| 732 | 732 | |
| 733 | 733 | memcpy(psh->Name, sh_name, umin(strlen(sh_name), sizeof psh->Name)); |
| 734 | 734 | if (si->cls == sec_debug) |
| 735 | − need_strtab += pe_put_long_secname(psh->Name, sh_name); | |
| 735 | + need_strtab += pe_put_long_secname((char*)psh->Name, sh_name); | |
| 736 | 736 | |
| 737 | 737 | psh->Characteristics = si->pe_flags; |
| 738 | 738 | psh->VirtualAddress = addr; |
| @@ -127,7 +127,7 @@ ST_FUNC void expect(const char *msg) · 126 unmodified lines | ||
| 127 | 127 | #define tal_realloc(al, p, size) tal_realloc_impl(&al, p, size) |
| 128 | 128 | #define TAL_DEBUG_PARAMS |
| 129 | 129 | #else |
| 130 | −#define TAL_DEBUG 1 | |
| 130 | +#define TAL_DEBUG MEM_DEBUG | |
| 131 | 131 | //#define TAL_INFO 1 /* collect and dump allocators stats */ |
| 132 | 132 | #define tal_free(al, p) tal_free_impl(al, p, __FILE__, __LINE__) |
| 133 | 133 | #define tal_realloc(al, p, size) tal_realloc_impl(&al, p, size, __FILE__, __LINE__) |
| @@ -189,7 +189,7 @@ tail_call: · 55 unmodified lines | ||
| 189 | 189 | al->limit, al->size / 1024.0 / 1024.0, al->nb_peak, al->nb_total, al->nb_missed, |
| 190 | 190 | (al->peak_p - al->buffer) * 100.0 / al->size); |
| 191 | 191 | #endif |
| 192 | −#ifdef TAL_DEBUG | |
| 192 | +#if TAL_DEBUG && TAL_DEBUG != 3 /* do not check TAL leaks with -DMEM_DEBUG=3 */ | |
| 193 | 193 | if (al->nb_allocs > 0) { |
| 194 | 194 | uint8_t *p; |
| 195 | 195 | fprintf(stderr, "TAL_DEBUG: memory leak %d chunk(s) (limit= %d)\n", |
| @@ -203,7 +203,7 @@ tail_call: · 7 unmodified lines | ||
| 203 | 203 | } |
| 204 | 204 | p += header->size + sizeof(tal_header_t); |
| 205 | 205 | } |
| 206 | −#if MEM_DEBUG-0 == 2 | |
| 206 | +#if TAL_DEBUG == 2 | |
| 207 | 207 | exit(2); |
| 208 | 208 | #endif |
| 209 | 209 | } |
| @@ -128,9 +128,9 @@ static int rt_mem(TCCState *s1, int size) · 127 unmodified lines | ||
| 128 | 128 | return tcc_error_noabort("tccrun: could not map memory"); |
| 129 | 129 | ptr_diff = (char*)prw - (char*)ptr; /* = size; */ |
| 130 | 130 | //printf("map %p %p %p\n", ptr, prw, (void*)ptr_diff); |
| 131 | + size *= 2; | |
| 131 | 132 | #else |
| 132 | − s1->run_mem = tcc_malloc(size + PAGESIZE); /* one extra page to align malloc memory */ | |
| 133 | − ptr = (void*)PAGEALIGN(s1->run_mem); | |
| 133 | + ptr = tcc_malloc(size += PAGESIZE); /* one extra page to align malloc memory */ | |
| 134 | 134 | #endif |
| 135 | 135 | s1->run_ptr = ptr; |
| 136 | 136 | s1->run_size = size; |
| @@ -188,14 +188,14 @@ ST_FUNC void tcc_run_free(TCCState *s1) · 51 unmodified lines | ||
| 188 | 188 | st_unlink(s1); |
| 189 | 189 | size = s1->run_size; |
| 190 | 190 | #ifdef HAVE_SELINUX |
| 191 | − munmap(ptr, size * 2); | |
| 191 | + munmap(ptr, size); | |
| 192 | 192 | #else |
| 193 | 193 | /* unprotect memory to make it usable for malloc again */ |
| 194 | − protect_pages(ptr, size, 2 /*rw*/); | |
| 194 | + protect_pages((void*)PAGEALIGN(ptr), size - PAGESIZE, 2 /*rw*/); | |
| 195 | 195 | # ifdef _WIN64 |
| 196 | 196 | win64_del_function_table(s1->run_function_table); |
| 197 | 197 | # endif |
| 198 | − tcc_free(s1->run_mem); | |
| 198 | + tcc_free(ptr); | |
| 199 | 199 | #endif |
| 200 | 200 | } |
| 201 | 201 | |
| @@ -286,8 +286,9 @@ static void cleanup_sections(TCCState *s1) · 84 unmodified lines | ||
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /* ------------------------------------------------------------- */ |
| 289 | −/* 0 = .text rwx other rw */ | |
| 290 | −/* 1 = .text rx .rdata r .data/.bss rw */ | |
| 289 | +/* 0 = .text rwx other rw (memory >= 2 pages a 4096 bytes) */ | |
| 290 | +/* 1 = .text rx other rw (memory >= 3 pages) */ | |
| 291 | +/* 2 = .text rx .rdata ro .data/.bss rw (memory >= 4 pages) */ | |
| 291 | 292 | |
| 292 | 293 | /* Some targets implement secutiry options that do not allow write in |
| 293 | 294 | executable code. These targets need CONFIG_RUNMEM_RO=1. |
| @@ -370,7 +371,7 @@ redo: · 76 unmodified lines | ||
| 370 | 371 | align = 64; |
| 371 | 372 | #endif |
| 372 | 373 | /* start new page for different permissions */ |
| 373 | − if (CONFIG_RUNMEM_RO || k == 0) | |
| 374 | + if (k <= CONFIG_RUNMEM_RO) | |
| 374 | 375 | align = PAGESIZE; |
| 375 | 376 | } |
| 376 | 377 | s->sh_addralign = align; |
| @@ -387,7 +388,7 @@ redo: · 10 unmodified lines | ||
| 387 | 388 | continue; |
| 388 | 389 | #endif |
| 389 | 390 | f = k; |
| 390 | − if (CONFIG_RUNMEM_RO == 0) { | |
| 391 | + if (f >= CONFIG_RUNMEM_RO) { | |
| 391 | 392 | if (f != 0) |
| 392 | 393 | continue; |
| 393 | 394 | f = 3; /* change only SHF_EXECINSTR to rwx */ |
| @@ -342,7 +342,7 @@ cache: tcc_g · 341 unmodified lines | ||
| 342 | 342 | clean: |
| 343 | 343 | rm -f *~ *.o *.a *.bin *.i *.ref *.out *.out? *.out?b *.cc *.gcc |
| 344 | 344 | rm -f *-cc *-gcc *-tcc *.exe hello libtcc_test vla_test tcctest[1234] |
| 345 | − rm -f asm-c-connect$(EXESUF) asm-c-connect-sep$(EXESUF) | |
| 345 | + rm -f asm-c-connect asm-c-connect-sep | |
| 346 | 346 | rm -f ex? tcc_g weaktest.*.txt *.def *.pdb *.obj libtcc_test_mt |
| 347 | 347 | @$(MAKE) -C tests2 $@ |
| 348 | 348 | @$(MAKE) -C pp $@ |
| @@ -3760,12 +3760,14 @@ void asm_dot_test(void) · 3759 unmodified lines | ||
| 3760 | 3760 | |
| 3761 | 3761 | void asm_pcrel_test(void) |
| 3762 | 3762 | { |
| 3763 | +#if defined(__i386__) | |
| 3763 | 3764 | unsigned o1, o2; |
| 3764 | 3765 | /* subtract text-section label from forward or other-section label */ |
| 3765 | 3766 | asm("1: mov $2f-1b,%%eax; mov %%eax,%0" : "=m"(o1)); |
| 3766 | 3767 | /* verify ... */ |
| 3767 | 3768 | asm("2: mov $2b,%%eax; sub $1b,%%eax; mov %%eax,%0" : "=m"(o2)); |
| 3768 | 3769 | printf("%s : %x\n", __FUNCTION__, o1 - o2); /* should be zero */ |
| 3770 | +#endif | |
| 3769 | 3771 | } |
| 3770 | 3772 | |
| 3771 | 3773 | void asm_test(void) |
| @@ -55,10 +55,6 @@ endif · 54 unmodified lines | ||
| 55 | 55 | |
| 56 | 56 | # Some tests might need arguments |
| 57 | 57 | ARGS = |
| 58 | −ifneq (-$(CONFIG_WIN32)-,-yes-) | |
| 59 | −22_floating_point.test: FLAGS += -lm | |
| 60 | −24_math_library.test: FLAGS += -lm | |
| 61 | −endif | |
| 62 | 58 | 31_args.test : ARGS = arg1 arg2 arg3 arg4 arg5 |
| 63 | 59 | 46_grep.test : ARGS = '[^* ]*[:a:d: ]+\:\*-/: $$' $(SRC)/46_grep.c |
| 64 | 60 | |
| @@ -69,6 +65,10 @@ NORUN = · 4 unmodified lines | ||
| 69 | 65 | # Some tests might need different flags |
| 70 | 66 | FLAGS = |
| 71 | 67 | 76_dollars_in_identifiers.test : FLAGS += -fdollars-in-identifiers |
| 68 | +ifneq (-$(CONFIG_WIN32)-,-yes-) | |
| 69 | +22_floating_point.test: FLAGS += -lm | |
| 70 | +24_math_library.test: FLAGS += -lm | |
| 71 | +endif | |
| 72 | 72 | |
| 73 | 73 | # These tests run several snippets from the same file one by one |
| 74 | 74 | 60_errors_and_warnings.test : FLAGS += -dt |