History

some smaller fixes

- libtcc.c/tccpp.c: fix -U option for multiple input files - libtcc: remove decl of tcc_add_crt() for PE - tcc.h: define __i386__ and __x86_64__ for msvc - tcc.h: undef __attribute__ for __TINYC__ on gnu/linux platforms - tccelf.c: disable prepare_dynamic_rel unless x86/x64 - tccpe.c: construct rather than predefine PE section flags - tccpp.c: (alt.) fix access of dead stack variable after error/longjmp - x86_64-gen.c: fix func_alloca chain for nocode_wanted - tccpp.c/tccgen.c: improve file:line info for inline functions - winapi/winnt.h: correct position for DECLSPEC_ALIGN attribute - win32/lib/crt: simplify top exception handler (needed for signal) - arm64-gen.c: remove dprintf left from VT_CMP commit - tccgen.c: limit binary scan with gcase to > 8 (= smaller code) - tccgen.c: call save_regs(4) in gen_opl for cmp-ops (see test in tcctest.c)

grischka committed 8 years ago

Commit ce1ef5b1 parent 4bb5bc414 files · +111 −231Browse files

Unified · Split

14 files
  1. arm64-gen.c +0 −11
  2. libtcc.c +6 −2
  3. tcc.h +16 −3
  4. tccelf.c +5 −9
  5. tccgen.c +7 −5
  6. tccpe.c +33 −21
  7. tccpp.c +19 −22
  8. tests/tcctest.c +10 −0
  9. win32/include/_mingw.h +0 −6
  10. win32/include/winapi/winnt.h +5 −5
  11. win32/lib/chkstk.S +0 −122
  12. win32/lib/crt1.c +1 −7
  13. win32/lib/wincrt1.c +6 −11
  14. x86_64-gen.c +3 −7
