History

fixes & cleanups

- tccgen.c/tcc.h: allow function declaration after use: int f() { return g(); } int g() { return 1; } may be a warning but not an error see also 76cb1144ef91924c53c57ea71e6f67ce73ce1cc6 - tccgen.c: redundant code related to inline functions removed (functions used anywhere have sym->c set automatically) - tccgen.c: make 32bit llop non-equal test portable (probably not on C67) - dynarray_add: change prototype to possibly avoid aliasing problems or at least warnings - lib/alloca*.S: ".section .note.GNU-stack,"",%progbits" removed (has no effect) - tccpe: set SizeOfCode field (for correct upx decompression) - libtcc.c: fixed alternative -run invocation tcc "-run -lxxx ..." file.c (meant to load the library after file). Also supported now: tcc files ... options ... -run @ arguments ...

grischka committed 9 years ago

Commit a4a20361 parent 981720413 files · +61 −90Browse files

Unified · Split

13 files
  1. arm-gen.c +1 −1
  2. i386-gen.c +4 −4
  3. lib/alloca-arm.S +0 −1
  4. lib/alloca86.S +0 −4
  5. lib/alloca86_64-bt.S +0 −4
  6. lib/alloca86_64.S +0 −4
  7. libtcc.c +12 −11
  8. tcc.h +2 −4
  9. tccelf.c +7 −8
  10. tccgen.c +23 −41
  11. tccpe.c +8 −4
  12. tccpp.c +3 −3
  13. x86_64-gen.c +1 −1
