History

tidy support for helper function such as memmove

tcc.h, tccgen.c: Introduce Sym *external_helper_sym(int v); to create an external reference with no specific type. This avoids type conflicts if the symbol is used from C too. the other files: use it.

grischka committed 5 years ago

Commit 4a42b0d1 parent 2f78f548 files · +59 −58Browse files

Unified · Split

8 files
  1. arm-gen.c +5 −5
  2. arm64-gen.c +6 −6
  3. c67-gen.c +3 −3
  4. i386-gen.c +5 −5
  5. riscv64-gen.c +6 −6
  6. tcc.h +2 −1
  7. tccgen.c +29 −29
  8. x86_64-gen.c +3 −3
arm-gen.c+5−5
@@ -785,7 +785,7 @@ static void gcall_or_jmp(int is_jmp) · 784 unmodified lines
785785
786786 static void gen_bounds_call(int v)
787787 {
788− Sym *sym = external_global_sym(v, &func_old_type);
788+ Sym *sym = external_helper_sym(v);
789789
790790 greloc(cur_text_section, sym, ind, R_ARM_PC24);
791791 o(0xebfffffe);
@@ -1717,7 +1717,7 @@ done: · 925 unmodified lines
17171717 vtop--;
17181718 break;
17191719 case 3:
1720− vpush_global_sym(&func_old_type, func);
1720+ vpush_helper_func(func);
17211721 vrott(3);
17221722 gfunc_call(2);
17231723 vpushi(0);
@@ -2137,7 +2137,7 @@ ST_FUNC void gen_cvt_itof(int t) · 413 unmodified lines
21372137 func=TOK___floatdidf;
21382138 }
21392139 if(func_type) {
2140− vpush_global_sym(func_type, func);
2140+ vpushsym(func_type, external_helper_sym(func));
21412141 vswap();
21422142 gfunc_call(1);
21432143 vpushi(0);
@@ -2196,7 +2196,7 @@ void gen_cvt_ftoi(int t) · 52 unmodified lines
21962196 func=TOK___fixdfdi;
21972197 }
21982198 if(func) {
2199− vpush_global_sym(&func_old_type, func);
2199+ vpush_helper_func(func);
22002200 vswap();
22012201 gfunc_call(1);
22022202 vpushi(0);
@@ -2277,7 +2277,7 @@ ST_FUNC void gen_vla_alloc(CType *type, int align) { · 74 unmodified lines
22772277 vtop->r = TREG_R0;
22782278 o(0xe1a0000d | (vtop->r << 12)); // mov r0,sp
22792279 vswap();
2280− vpush_global_sym(&func_old_type, TOK___bound_new_region);
2280+ vpush_helper_func(TOK___bound_new_region);
22812281 vrott(3);
22822282 gfunc_call(2);
22832283 func_bound_add_epilog = 1;
arm64-gen.c+6−6
@@ -662,7 +662,7 @@ static void arm64_gen_bl_or_b(int b) · 661 unmodified lines
662662
663663 static void gen_bounds_call(int v)
664664 {
665− Sym *sym = external_global_sym(v, &func_old_type);
665+ Sym *sym = external_helper_sym(v);
666666
667667 greloca(cur_text_section, sym, ind, R_AARCH64_CALL26, 0);
668668 o(0x94000000); // bl
@@ -1782,7 +1782,7 @@ ST_FUNC void gen_opf(int op) · 1113 unmodified lines
17821782 case TOK_GT: func = TOK___gttf2; cond = 13; break;
17831783 default: assert(0); break;
17841784 }
1785− vpush_global_sym(&func_old_type, func);
1785+ vpush_helper_func(func);
17861786 vrott(3);
17871787 gfunc_call(2);
17881788 vpushi(0);
@@ -1885,7 +1885,7 @@ ST_FUNC void gen_cvt_itof(int t) · 96 unmodified lines
18851885 int func = (f & VT_BTYPE) == VT_LLONG ?
18861886 (f & VT_UNSIGNED ? TOK___floatunditf : TOK___floatditf) :
18871887 (f & VT_UNSIGNED ? TOK___floatunsitf : TOK___floatsitf);
1888− vpush_global_sym(&func_old_type, func);
1888+ vpush_helper_func(func);
18891889 vrott(2);
18901890 gfunc_call(1);
18911891 vpushi(0);
@@ -1913,7 +1913,7 @@ ST_FUNC void gen_cvt_ftoi(int t) · 21 unmodified lines
19131913 int func = (t & VT_BTYPE) == VT_LLONG ?
19141914 (t & VT_UNSIGNED ? TOK___fixunstfdi : TOK___fixtfdi) :
19151915 (t & VT_UNSIGNED ? TOK___fixunstfsi : TOK___fixtfsi);
1916− vpush_global_sym(&func_old_type, func);
1916+ vpush_helper_func(func);
19171917 vrott(2);
19181918 gfunc_call(1);
19191919 vpushi(0);
@@ -1947,7 +1947,7 @@ ST_FUNC void gen_cvt_ftof(int t) · 27 unmodified lines
19471947 int func = (t == VT_LDOUBLE) ?
19481948 (f == VT_FLOAT ? TOK___extendsftf2 : TOK___extenddftf2) :
19491949 (t == VT_FLOAT ? TOK___trunctfsf2 : TOK___trunctfdf2);
1950− vpush_global_sym(&func_old_type, func);
1950+ vpush_helper_func(func);
19511951 vrott(2);
19521952 gfunc_call(1);
19531953 vpushi(0);
@@ -2061,7 +2061,7 @@ ST_FUNC void gen_vla_alloc(CType *type, int align) { · 107 unmodified lines
20612061 vtop->r = TREG_R(0);
20622062 o(0x910003e0 | vtop->r); // mov r0,sp
20632063 vswap();
2064− vpush_global_sym(&func_old_type, TOK___bound_new_region);
2064+ vpush_helper_func(TOK___bound_new_region);
20652065 vrott(3);
20662066 gfunc_call(2);
20672067 func_bound_add_epilog = 1;
c67-gen.c+3−3
@@ -2254,7 +2254,7 @@ void gen_opi(int op) · 2253 unmodified lines
22542254 call_func:
22552255 vswap();
22562256 /* call generic idiv function */
2257− vpush_global_sym(&func_old_type, t);
2257+ vpush_helper_func(t);
22582258 vrott(3);
22592259 gfunc_call(2);
22602260 vpushi(0);
@@ -2385,7 +2385,7 @@ void gen_opf(int op) · 124 unmodified lines
23852385 // must call intrinsic DP floating point divide
23862386 vswap();
23872387 /* call generic idiv function */
2388− vpush_global_sym(&func_old_type, TOK__divd);
2388+ vpush_helper_func(TOK__divd);
23892389 vrott(3);
23902390 gfunc_call(2);
23912391 vpushi(0);
@@ -2396,7 +2396,7 @@ void gen_opf(int op) · 4 unmodified lines
23962396 // must call intrinsic SP floating point divide
23972397 vswap();
23982398 /* call generic idiv function */
2399− vpush_global_sym(&func_old_type, TOK__divf);
2399+ vpush_helper_func(TOK__divf);
24002400 vrott(3);
24012401 gfunc_call(2);
24022402 vpushi(0);
i386-gen.c+5−5
@@ -345,7 +345,7 @@ static void gen_static_call(int v) · 344 unmodified lines
345345 {
346346 Sym *sym;
347347
348− sym = external_global_sym(v, &func_old_type);
348+ sym = external_helper_sym(v);
349349 oad(0xe8, -4);
350350 greloc(cur_text_section, sym, ind-4, R_386_PC32);
351351 }
@@ -985,11 +985,11 @@ ST_FUNC void gen_cvt_ftoi(int t) · 633 unmodified lines
985985 {
986986 int bt = vtop->type.t & VT_BTYPE;
987987 if (bt == VT_FLOAT)
988− vpush_global_sym(&func_old_type, TOK___fixsfdi);
988+ vpush_helper_func(TOK___fixsfdi);
989989 else if (bt == VT_LDOUBLE)
990− vpush_global_sym(&func_old_type, TOK___fixxfdi);
990+ vpush_helper_func(TOK___fixxfdi);
991991 else
992− vpush_global_sym(&func_old_type, TOK___fixdfdi);
992+ vpush_helper_func(TOK___fixdfdi);
993993 vswap();
994994 gfunc_call(1);
995995 vpushi(0);
@@ -1099,7 +1099,7 @@ ST_FUNC void gen_vla_alloc(CType *type, int align) { · 103 unmodified lines
10991099 #endif
11001100 if (use_call)
11011101 {
1102− vpush_global_sym(&func_old_type, TOK_alloca);
1102+ vpush_helper_func(TOK_alloca);
11031103 vswap(); /* Move alloca ref past allocation size */
11041104 gfunc_call(1);
11051105 }
riscv64-gen.c+6−6
@@ -402,7 +402,7 @@ static void gcall_or_jmp(int docall) · 401 unmodified lines
402402
403403 static void gen_bounds_call(int v)
404404 {
405− Sym *sym = external_global_sym(v, &func_old_type);
405+ Sym *sym = external_helper_sym(v);
406406
407407 greloca(cur_text_section, sym, ind, R_RISCV_CALL_PLT, 0);
408408 o(0x17 | (1 << 7)); // auipc TR, 0 %call(func)
@@ -1125,7 +1125,7 @@ ST_FUNC void gen_opf(int op) · 716 unmodified lines
11251125 case TOK_GT: func = TOK___gttf2; cond = 13; break;
11261126 default: assert(0); break;
11271127 }
1128− vpush_global_sym(&func_old_type, func);
1128+ vpush_helper_func(func);
11291129 vrott(3);
11301130 gfunc_call(2);
11311131 vpushi(0);
@@ -1213,7 +1213,7 @@ ST_FUNC void gen_cvt_itof(int t) · 81 unmodified lines
12131213 int func = l ?
12141214 (u ? TOK___floatunditf : TOK___floatditf) :
12151215 (u ? TOK___floatunsitf : TOK___floatsitf);
1216− vpush_global_sym(&func_old_type, func);
1216+ vpush_helper_func(func);
12171217 vrott(2);
12181218 gfunc_call(1);
12191219 vpushi(0);
@@ -1239,7 +1239,7 @@ ST_FUNC void gen_cvt_ftoi(int t) · 19 unmodified lines
12391239 int func = l ?
12401240 (u ? TOK___fixunstfdi : TOK___fixtfdi) :
12411241 (u ? TOK___fixunstfsi : TOK___fixtfsi);
1242− vpush_global_sym(&func_old_type, func);
1242+ vpush_helper_func(func);
12431243 vrott(2);
12441244 gfunc_call(1);
12451245 vpushi(0);
@@ -1281,7 +1281,7 @@ ST_FUNC void gen_cvt_ftof(int dt) · 35 unmodified lines
12811281 vtop->r2 = 1 + vtop->r;
12821282 }
12831283 }
1284− vpush_global_sym(&func_old_type, func);
1284+ vpush_helper_func(func);
12851285 gcall_or_jmp(1);
12861286 vtop -= 2;
12871287 vpushi(0);
@@ -1342,7 +1342,7 @@ ST_FUNC void gen_vla_alloc(CType *type, int align) · 54 unmodified lines
13421342 vtop->r = TREG_R(0);
13431343 o(0x00010513); /* mv a0,sp */
13441344 vswap();
1345− vpush_global_sym(&func_old_type, TOK___bound_new_region);
1345+ vpush_helper_func(TOK___bound_new_region);
13461346 vrott(3);
13471347 gfunc_call(2);
13481348 func_bound_add_epilog = 1;
tcc.h+2−1
@@ -1437,10 +1437,11 @@ ST_FUNC void vpushi(int v); · 1436 unmodified lines
14371437 ST_FUNC ElfSym *elfsym(Sym *);
14381438 ST_FUNC void update_storage(Sym *sym);
14391439 ST_FUNC Sym *external_global_sym(int v, CType *type);
1440+ST_FUNC Sym *external_helper_sym(int v);
1441+ST_FUNC void vpush_helper_func(int v);
14401442 ST_FUNC void vset(CType *type, int r, int v);
14411443 ST_FUNC void vset_VT_CMP(int op);
14421444 ST_FUNC void vswap(void);
1443−ST_FUNC void vpush_global_sym(CType *type, int v);
14441445 ST_FUNC void vrote(SValue *e, int n);
14451446 ST_FUNC void vrott(int n);
14461447 ST_FUNC void vrotb(int n);
tccgen.c+29−29
@@ -80,7 +80,7 @@ ST_DATA int func_var; /* true if current function is variadic (used by return in · 79 unmodified lines
8080 ST_DATA int func_vc;
8181 static int last_line_num, new_file, func_ind; /* debug info control */
8282 ST_DATA const char *funcname;
83−ST_DATA CType int_type, func_old_type, char_type, char_pointer_type, func_mem_move, void_type, void_ptr_type;
83+ST_DATA CType int_type, func_old_type, char_type, char_pointer_type;
8484 static CString initstr;
8585
8686 #if PTR_SIZE == 4
@@ -800,14 +800,6 @@ ST_FUNC void tccgen_init(TCCState *s1) · 713 unmodified lines
800800 char_pointer_type = char_type;
801801 mk_pointer(&char_pointer_type);
802802
803− void_type.t = VT_VOID;
804− void_ptr_type = void_type;
805− mk_pointer(&void_ptr_type);
806− func_mem_move.t = VT_FUNC;
807− func_mem_move.ref = sym_push(SYM_FIELD, &void_ptr_type, 0, 0);
808− func_mem_move.ref->f.func_call = FUNC_CDECL;
809− func_mem_move.ref->f.func_type = FUNC_OLD;
810−
811803 func_old_type.t = VT_FUNC;
812804 func_old_type.ref = sym_push(SYM_FIELD, &int_type, 0, 0);
813805 func_old_type.ref->f.func_call = FUNC_CDECL;
@@ -1493,6 +1485,20 @@ ST_FUNC Sym *external_global_sym(int v, CType *type) · 679 unmodified lines
14931485 return s;
14941486 }
14951487
1488+/* create an external reference with no specific type similar to asm labels.
1489+ This avoids type conflicts if the symbol is used from C too */
1490+ST_FUNC Sym *external_helper_sym(int v)
1491+{
1492+ CType ct = { VT_ASM, NULL };
1493+ return external_global_sym(v, &ct);
1494+}
1495+
1496+/* push a reference to an helper function (such as memmove) */
1497+ST_FUNC void vpush_helper_func(int v)
1498+{
1499+ vpushsym(&func_old_type, external_helper_sym(v));
1500+}
1501+
14961502 /* Merge symbol attributes. */
14971503 static void merge_symattr(struct SymAttr *sa, struct SymAttr *sa1)
14981504 {
@@ -1681,12 +1687,6 @@ static Sym *external_sym(int v, CType *type, int r, AttributeDef *ad) · 182 unmodified lines
16811687 return s;
16821688 }
16831689
1684−/* push a reference to global symbol v */
1685−ST_FUNC void vpush_global_sym(CType *type, int v)
1686−{
1687− vpushsym(type, external_global_sym(v, type));
1688−}
1689−
16901690 /* save registers up to (vtop - n) stack entry */
16911691 ST_FUNC void save_regs(int n)
16921692 {
@@ -1904,7 +1904,7 @@ static void gen_bounded_ptr_add(void) · 211 unmodified lines
19041904 vpushv(&vtop[-1]);
19051905 vrott(3);
19061906 }
1907− vpush_global_sym(&func_old_type, TOK___bound_ptr_add);
1907+ vpush_helper_func(TOK___bound_ptr_add);
19081908 vrott(3);
19091909 gfunc_call(2);
19101910 vtop -= save;
@@ -1941,7 +1941,7 @@ static void gen_bounded_ptr_deref(void) · 30 unmodified lines
19411941 /* may happen with struct member access */
19421942 return;
19431943 }
1944− sym = external_global_sym(func, &func_old_type);
1944+ sym = external_helper_sym(func);
19451945 if (!sym->c)
19461946 put_extern_sym(sym, NULL, 0, 0);
19471947 /* patch relocation */
@@ -1998,7 +1998,7 @@ ST_FUNC void gbound_args(int nb_args) · 50 unmodified lines
19981998 || v == TOK___sigsetjmp
19991999 #endif
20002000 ) {
2001− vpush_global_sym(&func_old_type, TOK___bound_setjmp);
2001+ vpush_helper_func(TOK___bound_setjmp);
20022002 vpushv(sv + 1);
20032003 gfunc_call(1);
20042004 func_bound_add_epilog = 1;
@@ -2415,7 +2415,7 @@ static void gen_opl(int op) · 410 unmodified lines
24152415 #endif
24162416 gen_func:
24172417 /* call generic long long function */
2418− vpush_global_sym(&func_old_type, func);
2418+ vpush_helper_func(func);
24192419 vrott(3);
24202420 gfunc_call(2);
24212421 vpushi(0);
@@ -3379,13 +3379,13 @@ static void gen_cvt_itof1(int t) · 957 unmodified lines
33793379 (VT_LLONG | VT_UNSIGNED)) {
33803380
33813381 if (t == VT_FLOAT)
3382− vpush_global_sym(&func_old_type, TOK___floatundisf);
3382+ vpush_helper_func(TOK___floatundisf);
33833383 #if LDOUBLE_SIZE != 8
33843384 else if (t == VT_LDOUBLE)
3385− vpush_global_sym(&func_old_type, TOK___floatundixf);
3385+ vpush_helper_func(TOK___floatundixf);
33863386 #endif
33873387 else
3388− vpush_global_sym(&func_old_type, TOK___floatundidf);
3388+ vpush_helper_func(TOK___floatundidf);
33893389 vrott(2);
33903390 gfunc_call(1);
33913391 vpushi(0);
@@ -3407,13 +3407,13 @@ static void gen_cvt_ftoi1(int t) · 15 unmodified lines
34073407 /* not handled natively */
34083408 st = vtop->type.t & VT_BTYPE;
34093409 if (st == VT_FLOAT)
3410− vpush_global_sym(&func_old_type, TOK___fixunssfdi);
3410+ vpush_helper_func(TOK___fixunssfdi);
34113411 #if LDOUBLE_SIZE != 8
34123412 else if (st == VT_LDOUBLE)
3413− vpush_global_sym(&func_old_type, TOK___fixunsxfdi);
3413+ vpush_helper_func(TOK___fixunsxfdi);
34143414 #endif
34153415 else
3416− vpush_global_sym(&func_old_type, TOK___fixunsdfdi);
3416+ vpush_helper_func(TOK___fixunsdfdi);
34173417 vrott(2);
34183418 gfunc_call(1);
34193419 vpushi(0);
@@ -3904,13 +3904,13 @@ ST_FUNC void vstore(void) · 484 unmodified lines
39043904 /* address of memcpy() */
39053905 #ifdef TCC_ARM_EABI
39063906 if(!(align & 7))
3907− vpush_global_sym(&func_old_type, TOK_memmove8);
3907+ vpush_helper_func(TOK_memmove8);
39083908 else if(!(align & 3))
3909− vpush_global_sym(&func_old_type, TOK_memmove4);
3909+ vpush_helper_func(TOK_memmove4);
39103910 else
39113911 #endif
39123912 /* Use memmove, rather than memcpy, as dest and src may be same: */
3913− vpush_global_sym(&func_mem_move, TOK_memmove);
3913+ vpush_helper_func(TOK_memmove);
39143914
39153915 vswap();
39163916 /* source */
@@ -7363,7 +7363,7 @@ static void init_putz(init_params *p, unsigned long c, int size) · 3446 unmodified lines
73637363 if (p->sec) {
73647364 /* nothing to do because globals are already set to zero */
73657365 } else {
7366− vpush_global_sym(&func_old_type, TOK_memset);
7366+ vpush_helper_func(TOK_memset);
73677367 vseti(VT_LOCAL, c);
73687368 #ifdef TCC_TARGET_ARM
73697369 vpushs(size);
x86_64-gen.c+3−3
@@ -653,7 +653,7 @@ static void gcall_or_jmp(int is_jmp) · 652 unmodified lines
653653
654654 static void gen_bounds_call(int v)
655655 {
656− Sym *sym = external_global_sym(v, &func_old_type);
656+ Sym *sym = external_helper_sym(v);
657657 oad(0xe8, 0);
658658 #ifdef TCC_TARGET_PE
659659 greloca(cur_text_section, sym, ind-4, R_X86_64_PC32, -4);
@@ -1022,7 +1022,7 @@ void gfunc_epilog(void) · 362 unmodified lines
10221022 v = -loc;
10231023
10241024 if (v >= 4096) {
1025− Sym *sym = external_global_sym(TOK___chkstk, &func_old_type);
1025+ Sym *sym = external_helper_sym(TOK___chkstk);
10261026 oad(0xb8, v); /* mov stacksize, %eax */
10271027 oad(0xe8, 0); /* call __chkstk, (does the stackframe too) */
10281028 greloca(cur_text_section, sym, ind-4, R_X86_64_PC32, -4);
@@ -2209,7 +2209,7 @@ ST_FUNC void gen_vla_alloc(CType *type, int align) { · 1180 unmodified lines
22092209 #endif
22102210 if (use_call)
22112211 {
2212− vpush_global_sym(&func_old_type, TOK_alloca);
2212+ vpush_helper_func(TOK_alloca);
22132213 vswap(); /* Move alloca ref past allocation size */
22142214 gfunc_call(1);
22152215 }

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