arm64-gen.c+0−11
@@ -91,9 +91,6 @@ static uint32_t fltr(int r) · 90 unmodified lines
9191 return r - TREG_F(0);
9292 }
9393
94−#define dprintf(x) ((void)(tcc_state->verbose == 2 && printf x))
95−//#define dprintf(x)
96−
9794 // Add an instruction to text section:
9895 ST_FUNC void o(unsigned int c)
9996 {
@@ -103,7 +100,6 @@ ST_FUNC void o(unsigned int c) · 3 unmodified lines
103100 if (ind1 > cur_text_section->data_allocated)
104101 section_realloc(cur_text_section, ind1);
105102 write32le(cur_text_section->data + ind, c);
106− dprintf(("o %04x : %08x\n", ind, c)); //gr
107103 ind = ind1;
108104 }
109105
@@ -236,7 +232,6 @@ ST_FUNC void gsym_addr(int t_, int a_) · 126 unmodified lines
236232 tcc_error("branch out of range");
237233 write32le(ptr, (a - t == 4 ? 0xd503201f : // nop
238234 0x14000000 | ((a - t) >> 2 & 0x3ffffff))); // b
239− dprintf((". gsym TARG=%04x ADDR=%04x\n", t, a)); //gr
240235 t = next;
241236 }
242237 }
@@ -1296,7 +1291,6 @@ ST_FUNC void gen_fill_nops(int bytes) · 1053 unmodified lines
12961291 ST_FUNC int gjmp(int t)
12971292 {
12981293 int r = ind;
1299− dprintf((". gjmp T=%04x\n", t)); //gr
13001294 if (nocode_wanted)
13011295 return t;
13021296 o(t);
@@ -1308,7 +1302,6 @@ ST_FUNC void gjmp_addr(int a) · 5 unmodified lines
13081302 {
13091303 assert(a - ind + 0x8000000 < 0x10000000);
13101304 o(0x14000000 | ((a - ind) >> 2 & 0x3ffffff));
1311− dprintf((". gjmp_addr T=%04x\n", a)); //gr
13121305 }
13131306
13141307 ST_FUNC int gjmp_append(int n, int t)
@@ -1330,7 +1323,6 @@ void arm64_vset_VT_CMP(int op) · 15 unmodified lines
13301323 if (op >= TOK_ULT && op <= TOK_GT) {
13311324 vtop->cmp_r = vtop->r;
13321325 vset_VT_CMP(0x80);
1333− dprintf((". set VT_CMP OP(%s) R=%x\n", get_tok_str(op, 0), vtop->cmp_r));
13341326 }
13351327 }
13361328
@@ -1339,7 +1331,6 @@ static void arm64_gen_opil(int op, uint32_t l); · 2 unmodified lines
13391331 static void arm64_load_cmp(int r, SValue *sv)
13401332 {
13411333 sv->r = sv->cmp_r;
1342− dprintf((". load VT_CMP OP(%x), R=%x/%x\n", (int)sv->c.i, sv->r, r));
13431334 if (sv->c.i & 1) {
13441335 vpushi(1);
13451336 arm64_gen_opil('^', 0);
@@ -1348,7 +1339,6 @@ static void arm64_load_cmp(int r, SValue *sv) · 2 unmodified lines
13481339 load(r, sv);
13491340 sv->r = r;
13501341 }
1351− dprintf((". load VT_CMP done\n")); //gr
13521342 }
13531343
13541344 ST_FUNC int gjmp_cond(int op, int t)
@@ -1357,7 +1347,6 @@ ST_FUNC int gjmp_cond(int op, int t) · 2 unmodified lines
13571347
13581348 int inv = op & 1;
13591349 vtop->r = vtop->cmp_r;
1360− dprintf((". gjmp_cond OP(%x) R=%x T=%04x\n", op, vtop->r, t)); //gr
13611350
13621351 if (bt == VT_LDOUBLE) {
13631352 uint32_t a, b, f = fltr(gv(RC_FLOAT));
libtcc.c+6−2
@@ -700,9 +700,11 @@ LIBTCCAPI void tcc_undefine_symbol(TCCState *s1, const char *sym) · 699 unmodified lines
700700 Sym *s;
701701 ts = tok_alloc(sym, strlen(sym));
702702 s = define_find(ts->tok);
703− /* undefine symbol by putting an invalid name */
704− if (s)
703+ if (s) {
705704 define_undef(s);
705+ tok_str_free_str(s->d);
706+ s->d = NULL;
707+ }
706708 }
707709
708710 /* cleanup all static data used during compilation */
@@ -1118,6 +1120,7 @@ ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags) · 409 unmodified lines
11181120 s->library_paths, s->nb_library_paths);
11191121 }
11201122
1123+#ifndef TCC_TARGET_PE
11211124 ST_FUNC int tcc_add_crt(TCCState *s, const char *filename)
11221125 {
11231126 if (-1 == tcc_add_library_internal(s, "%s/%s",
@@ -1125,6 +1128,7 @@ ST_FUNC int tcc_add_crt(TCCState *s, const char *filename) · 1 unmodified line
11251128 tcc_error_noabort("file '%s' not found", filename);
11261129 return 0;
11271130 }
1131+#endif
11281132
11291133 /* the library name is the same as the argument of the '-l' option */
11301134 LIBTCCAPI int tcc_add_library(TCCState *s, const char *libraryname)
tcc.h+16−3
@@ -73,6 +73,12 @@ extern long double strtold (const char *__nptr, char **__endptr); · 72 unmodified lines
7373 # pragma warning (disable : 4018) // signed/unsigned mismatch
7474 # pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
7575 # define ssize_t intptr_t
76+# ifdef _X86_
77+# define __i386__ 1
78+# endif
79+# ifdef _AMD64_
80+# define __x86_64__ 1
81+# endif
7682 # endif
7783 # undef CONFIG_TCC_STATIC
7884 #endif
@@ -97,6 +103,11 @@ extern long double strtold (const char *__nptr, char **__endptr); · 18 unmodified lines
97103 # define ALIGNED(x) __attribute__((aligned(x)))
98104 #endif
99105
106+/* gnu headers use to #define __attribute__ to empty for non-gcc compilers */
107+#ifdef __TINYC__
108+# undef __attribute__
109+#endif
110+
100111 #ifdef _WIN32
101112 # define IS_DIRSEP(c) (c == '/' || c == '\\')
102113 # define IS_ABSPATH(p) (IS_DIRSEP(p[0]) || (p[0] && p[1] == ':' && IS_DIRSEP(p[2])))
@@ -133,7 +144,7 @@ extern long double strtold (const char *__nptr, char **__endptr); · 30 unmodified lines
133144 #if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_ARM) && \
134145 !defined(TCC_TARGET_ARM64) && !defined(TCC_TARGET_C67) && \
135146 !defined(TCC_TARGET_X86_64)
136−# if defined __x86_64__ || defined _AMD64_
147+# if defined __x86_64__
137148 # define TCC_TARGET_X86_64
138149 # elif defined __arm__
139150 # define TCC_TARGET_ARM
@@ -151,9 +162,9 @@ extern long double strtold (const char *__nptr, char **__endptr); · 11 unmodified lines
151162
152163 /* only native compiler supports -run */
153164 #if defined _WIN32 == defined TCC_TARGET_PE
154−# if (defined __i386__ || defined _X86_) && defined TCC_TARGET_I386
165+# if defined __i386__ && defined TCC_TARGET_I386
155166 # define TCC_IS_NATIVE
156−# elif (defined __x86_64__ || defined _AMD64_) && defined TCC_TARGET_X86_64
167+# elif defined __x86_64__ && defined TCC_TARGET_X86_64
157168 # define TCC_IS_NATIVE
158169 # elif defined __arm__ && defined TCC_TARGET_ARM
159170 # define TCC_IS_NATIVE
@@ -1179,7 +1190,9 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 1019 unmodified lines
11791190 #define AFF_BINTYPE_C67 4
11801191
11811192
1193+#ifndef TCC_TARGET_PE
11821194 ST_FUNC int tcc_add_crt(TCCState *s, const char *filename);
1195+#endif
11831196 ST_FUNC int tcc_add_dll(TCCState *s, const char *filename, int flags);
11841197 ST_FUNC void tcc_add_pragma_libs(TCCState *s1);
11851198 PUB_FUNC int tcc_add_library_err(TCCState *s, const char *f);
tccelf.c+5−9
@@ -171,7 +171,7 @@ ST_FUNC void tccelf_end_file(TCCState *s1) · 170 unmodified lines
171171 && ELFW(ST_BIND)(sym->st_info) == STB_LOCAL)
172172 sym->st_info = ELFW(ST_INFO)(STB_GLOBAL, ELFW(ST_TYPE)(sym->st_info));
173173 tr[i] = set_elf_sym(s, sym->st_value, sym->st_size, sym->st_info,
174− sym->st_other, sym->st_shndx, s->link->data + sym->st_name);
174+ sym->st_other, sym->st_shndx, (char*)s->link->data + sym->st_name);
175175 }
176176 /* now update relocations */
177177 for (i = 1; i < s1->nb_sections; i++) {
@@ -865,17 +865,13 @@ static void relocate_rel(TCCState *s1, Section *sr) · 687 unmodified lines
865865 their space */
866866 static int prepare_dynamic_rel(TCCState *s1, Section *sr)
867867 {
868+ int count = 0;
869+#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)
868870 ElfW_Rel *rel;
869− int type, count;
870−
871− count = 0;
872871 for_each_elem(sr, 0, rel, ElfW_Rel) {
873−#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)
874872 int sym_index = ELFW(R_SYM)(rel->r_info);
875−#endif
876− type = ELFW(R_TYPE)(rel->r_info);
873+ int type = ELFW(R_TYPE)(rel->r_info);
877874 switch(type) {
878−#if defined(TCC_TARGET_I386) || defined(TCC_TARGET_X86_64)
879875 #if defined(TCC_TARGET_I386)
880876 case R_386_32:
881877 if (!get_sym_attr(s1, sym_index, 0)->dyn_index
@@ -899,7 +895,6 @@ static int prepare_dynamic_rel(TCCState *s1, Section *sr) · 17 unmodified lines
899895 if (get_sym_attr(s1, sym_index, 0)->dyn_index)
900896 count++;
901897 break;
902−#endif
903898 default:
904899 break;
905900 }
@@ -909,6 +904,7 @@ static int prepare_dynamic_rel(TCCState *s1, Section *sr) · 3 unmodified lines
909904 sr->sh_flags |= SHF_ALLOC;
910905 sr->sh_size = count * sizeof(ElfW_Rel);
911906 }
907+#endif
912908 return count;
913909 }
914910
tccgen.c+7−5
@@ -1990,6 +1990,7 @@ static void gen_opl(int op) · 1989 unmodified lines
19901990 vtop[-1] = vtop[-2];
19911991 vtop[-2] = tmp;
19921992 /* stack: L1 L2 H1 H2 */
1993+ save_regs(4);
19931994 /* compare high */
19941995 op1 = op;
19951996 /* when values are equal, we need to compare low words. since
@@ -2205,7 +2206,7 @@ static void gen_opif(int op) · 209 unmodified lines
22052206 {
22062207 int c1, c2;
22072208 SValue *v1, *v2;
2208−#if defined _MSC_VER && defined _AMD64_
2209+#if defined _MSC_VER && defined __x86_64__
22092210 /* avoid bad optimization with f1 -= f2 for f1:-0.0, f2:0.0 */
22102211 volatile
22112212 #endif
@@ -4497,6 +4498,7 @@ static int post_type(CType *type, AttributeDef *ad, int storage, int td) · 2285 unmodified lines
44974498 if (n < TOK_UIDENT)
44984499 expect("identifier");
44994500 pt.t = VT_VOID; /* invalid type */
4501+ pt.ref = NULL;
45004502 next();
45014503 }
45024504 convert_parameter_type(&pt);
@@ -6113,7 +6115,7 @@ static void gcase(struct case_t **base, int len, int *bsym) · 1610 unmodified lines
61136115 struct case_t *p;
61146116 int e;
61156117 int ll = (vtop->type.t & VT_BTYPE) == VT_LLONG;
6116− while (len > 4) {
6118+ while (len > 8) {
61176119 /* binary search */
61186120 p = base[len/2];
61196121 vdup();
@@ -7538,10 +7540,10 @@ static void gen_function(Sym *sym) · 1418 unmodified lines
75387540 static void gen_inline_functions(TCCState *s)
75397541 {
75407542 Sym *sym;
7541− int inline_generated, i, ln;
7543+ int inline_generated, i;
75427544 struct InlineFunc *fn;
75437545
7544− ln = file->line_num;
7546+ tcc_open_bf(s, ":inline:", 0);
75457547 /* iterate while inline function are referenced */
75467548 do {
75477549 inline_generated = 0;
@@ -7564,7 +7566,7 @@ static void gen_inline_functions(TCCState *s) · 16 unmodified lines
75647566 }
75657567 }
75667568 } while (inline_generated);
7567− file->line_num = ln;
7569+ tcc_close();
75687570 }
75697571
75707572 ST_FUNC void free_inline_functions(TCCState *s)
tccpe.c+33−21
@@ -231,6 +231,17 @@ typedef struct _IMAGE_BASE_RELOCATION { · 230 unmodified lines
231231 #define IMAGE_REL_BASED_REL32 7
232232 #define IMAGE_REL_BASED_DIR64 10
233233
234+#define IMAGE_SCN_CNT_CODE 0x00000020
235+#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040
236+#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080
237+#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
238+#define IMAGE_SCN_MEM_SHARED 0x10000000
239+#define IMAGE_SCN_MEM_EXECUTE 0x20000000
240+#define IMAGE_SCN_MEM_READ 0x40000000
241+#define IMAGE_SCN_MEM_WRITE 0x80000000
242+#define IMAGE_SCN_TYPE_NOLOAD 0x00000002
243+#define IMAGE_SCN_LNK_REMOVE 0x00000800
244+
234245 #pragma pack(pop)
235246
236247 /* ----------------------------------------------------------- */
@@ -279,17 +290,6 @@ struct pe_rsrc_reloc { · 42 unmodified lines
279290 /* ------------------------------------------------------------- */
280291 /* internal temporary structures */
281292
282−/*
283−#define IMAGE_SCN_CNT_CODE 0x00000020
284−#define IMAGE_SCN_CNT_INITIALIZED_DATA 0x00000040
285−#define IMAGE_SCN_CNT_UNINITIALIZED_DATA 0x00000080
286−#define IMAGE_SCN_MEM_DISCARDABLE 0x02000000
287−#define IMAGE_SCN_MEM_SHARED 0x10000000
288−#define IMAGE_SCN_MEM_EXECUTE 0x20000000
289−#define IMAGE_SCN_MEM_READ 0x40000000
290−#define IMAGE_SCN_MEM_WRITE 0x80000000
291−*/
292−
293293 enum {
294294 sec_text = 0,
295295 sec_data ,
@@ -303,6 +303,7 @@ enum { · 7 unmodified lines
303303 sec_last
304304 };
305305
306+#if 0
306307 static const DWORD pe_sec_flags[] = {
307308 0x60000020, /* ".text" , */
308309 0xC0000040, /* ".data" , */
@@ -314,13 +315,14 @@ static const DWORD pe_sec_flags[] = { · 5 unmodified lines
314315 0x42000802, /* ".stab" , */
315316 0x42000040, /* ".reloc" , */
316317 };
318+#endif
317319
318320 struct section_info {
319321 int cls, ord;
320322 char name[32];
321323 DWORD sh_addr;
322324 DWORD sh_size;
323− DWORD sh_flags;
325+ DWORD pe_flags;
324326 unsigned char *data;
325327 DWORD data_size;
326328 IMAGE_SECTION_HEADER ish;
@@ -656,9 +658,6 @@ static int pe_write(struct pe_info *pe) · 329 unmodified lines
656658 case sec_pdata:
657659 pe_set_datadir(&pe_header, IMAGE_DIRECTORY_ENTRY_EXCEPTION, addr, size);
658660 break;
659−
660− case sec_stab:
661− break;
662661 }
663662
664663 if (pe->thunk == pe->s1->sections[si->ord]) {
@@ -676,7 +675,7 @@ static int pe_write(struct pe_info *pe) · 11 unmodified lines
676675
677676 strncpy((char*)psh->Name, sh_name, sizeof psh->Name);
678677
679− psh->Characteristics = pe_sec_flags[si->cls];
678+ psh->Characteristics = si->pe_flags;
680679 psh->VirtualAddress = addr;
681680 psh->Misc.VirtualSize = size;
682681 pe_header.opthdr.SizeOfImage =
@@ -1064,15 +1063,15 @@ static int pe_section_class(Section *s) · 381 unmodified lines
10641063 return sec_idata;
10651064 if (0 == strcmp(name, ".pdata"))
10661065 return sec_pdata;
1067− return sec_other;
10681066 } else if (type == SHT_NOBITS) {
10691067 if (flags & SHF_WRITE)
10701068 return sec_bss;
10711069 }
1070+ return sec_other;
10721071 } else {
10731072 if (0 == strcmp(name, ".reloc"))
10741073 return sec_reloc;
1075− if (0 == strncmp(name, ".stab", 5)) /* .stab and .stabstr */
1074+ if (0 == memcmp(name, ".stab", 5))
10761075 return sec_stab;
10771076 }
10781077 return -1;
@@ -1129,7 +1128,21 @@ static int pe_assign_addresses (struct pe_info *pe) · 50 unmodified lines
11291128 si->cls = c;
11301129 si->ord = k;
11311130 si->sh_addr = s->sh_addr = addr = pe_virtual_align(pe, addr);
1132− si->sh_flags = s->sh_flags;
1131+
1132+ si->pe_flags = IMAGE_SCN_MEM_READ;
1133+ if (s->sh_flags & SHF_EXECINSTR)
1134+ si->pe_flags |= IMAGE_SCN_MEM_EXECUTE | IMAGE_SCN_CNT_CODE;
1135+ else if (s->sh_type == SHT_NOBITS)
1136+ si->pe_flags |= IMAGE_SCN_CNT_UNINITIALIZED_DATA;
1137+ else
1138+ si->pe_flags |= IMAGE_SCN_CNT_INITIALIZED_DATA;
1139+ if (s->sh_flags & SHF_WRITE)
1140+ si->pe_flags |= IMAGE_SCN_MEM_WRITE;
1141+ if (0 == (s->sh_flags & SHF_ALLOC)) {
1142+ si->pe_flags |= IMAGE_SCN_MEM_DISCARDABLE;
1143+ if (c == sec_stab)
1144+ si->pe_flags |= 0x802; //IMAGE_SCN_TYPE_NOLOAD|IMAGE_SCN_LNK_REMOVE
1145+ }
11331146
11341147 if (c == sec_data && NULL == pe->thunk)
11351148 pe->thunk = s;
@@ -1153,9 +1166,8 @@ static int pe_assign_addresses (struct pe_info *pe) · 17 unmodified lines
11531166 si->sh_size = s->data_offset;
11541167 ++pe->sec_count;
11551168 }
1156− // printf("%08x %05x %s\n", si->sh_addr, si->sh_size, si->name);
1169+ //printf("%08x %05x %s %08x\n", si->sh_addr, si->sh_size, si->name, si->pe_flags);
11571170 }
1158−
11591171 #if 0
11601172 for (i = 1; i < pe->s1->nb_sections; ++i) {
11611173 Section *s = pe->s1->sections[i];
tccpp.c+19−22
@@ -1119,9 +1119,9 @@ ST_FUNC void end_macro(void) · 1118 unmodified lines
11191119 macro_stack = str->prev;
11201120 macro_ptr = str->prev_ptr;
11211121 file->line_num = str->save_line_num;
1122− if (str->alloc == 2) {
1123− str->alloc = 3; /* just mark as finished */
1124− } else {
1122+ if (str->alloc != 0) {
1123+ if (str->alloc == 2)
1124+ str->str = NULL; /* don't free */
11251125 tok_str_free(str);
11261126 }
11271127 }
@@ -1345,7 +1345,7 @@ ST_FUNC void free_defines(Sym *b) · 217 unmodified lines
13451345 int v = b->v;
13461346 if (v >= TOK_IDENT && v < tok_ident) {
13471347 Sym **d = &table_ident[v - TOK_IDENT]->sym_define;
1348− if (!*d)
1348+ if (!*d && b->d)
13491349 *d = b;
13501350 }
13511351 b = b->prev;
@@ -1799,9 +1799,9 @@ ST_FUNC void preprocess(int is_bof) · 447 unmodified lines
17991799
18001800 if (s1->include_stack_ptr >= s1->include_stack + INCLUDE_STACK_SIZE)
18011801 tcc_error("#include recursion too deep");
1802− /* store current file in stack, but increment stack later below */
1803− *s1->include_stack_ptr = file;
1804− i = tok == TOK_INCLUDE_NEXT ? file->include_next_index : 0;
1802+ /* push current file on stack */
1803+ *s1->include_stack_ptr++ = file;
1804+ i = tok == TOK_INCLUDE_NEXT ? file->include_next_index: 0;
18051805 n = 2 + s1->nb_include_paths + s1->nb_sysinclude_paths;
18061806 for (; i < n; ++i) {
18071807 char buf1[sizeof file->filename];
@@ -1849,10 +1849,10 @@ ST_FUNC void preprocess(int is_bof) · 41 unmodified lines
18491849 printf("%s: including %s\n", file->prev->filename, file->filename);
18501850 #endif
18511851 /* update target deps */
1852− dynarray_add(&s1->target_deps, &s1->nb_target_deps,
1852+ if (s1->gen_deps) {
1853+ dynarray_add(&s1->target_deps, &s1->nb_target_deps,
18531854 tcc_strdup(buf1));
1854− /* push current file in stack */
1855− ++s1->include_stack_ptr;
1855+ }
18561856 /* add include file debug info */
18571857 if (s1->do_debug)
18581858 put_stabs(file->filename, N_BINCL, 0, 0, 0);
@@ -1862,6 +1862,7 @@ ST_FUNC void preprocess(int is_bof) · 3 unmodified lines
18621862 }
18631863 tcc_error("include file '%s' not found", buf);
18641864 include_done:
1865+ --s1->include_stack_ptr;
18651866 break;
18661867 case TOK_IFNDEF:
18671868 c = 1;
@@ -3486,14 +3487,14 @@ static void macro_subst( · 1618 unmodified lines
34863487 }
34873488
34883489 {
3489− TokenString str;
3490− str.str = (int*)macro_str;
3491− begin_macro(&str, 2);
3490+ TokenString *str = tok_str_alloc();
3491+ str->str = (int*)macro_str;
3492+ begin_macro(str, 2);
34923493
34933494 tok = t;
34943495 macro_subst_tok(tok_str, nested_list, s);
34953496
3496− if (str.alloc == 3) {
3497+ if (macro_stack != str) {
34973498 /* already finished by reading function macro arguments */
34983499 break;
34993500 }
@@ -3554,7 +3555,7 @@ ST_FUNC void next(void) · 54 unmodified lines
35543555 tokstr_buf.len = 0;
35553556 macro_subst_tok(&tokstr_buf, &nested_list, s);
35563557 tok_str_add(&tokstr_buf, 0);
3557− begin_macro(&tokstr_buf, 2);
3558+ begin_macro(&tokstr_buf, 0);
35583559 goto redo;
35593560 }
35603561 }
@@ -3593,6 +3594,7 @@ ST_FUNC void preprocess_start(TCCState *s1, int is_asm) · 32 unmodified lines
35933594 pp_debug_tok = pp_debug_symv = 0;
35943595 pp_once++;
35953596 pvtop = vtop = vstack - 1;
3597+ memset(vtop, 0, sizeof *vtop);
35963598 s1->pack_stack[0] = 0;
35973599 s1->pack_stack_ptr = s1->pack_stack;
35983600
@@ -3628,13 +3630,8 @@ ST_FUNC void preprocess_start(TCCState *s1, int is_asm) · 29 unmodified lines
36283630 /* cleanup from error/setjmp */
36293631 ST_FUNC void preprocess_end(TCCState *s1)
36303632 {
3631− /* Normally macro_stack is NULL here, except if an
3632− error was thrown; then it can point to allocated storage
3633− or to some stack variables, but those are unwound via
3634− setjmp already, so can't be accessed. Only two choices:
3635− either we leak memory or we access invalid memory. The
3636− former is the better choice. */
3637− macro_stack = NULL;
3633+ while (macro_stack)
3634+ end_macro();
36383635 macro_ptr = NULL;
36393636 }
36403637
tests/tcctest.c+10−0
@@ -2466,6 +2466,11 @@ long long llfunc2(long long x, long long y, int z) · 2465 unmodified lines
24662466 return x * y * z;
24672467 }
24682468
2469+void check_opl_save_regs(char *a, long long b, int c)
2470+{
2471+ *a = b < 0 && !c;
2472+}
2473+
24692474 void longlong_test(void)
24702475 {
24712476 long long a, b, c;
@@ -2538,6 +2543,11 @@ void longlong_test(void) · 66 unmodified lines
25382543 unsigned long long u = 0x8000000000000001ULL;
25392544 u = (unsigned)(u + 1);
25402545 printf("long long u=" ULONG_LONG_FORMAT "\n", u);
2546+
2547+ /* was a problem with missing save_regs in gen_opl on 32-bit platforms */
2548+ char cc = 78;
2549+ check_opl_save_regs(&cc, -1, 0);
2550+ printf("check_opl_save_regs: %d\n", cc);
25412551 }
25422552
25432553 void manyarg_test(void)
win32/include/_mingw.h+0−6
@@ -76,18 +76,12 @@ · 75 unmodified lines
7676 #define _M_AMD64 100 /* Visual Studio */
7777 #define USE_MINGW_SETJMP_TWO_ARGS
7878 #define mingw_getsp tinyc_getbp
79−#define __TRY__
8079 #else
8180 #define __stdcall __attribute__((__stdcall__))
8281 #define _X86_ 1
8382 #define _M_IX86 300 /* Visual Studio */
8483 #define WIN32 1
8584 #define _USE_32BIT_TIME_T
86−#ifdef __arm__
87−#define __TRY__
88−#else
89−#define __TRY__ void __try__(void**), *_sehrec[6]; __try__(_sehrec);
90−#endif
9185 #endif
9286
9387 /* in stddef.h */
win32/include/winapi/winnt.h+5−5
@@ -1310,7 +1310,7 @@ typedef DWORD LCID; · 1309 unmodified lines
13101310 #define INITIAL_MXCSR 0x1f80
13111311 #define INITIAL_FPCSR 0x027f
13121312
1313− typedef DECLSPEC_ALIGN(16) struct _M128A {
1313+ typedef struct DECLSPEC_ALIGN(16) _M128A {
13141314 ULONGLONG Low;
13151315 LONGLONG High;
13161316 } M128A,*PM128A;
@@ -1336,7 +1336,7 @@ typedef DWORD LCID; · 19 unmodified lines
13361336
13371337 #define LEGACY_SAVE_AREA_LENGTH sizeof(XMM_SAVE_AREA32)
13381338
1339− typedef DECLSPEC_ALIGN(16) struct _CONTEXT {
1339+ typedef struct DECLSPEC_ALIGN(16) _CONTEXT {
13401340 DWORD64 P1Home;
13411341 DWORD64 P2Home;
13421342 DWORD64 P3Home;
@@ -3150,7 +3150,7 @@ typedef DWORD LCID; · 1807 unmodified lines
31503150 DWORD Type;
31513151 } MEMORY_BASIC_INFORMATION32,*PMEMORY_BASIC_INFORMATION32;
31523152
3153− typedef DECLSPEC_ALIGN(16) struct _MEMORY_BASIC_INFORMATION64 {
3153+ typedef struct DECLSPEC_ALIGN(16) _MEMORY_BASIC_INFORMATION64 {
31543154 ULONGLONG BaseAddress;
31553155 ULONGLONG AllocationBase;
31563156 DWORD AllocationProtect;
@@ -4949,7 +4949,7 @@ typedef DWORD LCID; · 1792 unmodified lines
49494949
49504950 #ifdef _WIN64
49514951 typedef struct _SLIST_ENTRY *PSLIST_ENTRY;
4952− typedef DECLSPEC_ALIGN(16) struct _SLIST_ENTRY {
4952+ typedef struct DECLSPEC_ALIGN(16) _SLIST_ENTRY {
49534953 PSLIST_ENTRY Next;
49544954 } SLIST_ENTRY;
49554955 #else
@@ -4961,7 +4961,7 @@ typedef DWORD LCID; · 5 unmodified lines
49614961
49624962 #if defined(_WIN64)
49634963
4964− typedef DECLSPEC_ALIGN(16) struct _SLIST_HEADER {
4964+ typedef struct DECLSPEC_ALIGN(16) _SLIST_HEADER {
49654965 ULONGLONG Alignment;
49664966 ULONGLONG Region;
49674967 } SLIST_HEADER;
win32/lib/chkstk.S+0−122
@@ -67,125 +67,3 @@ tinyc_getbp: · 66 unmodified lines
6767 /* ---------------------------------------------- */
6868
6969
70−/* ---------------------------------------------- */
71−#ifndef __x86_64__
72−/* ---------------------------------------------- */
73−
74−/*
75− int _except_handler3(
76− PEXCEPTION_RECORD exception_record,
77− PEXCEPTION_REGISTRATION registration,
78− PCONTEXT context,
79− PEXCEPTION_REGISTRATION dispatcher
80− );
81−
82− int __cdecl _XcptFilter(
83− unsigned long xcptnum,
84− PEXCEPTION_POINTERS pxcptinfoptrs
85− );
86−
87− struct _sehrec {
88− void *esp; // 0
89− void *exception_pointers; // 1
90− void *prev; // 2
91− void *handler; // 3
92− void *scopetable; // 4
93− int trylevel; // 5
94− void *ebp // 6
95− };
96−
97− // this is what the assembler code below means:
98− __try
99− {
100− // ...
101− }
102− __except (_XcptFilter(GetExceptionCode(), GetExceptionInformation()))
103− {
104− exit(GetExceptionCode());
105− }
106−*/
107−
108−.globl _exception_info
109−_exception_info:
110− mov 1*4-24(%ebp),%eax
111− ret
112−
113−.globl _exception_code
114−_exception_code:
115− call _exception_info
116− mov (%eax),%eax
117− mov (%eax),%eax
118− ret
119−
120−seh_filter:
121− call _exception_info
122− push %eax
123− call _exception_code
124− push %eax
125− call _XcptFilter
126− add $ 8,%esp
127− ret
128−
129−seh_except:
130− mov 0*4-24(%ebp),%esp
131− call _exception_code
132− push %eax
133− call _exit
134−
135−// msvcrt wants scopetables aligned and in read-only segment (using .text)
136−.align 4
137−seh_scopetable:
138− .long -1
139− .long seh_filter
140− .long seh_except
141−
142−seh_handler:
143− jmp _except_handler3
144−
145−.globl ___try__
146−___try__:
147−.globl __try__
148−__try__:
149− push %ebp
150− mov 8(%esp),%ebp
151−
152−// void *esp;
153− lea 12(%esp),%eax
154− mov %eax,0*4(%ebp)
155−
156−// void *exception_pointers;
157− xor %eax,%eax
158− mov %eax,1*4(%ebp)
159−
160−// void *prev;
161− mov %fs:0,%eax
162− mov %eax,2*4(%ebp)
163−
164−// void *handler;
165− mov $ seh_handler,%eax
166− mov %eax,3*4(%ebp)
167−
168−// void *scopetable;
169− mov $ seh_scopetable,%eax
170− mov %eax,4*4(%ebp)
171−
172−// int trylevel;
173− xor %eax,%eax
174− mov %eax,5*4(%ebp)
175−
176−// register new SEH
177− lea 2*4(%ebp),%eax
178− mov %eax,%fs:0
179−
180− pop %ebp
181− ret
182−
183−/* ---------------------------------------------- */
184−#else
185−/* ---------------------------------------------- */
186−
187−/* SEH on x86-64 not implemented */
188−
189−/* ---------------------------------------------- */
190−#endif
191−/* ---------------------------------------------- */
win32/lib/crt1.c+1−7
@@ -38,21 +38,15 @@ extern int _tmain(int argc, _TCHAR * argv[], _TCHAR * env[]); · 37 unmodified lines
3838 /* Allow command-line globbing with "int _dowildcard = 1;" in the user source */
3939 int _dowildcard;
4040
41−#ifdef __x86_64__
4241 static LONG WINAPI catch_sig(EXCEPTION_POINTERS *ex)
4342 {
4443 return _XcptFilter(ex->ExceptionRecord->ExceptionCode, ex);
4544 }
46−#endif
4745
4846 void _tstart(void)
4947 {
50− __TRY__
51−#ifdef __x86_64__
52− SetUnhandledExceptionFilter(catch_sig);
53−#endif
5448 _startupinfo start_info = {0};
55−
49+ SetUnhandledExceptionFilter(catch_sig);
5650 // Sets the current application type
5751 __set_app_type(_CONSOLE_APP);
5852
win32/lib/wincrt1.c+6−11
@@ -26,13 +26,6 @@ int APIENTRY wWinMain(HINSTANCE, HINSTANCE, LPWSTR, int); · 25 unmodified lines
2626 typedef struct { int newmode; } _startupinfo;
2727 int __cdecl __tgetmainargs(int *pargc, _TCHAR ***pargv, _TCHAR ***penv, int globb, _startupinfo*);
2828
29−#ifdef __x86_64__
30−static LONG WINAPI catch_sig(EXCEPTION_POINTERS *ex)
31−{
32− return _XcptFilter(ex->ExceptionRecord->ExceptionCode, ex);
33−}
34−#endif
35−
3629 static int go_winmain(TCHAR *arg1)
3730 {
3831 STARTUPINFO si;
@@ -58,13 +51,15 @@ static int go_winmain(TCHAR *arg1) · 19 unmodified lines
5851 return _tWinMain(GetModuleHandle(NULL), NULL, szCmd, fShow);
5952 }
6053
54+static LONG WINAPI catch_sig(EXCEPTION_POINTERS *ex)
55+{
56+ return _XcptFilter(ex->ExceptionRecord->ExceptionCode, ex);
57+}
58+
6159 int _twinstart(void)
6260 {
63− __TRY__
64−#ifdef __x86_64__
65− SetUnhandledExceptionFilter(catch_sig);
66−#endif
6761 _startupinfo start_info_con = {0};
62+ SetUnhandledExceptionFilter(catch_sig);
6863 __set_app_type(__GUI_APP);
6964 __tgetmainargs(&__argc, &__targv, &_tenviron, 0, &start_info_con);
7065 exit(go_winmain(__argc > 1 ? __targv[1] : NULL));
x86_64-gen.c+3−7
@@ -206,7 +206,7 @@ ST_FUNC void gsym_addr(int t, int a) · 205 unmodified lines
206206 while (t) {
207207 unsigned char *ptr = cur_text_section->data + t;
208208 uint32_t n = read32le(ptr); /* next value */
209− write32le(ptr, a - t - 4);
209+ write32le(ptr, a < 0 ? -a : a - t - 4);
210210 t = n;
211211 }
212212 }
@@ -909,7 +909,7 @@ void gfunc_call(int nb_args) · 696 unmodified lines
909909
910910 if ((vtop->r & VT_SYM) && vtop->sym->v == TOK_alloca) {
911911 /* need to add the "func_scratch" area after alloca */
912− o(0x0548), gen_le32(func_alloca), func_alloca = ind - 4;
912+ o(0x48); func_alloca = oad(0x05, func_alloca); /* sub $NN, %rax */
913913 }
914914
915915 /* other compilers don't clear the upper bits when returning char/short */
@@ -1037,11 +1037,7 @@ void gfunc_epilog(void) · 121 unmodified lines
10371037 }
10381038
10391039 /* add the "func_scratch" area after each alloca seen */
1040− while (func_alloca) {
1041− unsigned char *ptr = cur_text_section->data + func_alloca;
1042− func_alloca = read32le(ptr);
1043− write32le(ptr, func_scratch);
1044− }
1040+ gsym_addr(func_alloca, -func_scratch);
10451041
10461042 cur_text_section->data_offset = saved_ind;
10471043 pe_add_unwind_data(ind, saved_ind, v);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t