arm-gen.c+1−1
@@ -341,7 +341,7 @@ void stuff_const_harder(uint32_t op, uint32_t v) { · 340 unmodified lines
341 }341 }
342}342}
343 343
344ST_FUNC uint32_t encbranch(int pos, int addr, int fail)344uint32_t encbranch(int pos, int addr, int fail)
345{345{
346 addr-=pos+8;346 addr-=pos+8;
347 addr/=4;347 addr/=4;
i386-gen.c+4−4
@@ -70,9 +70,6 @@ enum { · 69 unmodified lines
70/* maximum alignment (for aligned attribute support) */70/* maximum alignment (for aligned attribute support) */
71#define MAX_ALIGN 871#define MAX_ALIGN 8
72 72
73/* generate jmp to a label */
74#define gjmp2(instr,lbl) oad(instr,lbl)
75
76/******************************************************/73/******************************************************/
77#else /* ! TARGET_DEFS_ONLY */74#else /* ! TARGET_DEFS_ONLY */
78/******************************************************/75/******************************************************/
@@ -148,7 +145,7 @@ ST_FUNC void gsym(int t) · 69 unmodified lines
148}145}
149 146
150/* instruction + 4 bytes data. Return the address of the data */147/* instruction + 4 bytes data. Return the address of the data */
151ST_FUNC int oad(int c, int s)148static int oad(int c, int s)
152{149{
153 int t;150 int t;
154 if (nocode_wanted)151 if (nocode_wanted)
@@ -159,6 +156,9 @@ ST_FUNC int oad(int c, int s) · 4 unmodified lines
159 return t;156 return t;
160}157}
161 158
159/* generate jmp to a label */
160#define gjmp2(instr,lbl) oad(instr,lbl)
161
162/* output constant with relocation if 'r & VT_SYM' is true */162/* output constant with relocation if 'r & VT_SYM' is true */
163ST_FUNC void gen_addr32(int r, Sym *sym, long c)163ST_FUNC void gen_addr32(int r, Sym *sym, long c)
164{164{
lib/alloca-arm.S+0−1
@@ -8,4 +8,3 @@ alloca: · 7 unmodified lines
8 mov r0, sp8 mov r0, sp
9 mov pc, lr9 mov pc, lr
10 .size alloca, .-alloca10 .size alloca, .-alloca
11 .section .note.GNU-stack,"",%progbits
lib/alloca86.S+0−4
@@ -28,8 +28,4 @@ p3: · 27 unmodified lines
28 push %edx28 push %edx
29 ret29 ret
30 30
31/* mark stack as nonexecutable */
32#if defined __ELF__ && defined __linux__
33 .section .note.GNU-stack,"",@progbits
34#endif
35/* ---------------------------------------------- */31/* ---------------------------------------------- */
lib/alloca86_64-bt.S+0−4
@@ -53,8 +53,4 @@ p3: · 52 unmodified lines
53 ret53 ret
54#endif54#endif
55 55
56/* mark stack as nonexecutable */
57#if defined __ELF__ && defined __linux__
58 .section .note.GNU-stack,"",@progbits
59#endif
60/* ---------------------------------------------- */56/* ---------------------------------------------- */
lib/alloca86_64.S+0−4
@@ -35,8 +35,4 @@ p3: · 34 unmodified lines
35 push %rdx35 push %rdx
36 ret36 ret
37 37
38/* mark stack as nonexecutable */
39#if defined __ELF__ && defined __linux__
40 .section .note.GNU-stack,"",@progbits
41#endif
42/* ---------------------------------------------- */38/* ---------------------------------------------- */
libtcc.c+12−11
@@ -403,13 +403,13 @@ PUB_FUNC void tcc_memstats(int bench) · 402 unmodified lines
403/********************************************************/403/********************************************************/
404/* dynarrays */404/* dynarrays */
405 405
406ST_FUNC void dynarray_add(void ***ptab, int *nb_ptr, void *data)406ST_FUNC void dynarray_add(void *ptab, int *nb_ptr, void *data)
407{407{
408 int nb, nb_alloc;408 int nb, nb_alloc;
409 void **pp;409 void **pp;
410 410
411 nb = *nb_ptr;411 nb = *nb_ptr;
412 pp = *ptab;412 pp = *(void ***)ptab;
413 /* every power of two we double array size */413 /* every power of two we double array size */
414 if ((nb & (nb - 1)) == 0) {414 if ((nb & (nb - 1)) == 0) {
415 if (!nb)415 if (!nb)
@@ -417,7 +417,7 @@ ST_FUNC void dynarray_add(void ***ptab, int *nb_ptr, void *data) · 1 unmodified line
417 else417 else
418 nb_alloc = nb * 2;418 nb_alloc = nb * 2;
419 pp = tcc_realloc(pp, nb_alloc * sizeof(void *));419 pp = tcc_realloc(pp, nb_alloc * sizeof(void *));
420 *ptab = pp;420 *(void***)ptab = pp;
421 }421 }
422 pp[nb++] = data;422 pp[nb++] = data;
423 *nb_ptr = nb;423 *nb_ptr = nb;
@@ -1013,7 +1013,7 @@ ST_FUNC int tcc_add_file_internal(TCCState *s1, const char *filename, int flags) · 589 unmodified lines
1013 }1013 }
1014 1014
1015 /* update target deps */1015 /* update target deps */
1016 dynarray_add((void ***)&s1->target_deps, &s1->nb_target_deps,1016 dynarray_add(&s1->target_deps, &s1->nb_target_deps,
1017 tcc_strdup(filename));1017 tcc_strdup(filename));
1018 1018
1019 parse_flags = 0;1019 parse_flags = 0;
@@ -1586,7 +1586,7 @@ static void args_parser_add_file(TCCState *s, const char* filename, int filetype · 566 unmodified lines
1586 struct filespec *f = tcc_malloc(sizeof *f + strlen(filename));1586 struct filespec *f = tcc_malloc(sizeof *f + strlen(filename));
1587 f->type = filetype;1587 f->type = filetype;
1588 strcpy(f->name, filename);1588 strcpy(f->name, filename);
1589 dynarray_add((void ***)&s->files, &s->nb_files, f);1589 dynarray_add(&s->files, &s->nb_files, f);
1590}1590}
1591 1591
1592/* read list file */1592/* read list file */
@@ -1611,8 +1611,8 @@ PUB_FUNC int tcc_parse_args(TCCState *s, int argc, char **argv) · 18 unmodified lines
1611{1611{
1612 const TCCOption *popt;1612 const TCCOption *popt;
1613 const char *optarg, *r;1613 const char *optarg, *r;
1614 const char *run = NULL;
1614 int optind = 0;1615 int optind = 0;
1615 int run = 0;
1616 int x;1616 int x;
1617 int last_o = -1;1617 int last_o = -1;
1618 CString linker_arg; /* collect -Wl options */1618 CString linker_arg; /* collect -Wl options */
@@ -1631,8 +1631,10 @@ reparse: · 12 unmodified lines
1631 }1631 }
1632 1632
1633 if (r[0] != '-' || r[1] == '\0') {1633 if (r[0] != '-' || r[1] == '\0') {
1634 args_parser_add_file(s, r, s->filetype);1634 if (r[0] != '@') /* allow "tcc file(s) -run @ args ..." */
1635 args_parser_add_file(s, r, s->filetype);
1635 if (run) {1636 if (run) {
1637 tcc_set_options(s, run);
1636 optind--;1638 optind--;
1637 /* argv[0] will be this file */1639 /* argv[0] will be this file */
1638 break;1640 break;
@@ -1753,7 +1755,7 @@ reparse: · 114 unmodified lines
1753 tcc_add_sysinclude_path(s, buf);1755 tcc_add_sysinclude_path(s, buf);
1754 break;1756 break;
1755 case TCC_OPTION_include:1757 case TCC_OPTION_include:
1756 dynarray_add((void ***)&s->cmd_include_files,1758 dynarray_add(&s->cmd_include_files,
1757 &s->nb_cmd_include_files, tcc_strdup(optarg));1759 &s->nb_cmd_include_files, tcc_strdup(optarg));
1758 break;1760 break;
1759 case TCC_OPTION_nostdinc:1761 case TCC_OPTION_nostdinc:
@@ -1769,8 +1771,7 @@ reparse: · 9 unmodified lines
1769#ifndef TCC_IS_NATIVE1771#ifndef TCC_IS_NATIVE
1770 tcc_error("-run is not available in a cross compiler");1772 tcc_error("-run is not available in a cross compiler");
1771#endif1773#endif
1772 tcc_set_options(s, optarg);1774 run = optarg;
1773 run = 1;
1774 x = TCC_OUTPUT_MEMORY;1775 x = TCC_OUTPUT_MEMORY;
1775 goto set_output_type;1776 goto set_output_type;
1776 case TCC_OPTION_v:1777 case TCC_OPTION_v:
@@ -1903,7 +1904,7 @@ LIBTCCAPI int tcc_set_options(TCCState *s, const char *r) · 126 unmodified lines
1903 }1904 }
1904 cstr_ccat(&str, 0);1905 cstr_ccat(&str, 0);
1905 //printf("<%s>\n", str.data), fflush(stdout);1906 //printf("<%s>\n", str.data), fflush(stdout);
1906 dynarray_add((void ***)&argv, &argc, tcc_strdup(str.data));1907 dynarray_add(&argv, &argc, tcc_strdup(str.data));
1907 cstr_free(&str);1908 cstr_free(&str);
1908 }1909 }
1909 ret = tcc_parse_args(s, argc, argv);1910 ret = tcc_parse_args(s, argc, argv);
tcc.h+2−4
@@ -388,7 +388,7 @@ struct Attribute { · 387 unmodified lines
388 func_export : 1,388 func_export : 1,
389 func_import : 1,389 func_import : 1,
390 func_args : 5,390 func_args : 5,
391 func_proto : 1,391 func_body : 1,
392 mode : 4,392 mode : 4,
393 weak : 1,393 weak : 1,
394 visibility : 2,394 visibility : 2,
@@ -1096,7 +1096,7 @@ PUB_FUNC NORETURN void tcc_error(const char *fmt, ...); · 701 unmodified lines
1096PUB_FUNC void tcc_warning(const char *fmt, ...);1096PUB_FUNC void tcc_warning(const char *fmt, ...);
1097 1097
1098/* other utilities */1098/* other utilities */
1099ST_FUNC void dynarray_add(void ***ptab, int *nb_ptr, void *data);1099ST_FUNC void dynarray_add(void *ptab, int *nb_ptr, void *data);
1100ST_FUNC void dynarray_reset(void *pp, int *n);1100ST_FUNC void dynarray_reset(void *pp, int *n);
1101ST_INLN void cstr_ccat(CString *cstr, int ch);1101ST_INLN void cstr_ccat(CString *cstr, int ch);
1102ST_FUNC void cstr_cat(CString *cstr, const char *str, int len);1102ST_FUNC void cstr_cat(CString *cstr, const char *str, int len);
@@ -1486,7 +1486,6 @@ static inline void add64le(unsigned char *p, int64_t x) { · 383 unmodified lines
1486/* ------------ i386-gen.c ------------ */1486/* ------------ i386-gen.c ------------ */
1487#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_641487#if defined TCC_TARGET_I386 || defined TCC_TARGET_X86_64
1488ST_FUNC void g(int c);1488ST_FUNC void g(int c);
1489ST_FUNC int oad(int c, int s);
1490ST_FUNC void gen_le16(int c);1489ST_FUNC void gen_le16(int c);
1491ST_FUNC void gen_le32(int c);1490ST_FUNC void gen_le32(int c);
1492ST_FUNC void gen_addr32(int r, Sym *sym, long c);1491ST_FUNC void gen_addr32(int r, Sym *sym, long c);
@@ -1510,7 +1509,6 @@ ST_FUNC void gen_opl(int op); · 17 unmodified lines
1510ST_FUNC char *default_elfinterp(struct TCCState *s);1509ST_FUNC char *default_elfinterp(struct TCCState *s);
1511#endif1510#endif
1512ST_FUNC void arm_init(struct TCCState *s);1511ST_FUNC void arm_init(struct TCCState *s);
1513ST_FUNC uint32_t encbranch(int pos, int addr, int fail);
1514ST_FUNC void gen_cvt_itof1(int t);1512ST_FUNC void gen_cvt_itof1(int t);
1515#endif1513#endif
1516 1514
tccelf.c+7−8
@@ -49,7 +49,7 @@ static int new_undef_sym = 0; /* Is there a new undefined sym since last new_und · 48 unmodified lines
49ST_FUNC void tccelf_new(TCCState *s)49ST_FUNC void tccelf_new(TCCState *s)
50{50{
51 /* no section zero */51 /* no section zero */
52 dynarray_add((void ***)&s->sections, &s->nb_sections, NULL);52 dynarray_add(&s->sections, &s->nb_sections, NULL);
53 53
54 /* create standard sections */54 /* create standard sections */
55 text_section = new_section(s, ".text", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR);55 text_section = new_section(s, ".text", SHT_PROGBITS, SHF_ALLOC | SHF_EXECINSTR);
@@ -153,10 +153,10 @@ ST_FUNC Section *new_section(TCCState *s1, const char *name, int sh_type, int sh · 97 unmodified lines
153 }153 }
154 154
155 if (sh_flags & SHF_PRIVATE) {155 if (sh_flags & SHF_PRIVATE) {
156 dynarray_add((void ***)&s1->priv_sections, &s1->nb_priv_sections, sec);156 dynarray_add(&s1->priv_sections, &s1->nb_priv_sections, sec);
157 } else {157 } else {
158 sec->sh_num = s1->nb_sections;158 sec->sh_num = s1->nb_sections;
159 dynarray_add((void ***)&s1->sections, &s1->nb_sections, sec);159 dynarray_add(&s1->sections, &s1->nb_sections, sec);
160 }160 }
161 161
162 return sec;162 return sec;
@@ -1896,7 +1896,7 @@ static int tcc_write_elf_file(TCCState *s1, const char *filename, int phnum, · 1733 unmodified lines
1896static int elf_output_file(TCCState *s1, const char *filename)1896static int elf_output_file(TCCState *s1, const char *filename)
1897{1897{
1898 int i, ret, phnum, shnum, file_type, file_offset, *sec_order;1898 int i, ret, phnum, shnum, file_type, file_offset, *sec_order;
1899 struct dyn_inf dyninf;1899 struct dyn_inf dyninf = {0};
1900 ElfW(Phdr) *phdr;1900 ElfW(Phdr) *phdr;
1901 ElfW(Sym) *sym;1901 ElfW(Sym) *sym;
1902 Section *strsec, *interp, *dynamic, *dynstr;1902 Section *strsec, *interp, *dynamic, *dynstr;
@@ -1912,7 +1912,6 @@ static int elf_output_file(TCCState *s1, const char *filename) · 9 unmodified lines
1912 phdr = NULL;1912 phdr = NULL;
1913 sec_order = NULL;1913 sec_order = NULL;
1914 interp = dynamic = dynstr = NULL; /* avoid warning */1914 interp = dynamic = dynstr = NULL; /* avoid warning */
1915 dyninf.dyn_rel_off = 0; /* avoid warning */
1916 1915
1917 if (file_type != TCC_OUTPUT_OBJ) {1916 if (file_type != TCC_OUTPUT_OBJ) {
1918 relocate_common_syms();1917 relocate_common_syms();
@@ -2595,7 +2594,7 @@ ST_FUNC int tcc_load_dll(TCCState *s1, int fd, const char *filename, int level) · 676 unmodified lines
2595 dllref = tcc_mallocz(sizeof(DLLReference) + strlen(soname));2594 dllref = tcc_mallocz(sizeof(DLLReference) + strlen(soname));
2596 dllref->level = level;2595 dllref->level = level;
2597 strcpy(dllref->name, soname);2596 strcpy(dllref->name, soname);
2598 dynarray_add((void ***)&s1->loaded_dlls, &s1->nb_loaded_dlls, dllref);2597 dynarray_add(&s1->loaded_dlls, &s1->nb_loaded_dlls, dllref);
2599 2598
2600 /* add dynamic symbols in dynsym_section */2599 /* add dynamic symbols in dynsym_section */
2601 for(i = 1, sym = dynsym + 1; i < nb_syms; i++, sym++) {2600 for(i = 1, sym = dynsym + 1; i < nb_syms; i++, sym++) {
@@ -2825,9 +2824,9 @@ static int ld_add_file_list(TCCState *s1, const char *cmd, int as_needed) · 223 unmodified lines
2825 goto lib_parse_error;2824 goto lib_parse_error;
2826 if (group) {2825 if (group) {
2827 /* Add the filename *and* the libname to avoid future conversions */2826 /* Add the filename *and* the libname to avoid future conversions */
2828 dynarray_add((void ***) &libs, &nblibs, tcc_strdup(filename));2827 dynarray_add(&libs, &nblibs, tcc_strdup(filename));
2829 if (libname[0] != '\0')2828 if (libname[0] != '\0')
2830 dynarray_add((void ***) &libs, &nblibs, tcc_strdup(libname));2829 dynarray_add(&libs, &nblibs, tcc_strdup(libname));
2831 }2830 }
2832 }2831 }
2833 }2832 }
tccgen.c+23−41
@@ -1608,23 +1608,15 @@ static void gen_opl(int op) · 1607 unmodified lines
1608 a = 0;1608 a = 0;
1609 b = 0;1609 b = 0;
1610 gen_op(op1);1610 gen_op(op1);
1611 if (op1 != TOK_NE) {1611 if (op == TOK_NE) {
1612 b = gvtst(0, 0);
1613 } else {
1612 a = gvtst(1, 0);1614 a = gvtst(1, 0);
1613 }1615 if (op != TOK_EQ) {
1614 if (op != TOK_EQ) {1616 /* generate non equal test */
1615 /* generate non equal test */1617 vpushi(TOK_NE);
1616 /* XXX: NOT PORTABLE yet */1618 vtop->r = VT_CMP;
1617 if (op1 == TOK_NE) {
1618 b = gvtst(0, 0);1619 b = gvtst(0, 0);
1619 } else {
1620#if defined(TCC_TARGET_I386)
1621 b = gjmp2(0x850f, 0);
1622#elif defined(TCC_TARGET_ARM)
1623 b = ind;
1624 o(0x1A000000 | encbranch(ind, 0, 1));
1625#else
1626 tcc_error("not implemented");
1627#endif
1628 }1620 }
1629 }1621 }
1630 /* compare low. Always unsigned */1622 /* compare low. Always unsigned */
@@ -4724,23 +4716,13 @@ ST_FUNC void unary(void) · 3093 unmodified lines
4724 tcc_warning("implicit declaration of function '%s'", name);4716 tcc_warning("implicit declaration of function '%s'", name);
4725 s = external_global_sym(t, &func_old_type, 0); 4717 s = external_global_sym(t, &func_old_type, 0);
4726 }4718 }
4727 if ((s->type.t & (VT_STATIC | VT_INLINE | VT_BTYPE)) ==4719
4728 (VT_STATIC | VT_INLINE | VT_FUNC)) {4720 r = s->r;
4729 /* if referencing an inline function, then we generate a4721 /* A symbol that has a register is a local register variable,
4730 symbol to it if not already done. It will have the4722 which starts out as VT_LOCAL value. */
4731 effect to generate code for it at the end of the4723 if ((r & VT_VALMASK) < VT_CONST)
4732 compilation unit. Inline function as always4724 r = (r & ~VT_VALMASK) | VT_LOCAL;
4733 generated in the text section. */4725
4734 if (!s->c && !nocode_wanted)
4735 put_extern_sym(s, text_section, 0, 0);
4736 r = VT_SYM | VT_CONST;
4737 } else {
4738 r = s->r;
4739 /* A symbol that has a register is a local register variable,
4740 which starts out as VT_LOCAL value. */
4741 if ((r & VT_VALMASK) < VT_CONST)
4742 r = (r & ~VT_VALMASK) | VT_LOCAL;
4743 }
4744 vset(&s->type, r, s->c);4726 vset(&s->type, r, s->c);
4745 /* Point to s as backpointer (even without r&VT_SYM).4727 /* Point to s as backpointer (even without r&VT_SYM).
4746 Will be used by at least the x86 inline asm parser for4728 Will be used by at least the x86 inline asm parser for
@@ -4822,7 +4804,7 @@ ST_FUNC void unary(void) · 75 unmodified lines
4822 s = vtop->type.ref;4804 s = vtop->type.ref;
4823 next();4805 next();
4824 sa = s->next; /* first parameter */4806 sa = s->next; /* first parameter */
4825 nb_args = 0;4807 nb_args = regsize = 0;
4826 ret.r2 = VT_CONST;4808 ret.r2 = VT_CONST;
4827 /* compute first implicit argument if a structure is returned */4809 /* compute first implicit argument if a structure is returned */
4828 if ((s->type.t & VT_BTYPE) == VT_STRUCT) {4810 if ((s->type.t & VT_BTYPE) == VT_STRUCT) {
@@ -5849,7 +5831,7 @@ static void block(int *bsym, int *csym, int is_expr) · 1020 unmodified lines
5849 tcc_warning("empty case range");5831 tcc_warning("empty case range");
5850 }5832 }
5851 cr->sym = ind;5833 cr->sym = ind;
5852 dynarray_add((void***) &cur_switch->p, &cur_switch->n, cr);5834 dynarray_add(&cur_switch->p, &cur_switch->n, cr);
5853 skip(':');5835 skip(':');
5854 is_expr = 0;5836 is_expr = 0;
5855 goto block_after_label;5837 goto block_after_label;
@@ -6897,7 +6879,6 @@ static void gen_inline_functions(TCCState *s) · 1041 unmodified lines
6897 fn->sym = NULL;6879 fn->sym = NULL;
6898 if (file)6880 if (file)
6899 pstrcpy(file->filename, sizeof file->filename, fn->filename);6881 pstrcpy(file->filename, sizeof file->filename, fn->filename);
6900 sym->r = VT_SYM | VT_CONST;
6901 sym->type.t &= ~VT_INLINE;6882 sym->type.t &= ~VT_INLINE;
6902 6883
6903 begin_macro(fn->func_str, 1);6884 begin_macro(fn->func_str, 1);
@@ -7038,8 +7019,6 @@ static int decl0(int l, int is_for_loop_init) · 134 unmodified lines
7038 goto func_error1;7019 goto func_error1;
7039 7020
7040 ref = sym->type.ref;7021 ref = sym->type.ref;
7041 if (0 == ref->a.func_proto)
7042 tcc_error("redefinition of '%s'", get_tok_str(v, NULL));
7043 7022
7044 /* use func_call from prototype if not defined */7023 /* use func_call from prototype if not defined */
7045 if (ref->a.func_call != FUNC_CDECL7024 if (ref->a.func_call != FUNC_CDECL
@@ -7064,15 +7043,20 @@ static int decl0(int l, int is_for_loop_init) · 18 unmodified lines
7064 tcc_error("incompatible types for redefinition of '%s'", 7043 tcc_error("incompatible types for redefinition of '%s'",
7065 get_tok_str(v, NULL));7044 get_tok_str(v, NULL));
7066 }7045 }
7067 type.ref->a.func_proto = 0;7046 if (ref->a.func_body)
7047 tcc_error("redefinition of '%s'", get_tok_str(v, NULL));
7068 /* if symbol is already defined, then put complete type */7048 /* if symbol is already defined, then put complete type */
7069 sym->type = type;7049 sym->type = type;
7050
7070 } else {7051 } else {
7071 /* put function symbol */7052 /* put function symbol */
7072 sym = global_identifier_push(v, type.t, 0);7053 sym = global_identifier_push(v, type.t, 0);
7073 sym->type.ref = type.ref;7054 sym->type.ref = type.ref;
7074 }7055 }
7075 7056
7057 sym->type.ref->a.func_body = 1;
7058 sym->r = VT_SYM | VT_CONST;
7059
7076 /* static inline functions are just recorded as a kind7060 /* static inline functions are just recorded as a kind
7077 of macro. Their code will be emitted at the end of7061 of macro. Their code will be emitted at the end of
7078 the compilation unit only if they are used */7062 the compilation unit only if they are used */
@@ -7106,14 +7090,13 @@ static int decl0(int l, int is_for_loop_init) · 27 unmodified lines
7106 }7090 }
7107 tok_str_add(fn->func_str, -1);7091 tok_str_add(fn->func_str, -1);
7108 tok_str_add(fn->func_str, 0);7092 tok_str_add(fn->func_str, 0);
7109 dynarray_add((void ***)&tcc_state->inline_fns, &tcc_state->nb_inline_fns, fn);7093 dynarray_add(&tcc_state->inline_fns, &tcc_state->nb_inline_fns, fn);
7110 7094
7111 } else {7095 } else {
7112 /* compute text section */7096 /* compute text section */
7113 cur_text_section = ad.section;7097 cur_text_section = ad.section;
7114 if (!cur_text_section)7098 if (!cur_text_section)
7115 cur_text_section = text_section;7099 cur_text_section = text_section;
7116 sym->r = VT_SYM | VT_CONST;
7117 gen_function(sym);7100 gen_function(sym);
7118 }7101 }
7119 break;7102 break;
@@ -7138,7 +7121,6 @@ static int decl0(int l, int is_for_loop_init) · 18 unmodified lines
7138 if ((type.t & VT_BTYPE) == VT_FUNC) {7121 if ((type.t & VT_BTYPE) == VT_FUNC) {
7139 /* external function definition */7122 /* external function definition */
7140 /* specific case for func_call attribute */7123 /* specific case for func_call attribute */
7141 ad.a.func_proto = 1;
7142 type.ref->a = ad.a;7124 type.ref->a = ad.a;
7143 } else if (!(type.t & VT_ARRAY)) {7125 } else if (!(type.t & VT_ARRAY)) {
7144 /* not lvalue if array */7126 /* not lvalue if array */
tccpe.c+8−4
@@ -691,6 +691,10 @@ static int pe_write(struct pe_info *pe) · 690 unmodified lines
691 psh->PointerToRawData = file_offset;691 psh->PointerToRawData = file_offset;
692 file_offset = pe_file_align(pe, file_offset + si->data_size);692 file_offset = pe_file_align(pe, file_offset + si->data_size);
693 psh->SizeOfRawData = file_offset - psh->PointerToRawData;693 psh->SizeOfRawData = file_offset - psh->PointerToRawData;
694 if (si->cls == sec_text)
695 pe_header.opthdr.SizeOfCode += psh->SizeOfRawData;
696 else
697 pe_header.opthdr.SizeOfInitializedData += psh->SizeOfRawData;
694 }698 }
695 }699 }
696 700
@@ -753,7 +757,7 @@ static struct import_symbol *pe_add_import(struct pe_info *pe, int sym_index) · 56 unmodified lines
753 }757 }
754 p = tcc_mallocz(sizeof *p);758 p = tcc_mallocz(sizeof *p);
755 p->dll_index = dll_index;759 p->dll_index = dll_index;
756 dynarray_add((void***)&pe->imp_info, &pe->imp_count, p);760 dynarray_add(&pe->imp_info, &pe->imp_count, p);
757 761
758found_dll:762found_dll:
759 i = dynarray_assoc ((void**)p->symbols, p->sym_count, sym_index);763 i = dynarray_assoc ((void**)p->symbols, p->sym_count, sym_index);
@@ -761,7 +765,7 @@ found_dll: · 1 unmodified line
761 return p->symbols[i];765 return p->symbols[i];
762 766
763 s = tcc_mallocz(sizeof *s);767 s = tcc_mallocz(sizeof *s);
764 dynarray_add((void***)&p->symbols, &p->sym_count, s);768 dynarray_add(&p->symbols, &p->sym_count, s);
765 s->sym_index = sym_index;769 s->sym_index = sym_index;
766 return s;770 return s;
767}771}
@@ -904,7 +908,7 @@ static void pe_build_exports(struct pe_info *pe) · 136 unmodified lines
904 p = tcc_malloc(sizeof *p);908 p = tcc_malloc(sizeof *p);
905 p->index = sym_index;909 p->index = sym_index;
906 p->name = name;910 p->name = name;
907 dynarray_add((void***)&sorted, &sym_count, p);911 dynarray_add(&sorted, &sym_count, p);
908 }912 }
909#if 0913#if 0
910 if (sym->st_other & ST_PE_EXPORT)914 if (sym->st_other & ST_PE_EXPORT)
@@ -1515,7 +1519,7 @@ static int add_dllref(TCCState *s1, const char *dllname) · 604 unmodified lines
1515 return i + 1;1519 return i + 1;
1516 dllref = tcc_mallocz(sizeof(DLLReference) + strlen(dllname));1520 dllref = tcc_mallocz(sizeof(DLLReference) + strlen(dllname));
1517 strcpy(dllref->name, dllname);1521 strcpy(dllref->name, dllname);
1518 dynarray_add((void ***) &s1->loaded_dlls, &s1->nb_loaded_dlls, dllref);1522 dynarray_add(&s1->loaded_dlls, &s1->nb_loaded_dlls, dllref);
1519 return s1->nb_loaded_dlls;1523 return s1->nb_loaded_dlls;
1520}1524}
1521 1525
tccpp.c+3−3
@@ -1566,7 +1566,7 @@ static CachedInclude *search_cached_include(TCCState *s1, const char *filename, · 1565 unmodified lines
1566 e = tcc_malloc(sizeof(CachedInclude) + strlen(filename));1566 e = tcc_malloc(sizeof(CachedInclude) + strlen(filename));
1567 strcpy(e->filename, filename);1567 strcpy(e->filename, filename);
1568 e->ifndef_macro = e->once = 0;1568 e->ifndef_macro = e->once = 0;
1569 dynarray_add((void ***)&s1->cached_includes, &s1->nb_cached_includes, e);1569 dynarray_add(&s1->cached_includes, &s1->nb_cached_includes, e);
1570 /* add in hash table */1570 /* add in hash table */
1571 e->hash_next = s1->cached_includes_hash[h];1571 e->hash_next = s1->cached_includes_hash[h];
1572 s1->cached_includes_hash[h] = s1->nb_cached_includes;1572 s1->cached_includes_hash[h] = s1->nb_cached_includes;
@@ -1665,7 +1665,7 @@ static void pragma_parse(TCCState *s1) · 92 unmodified lines
1665 if (tok != TOK_STR)1665 if (tok != TOK_STR)
1666 goto pragma_err;1666 goto pragma_err;
1667 file = tcc_strdup((char *)tokc.str.data);1667 file = tcc_strdup((char *)tokc.str.data);
1668 dynarray_add((void ***)&s1->pragma_libs, &s1->nb_pragma_libs, file);1668 dynarray_add(&s1->pragma_libs, &s1->nb_pragma_libs, file);
1669 next();1669 next();
1670 if (tok != ')')1670 if (tok != ')')
1671 goto pragma_err;1671 goto pragma_err;
@@ -1820,7 +1820,7 @@ ST_FUNC void preprocess(int is_bof) · 148 unmodified lines
1820 printf("%s: including %s\n", file->prev->filename, file->filename);1820 printf("%s: including %s\n", file->prev->filename, file->filename);
1821#endif1821#endif
1822 /* update target deps */1822 /* update target deps */
1823 dynarray_add((void ***)&s1->target_deps, &s1->nb_target_deps,1823 dynarray_add(&s1->target_deps, &s1->nb_target_deps,
1824 tcc_strdup(buf1));1824 tcc_strdup(buf1));
1825 /* push current file in stack */1825 /* push current file in stack */
1826 ++s1->include_stack_ptr;1826 ++s1->include_stack_ptr;
x86_64-gen.c+1−1
@@ -224,7 +224,7 @@ static int is64_type(int t) · 223 unmodified lines
224}224}
225 225
226/* instruction + 4 bytes data. Return the address of the data */226/* instruction + 4 bytes data. Return the address of the data */
227ST_FUNC int oad(int c, int s)227static int oad(int c, int s)
228{228{
229 int t;229 int t;
230 if (nocode_wanted)230 if (nocode_wanted)

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