History

unsorted adjustments

- configure * use aarch64 instead of arm64 - Makefile * rename the custom include file to "config-extra.mak" * Also avoid "rm -r /*" if $(tccdir) is empty - pp/Makefile * fix .expect generation with gcc - tcc.h * cleanup #defines for _MSC_VER - tccgen.c: * fix const-propagation for &,| * fix anonymous named struct (ms-extension) and enable -fms-extension by default - i386-gen.c * clear VT_DEFSIGN - x86_64-gen.c/win64: * fix passing structs in registers * fix alloca (need to keep "func_scratch" below each alloca area on stack) (This allows to compile a working gnu-make on win64) - tccpp.c * alternative approach to 37999a4fbf3487b363fd0c2f9b7ab622401b202a This is to avoid some slowdown with ## token pasting. * get_tok_str() : return <eof> for TOK_EOF * -funsigned-char: apply to "string" literals as well - tccpe/tools.c: -impdef: support both 32 and 64 bit dlls anyway

grischka committed 9 years ago

Commit 9f79b621 parent 6c468c111 files · +105 −80Browse files

Unified · Split

11 files
  1. Makefile +17 −12
  2. configure +6 −8
  3. i386-gen.c +1 −1
  4. lib/alloca86_64.S +0 −4
  5. libtcc.c +8 −6
  6. tcc.h +10 −12
  7. tccgen.c +10 −4
  8. tccpe.c +18 −19
  9. tccpp.c +7 −4
  10. tcctools.c +1 −2
  11. x86_64-gen.c +27 −8
Makefile+17−12
@@ -151,8 +151,8 @@ DEF-win += -DCONFIG_TCCDIR="\"$(tccdir)/win32\"" · 150 unmodified lines
151151 endif
152152 endif
153153
154−# include custom cross-compiler configuration (see make help)
155−-include config-cross.mak
154+# include custom configuration (see make help)
155+-include config-extra.mak
156156
157157 CORE_FILES = tcc.c tcctools.c libtcc.c tccpp.c tccgen.c tccelf.c tccasm.c tccrun.c
158158 CORE_FILES += tcc.h config.h libtcc.h tcctok.h
@@ -318,7 +318,7 @@ install-win : INSTALL = cp · 159 unmodified lines
318318
319319 # uninstall on windows
320320 uninstall-win:
321− rm -r "$(tccdir)/"*
321+ rm -r "$(tccdir)"
322322
323323 # --------------------------------------------------------------------------
324324 # other stuff
@@ -374,19 +374,24 @@ help: · 49 unmodified lines
374374 @echo " build one specific cross compiler for 'TARGET', as in"
375375 @echo " $(TCC_X)"
376376 @echo ""
377− @echo "Cross compiler configuration:"
378− @echo " make will read custom configuration for cross compilers from a file"
379− @echo " 'config-cross.mak' if present. For example for a windows->i386-linux"
380− @echo " cross-compiler that expects the linux files in <tccdir>/i386-linux:"
377+ @echo "Custom configuration:"
378+ @echo " The makefile includes a file 'config-extra.mak' if it is present."
379+ @echo " This file may contain some custom configuration. For example:"
380+ @echo ""
381+ @echo " NATIVE_DEFINES += -D..."
381382 @echo ""
382− @echo " ROOT-i386 = {B}/i386-linux"
383− @echo " CRT-i386 = {B}/i386-linux/usr/lib"
384− @echo " LIB-i386 = {B}/i386-linux/lib:{B}/i386-linux/usr/lib"
385− @echo " INC-i386 = {B}/lib/include:{B}/i386-linux/usr/include"
386− @echo " DEF-i386 += -D__linux__"
383+ @echo " Or for example to configure the search paths for a cross-compiler"
384+ @echo " that expects the linux files in <tccdir>/i386-linux:"
385+ @echo ""
386+ @echo " ROOT-i386 = {B}/i386-linux"
387+ @echo " CRT-i386 = {B}/i386-linux/usr/lib"
388+ @echo " LIB-i386 = {B}/i386-linux/lib:{B}/i386-linux/usr/lib"
389+ @echo " INC-i386 = {B}/lib/include:{B}/i386-linux/usr/include"
390+ @echo " DEF-i386 += -D__linux__"
387391 @echo ""
388392 @echo "Other supported make targets:"
389393 @echo " install install-strip test tags ETAGS tar clean distclean help"
394+ @echo ""
390395
391396 # --------------------------------------------------------------------------
392397 endif # ($(INCLUDED),no)
configure+6−8
@@ -161,7 +161,7 @@ fi · 160 unmodified lines
161161
162162 case "$cpu" in
163163 x86|i386|i486|i586|i686|i86pc|BePC|i686-AT386)
164− cpu="x86"
164+ cpu="i386"
165165 ;;
166166 x86_64|amd64|x86-64)
167167 cpu="x86_64"
@@ -184,7 +184,7 @@ case "$cpu" in · 16 unmodified lines
184184 cpu="arm"
185185 ;;
186186 aarch64)
187− cpu="arm64"
187+ cpu="aarch64"
188188 ;;
189189 alpha)
190190 cpu="alpha"
@@ -301,7 +301,7 @@ Advanced options (experts only): · 110 unmodified lines
301301 --disable-static make libtcc.so instead of libtcc.a
302302 --enable-static make libtcc.a instead of libtcc.dll (win32)
303303 --disable-rpath disable use of -rpath with the above
304− --with-libgcc use libgcc_s.so.1 instead of libtcc1.a in dynamic link
304+ --with-libgcc use libgcc_s.so.1 instead of libtcc1.a
305305 --enable-mingw32 build windows version on linux with mingw32
306306 --enable-cross build cross compilers
307307 --with-selinux use mmap for executable memory (with tcc -run)
@@ -340,7 +340,7 @@ if test -z "$cross_prefix" ; then · 32 unmodified lines
340340 fi
341341
342342 if test -z "$triplet"; then
343− if test $cpu = "x86_64" -o $cpu = "arm64" ; then
343+ if test $cpu = "x86_64" -o $cpu = "aarch64" ; then
344344 if test -f "/usr/lib64/crti.o" ; then
345345 tcc_lddir="lib64"
346346 fi
@@ -473,13 +473,11 @@ print_mak_int TCC_CPU_VERSION "$cpuver" · 126 unmodified lines
473473
474474 echo "#define GCC_MAJOR $gcc_major" >> $TMPH
475475 echo "#define GCC_MINOR $gcc_minor" >> $TMPH
476−
477−if test "$cpu" = "x86" ; then
478− echo "ARCH=i386" >> config.mak
476+if test "$cpu" = "aarch64" ; then
477+ echo "ARCH=arm64" >> config.mak
479478 else
480479 echo "ARCH=$cpu" >> config.mak
481480 fi
482−
483481 echo "TARGETOS=$targetos" >> config.mak
484482
485483 for v in $confvars ; do
i386-gen.c+1−1
@@ -210,7 +210,7 @@ ST_FUNC void load(int r, SValue *sv) · 209 unmodified lines
210210 #endif
211211
212212 fr = sv->r;
213− ft = sv->type.t;
213+ ft = sv->type.t & ~VT_DEFSIGN;
214214 fc = sv->c.i;
215215
216216 ft &= ~(VT_VOLATILE | VT_CONSTANT);
lib/alloca86_64.S+0−4
@@ -27,10 +27,6 @@ p2: · 26 unmodified lines
2727
2828 sub %rax,%rsp
2929 mov %rsp,%rax
30−#ifdef TCC_TARGET_PE
31− add $32,%rax
32−#endif
33−
3430 p3:
3531 push %rdx
3632 ret
libtcc.c+8−6
@@ -264,7 +264,7 @@ struct mem_debug_header { · 263 unmodified lines
264264 int line_num;
265265 char file_name[MEM_DEBUG_FILE_LEN + 1];
266266 unsigned magic2;
267− __attribute__((aligned(16))) unsigned magic3;
267+ ALIGNED(16) unsigned magic3;
268268 };
269269
270270 typedef struct mem_debug_header mem_debug_header_t;
@@ -581,10 +581,7 @@ ST_FUNC void tcc_open_bf(TCCState *s1, const char *filename, int initlen) · 310 unmodified lines
581581 bf->buf_end = bf->buffer + initlen;
582582 bf->buf_end[0] = CH_EOB; /* put eob symbol */
583583 pstrcpy(bf->filename, sizeof(bf->filename), filename);
584− pstrcpy(bf->filename2, sizeof(bf->filename2), filename);
585−#ifdef _WIN32
586− normalize_slashes(bf->filename);
587−#endif
584+ bf->true_filename = bf->filename;
588585 bf->line_num = 1;
589586 bf->ifdef_stack_ptr = s1->ifdef_stack_ptr;
590587 bf->fd = -1;
@@ -599,6 +596,8 @@ ST_FUNC void tcc_close(void) · 8 unmodified lines
599596 close(bf->fd);
600597 total_lines += bf->line_num;
601598 }
599+ if (bf->true_filename != bf->filename)
600+ tcc_free(bf->true_filename);
602601 file = bf->prev;
603602 tcc_free(bf);
604603 }
@@ -615,8 +614,10 @@ ST_FUNC int tcc_open(TCCState *s1, const char *filename) · 10 unmodified lines
615614 (int)(s1->include_stack_ptr - s1->include_stack), "", filename);
616615 if (fd < 0)
617616 return -1;
618−
619617 tcc_open_bf(s1, filename, 0);
618+#ifdef _WIN32
619+ normalize_slashes(file->filename);
620+#endif
620621 file->fd = fd;
621622 return fd;
622623 }
@@ -737,6 +738,7 @@ LIBTCCAPI TCCState *tcc_new(void) · 114 unmodified lines
737738 s->alacarte_link = 1;
738739 s->nocommon = 1;
739740 s->warn_implicit_function_declaration = 1;
741+ s->ms_extensions = 1;
740742
741743 #ifdef CHAR_IS_UNSIGNED
742744 s->char_is_unsigned = 1;
tcc.h+10−12
@@ -41,10 +41,11 @@ · 40 unmodified lines
4141 # include <dlfcn.h>
4242 # endif
4343 /* XXX: need to define this to use them in non ISOC99 context */
44− extern float strtof (const char *__nptr, char **__endptr);
45− extern long double strtold (const char *__nptr, char **__endptr);
44+extern float strtof (const char *__nptr, char **__endptr);
45+extern long double strtold (const char *__nptr, char **__endptr);
46+#endif
4647
47−#else /* on _WIN32: */
48+#ifdef _WIN32
4849 # include <windows.h>
4950 # include <io.h> /* open, close etc. */
5051 # include <direct.h> /* getcwd */
@@ -52,7 +53,6 @@ · 1 unmodified line
5253 # include <stdint.h>
5354 # endif
5455 # define inline __inline
55−# define inp next_inp /* inp is an intrinsic on msvc */
5656 # define snprintf _snprintf
5757 # define vsnprintf _vsnprintf
5858 # ifndef __GNUC__
@@ -65,6 +65,7 @@ · 6 unmodified lines
6565 # define LIBTCCAPI __declspec(dllexport)
6666 # define PUB_FUNC LIBTCCAPI
6767 # endif
68+# define inp next_inp /* inp is an intrinsic on msvc/mingw */
6869 # ifdef _MSC_VER
6970 # pragma warning (disable : 4244) // conversion from 'uint64_t' to 'int', possible loss of data
7071 # pragma warning (disable : 4267) // conversion from 'size_t' to 'int', possible loss of data
@@ -72,9 +73,6 @@ · 1 unmodified line
7273 # pragma warning (disable : 4018) // signed/unsigned mismatch
7374 # pragma warning (disable : 4146) // unary minus operator applied to unsigned type, result still unsigned
7475 # define ssize_t intptr_t
75−# define __attribute__(x) __declspec x
76−# define aligned align
77−# else
7876 # endif
7977 # undef CONFIG_TCC_STATIC
8078 #endif
@@ -83,12 +81,12 @@ · 2 unmodified lines
8381 # define O_BINARY 0
8482 #endif
8583
86−#ifdef __GNUC__
87−# define NORETURN __attribute__ ((noreturn))
88−#elif defined _MSC_VER
84+#ifdef _MSC_VER
8985 # define NORETURN __declspec(noreturn)
86+# define ALIGNED(x) __declspec(align(x))
9087 #else
91−# define NORETURN
88+# define NORETURN __attribute__((noreturn))
89+# define ALIGNED(x) __attribute__((aligned(x)))
9290 #endif
9391
9492 #ifdef _WIN32
@@ -540,7 +538,7 @@ typedef struct BufferedFile { · 445 unmodified lines
540538 int *ifdef_stack_ptr; /* ifdef_stack value at the start of the file */
541539 int include_next_index; /* next search path */
542540 char filename[1024]; /* filename */
543− char filename2[1024]; /* filename not modified by # line directive */
541+ char *true_filename; /* filename not modified by # line directive */
544542 unsigned char unget[4];
545543 unsigned char buffer[1]; /* extra size for CH_EOB char */
546544 } BufferedFile;
tccgen.c+10−4
@@ -1752,8 +1752,8 @@ static void gen_opic(int op) · 1751 unmodified lines
17521752 vtop--;
17531753 } else if (!const_wanted &&
17541754 c2 && ((l2 == 0 && (op == '&' || op == '*')) ||
1755− (l2 == -1 && op == '|') ||
1756− (l2 == 0xffffffff && t2 != VT_LLONG && op == '|') ||
1755+ (op == '|' &&
1756+ (l2 == -1 || (l2 == 0xFFFFFFFF && t2 != VT_LLONG))) ||
17571757 (l2 == 1 && (op == '%' || op == TOK_UMOD)))) {
17581758 /* treat (x & 0), (x * 0), (x | -1) and (x % 1) as constant */
17591759 if (l2 == 1)
@@ -1767,7 +1767,7 @@ static void gen_opic(int op) · 7 unmodified lines
17671767 op == TOK_SHL || op == TOK_SHR || op == TOK_SAR) &&
17681768 l2 == 0) ||
17691769 (op == '&' &&
1770− l2 == -1))) {
1770+ (l2 == -1 || (l2 == 0xFFFFFFFF && t2 != VT_LLONG))))) {
17711771 /* filter out NOP operations like x*1, x-0, x&-1... */
17721772 vtop--;
17731773 } else if (c2 && (op == '*' || op == TOK_PDIV || op == TOK_UDIV)) {
@@ -1817,6 +1817,10 @@ static void gen_opif(int op) · 43 unmodified lines
18171817 {
18181818 int c1, c2;
18191819 SValue *v1, *v2;
1820+#if defined _MSC_VER && defined _AMD64_
1821+ /* avoid bad optimization with f1 -= f2 for f1:-0.0, f2:0.0 */
1822+ volatile
1823+#endif
18201824 long double f1, f2;
18211825
18221826 v1 = vtop - 1;
@@ -3497,7 +3501,7 @@ static void struct_decl(CType *type, AttributeDef *ad, int u) · 1674 unmodified lines
34973501 if (v < TOK_IDENT)
34983502 expect("struct/union/enum name");
34993503 s = struct_find(v);
3500− if (s && (s->scope == local_scope || (tok != '{' && tok != ';'))) {
3504+ if (s && (s->scope == local_scope || tok != '{')) {
35013505 if (s->type.t != a)
35023506 tcc_error("redefinition of '%s'", get_tok_str(v, NULL));
35033507 goto do_decl;
@@ -4381,6 +4385,8 @@ ST_FUNC void unary(void) · 877 unmodified lines
43814385 case TOK_STR:
43824386 /* string parsing */
43834387 t = VT_BYTE;
4388+ if (tcc_state->char_is_unsigned)
4389+ t = VT_BYTE | VT_UNSIGNED;
43844390 str_init:
43854391 if (tcc_state->warn_write_strings)
43864392 t |= VT_CONSTANT;
tccpe.c+18−19
@@ -1547,11 +1547,7 @@ PUB_FUNC int tcc_get_dllexports(const char *filename, char **pp) · 1546 unmodified lines
15471547 IMAGE_DOS_HEADER dh;
15481548 IMAGE_FILE_HEADER ih;
15491549 DWORD sig, ref, addr, ptr, namep;
1550−#ifdef TCC_TARGET_X86_64
1551− IMAGE_OPTIONAL_HEADER64 oh;
1552−#else
1553− IMAGE_OPTIONAL_HEADER32 oh;
1554−#endif
1550+
15551551 int pef_hdroffset, opt_hdroffset, sec_hdroffset;
15561552
15571553 n = n0 = 0;
@@ -1562,7 +1558,6 @@ PUB_FUNC int tcc_get_dllexports(const char *filename, char **pp) · 4 unmodified lines
15621558 if (fd < 0)
15631559 goto the_end_1;
15641560 ret = 1;
1565−
15661561 if (!read_mem(fd, 0, &dh, sizeof dh))
15671562 goto the_end;
15681563 if (!read_mem(fd, dh.e_lfanew, &sig, sizeof sig))
@@ -1572,22 +1567,26 @@ PUB_FUNC int tcc_get_dllexports(const char *filename, char **pp) · 3 unmodified lines
15721567 pef_hdroffset = dh.e_lfanew + sizeof sig;
15731568 if (!read_mem(fd, pef_hdroffset, &ih, sizeof ih))
15741569 goto the_end;
1575− if (IMAGE_FILE_MACHINE != ih.Machine) {
1576− if (ih.Machine == 0x014C)
1577− ret = 32;
1578− else if (ih.Machine == 0x8664)
1579− ret = 64;
1580− goto the_end;
1581− }
15821570 opt_hdroffset = pef_hdroffset + sizeof ih;
1583− sec_hdroffset = opt_hdroffset + sizeof oh;
1584− if (!read_mem(fd, opt_hdroffset, &oh, sizeof oh))
1571+ if (ih.Machine == 0x014C) {
1572+ IMAGE_OPTIONAL_HEADER32 oh;
1573+ sec_hdroffset = opt_hdroffset + sizeof oh;
1574+ if (!read_mem(fd, opt_hdroffset, &oh, sizeof oh))
1575+ goto the_end;
1576+ if (IMAGE_DIRECTORY_ENTRY_EXPORT >= oh.NumberOfRvaAndSizes)
1577+ goto the_end_0;
1578+ addr = oh.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
1579+ } else if (ih.Machine == 0x8664) {
1580+ IMAGE_OPTIONAL_HEADER64 oh;
1581+ sec_hdroffset = opt_hdroffset + sizeof oh;
1582+ if (!read_mem(fd, opt_hdroffset, &oh, sizeof oh))
1583+ goto the_end;
1584+ if (IMAGE_DIRECTORY_ENTRY_EXPORT >= oh.NumberOfRvaAndSizes)
1585+ goto the_end_0;
1586+ addr = oh.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
1587+ } else
15851588 goto the_end;
15861589
1587− if (IMAGE_DIRECTORY_ENTRY_EXPORT >= oh.NumberOfRvaAndSizes)
1588− goto the_end_0;
1589−
1590− addr = oh.DataDirectory[IMAGE_DIRECTORY_ENTRY_EXPORT].VirtualAddress;
15911590 //printf("addr: %08x\n", addr);
15921591 for (i = 0; i < ih.NumberOfSections; ++i) {
15931592 if (!read_mem(fd, sec_hdroffset + i * sizeof ish, &ish, sizeof ish))
tccpp.c+7−4
@@ -531,7 +531,6 @@ ST_FUNC const char *get_tok_str(int v, CValue *cv) · 530 unmodified lines
531531 break;
532532
533533 /* above tokens have value, the ones below don't */
534−
535534 case TOK_LT:
536535 v = '<';
537536 goto addv;
@@ -544,6 +543,8 @@ ST_FUNC const char *get_tok_str(int v, CValue *cv) · 6 unmodified lines
544543 return strcpy(p, "<<=");
545544 case TOK_A_SAR:
546545 return strcpy(p, ">>=");
546+ case TOK_EOF:
547+ return strcpy(p, "<eof>");
547548 default:
548549 if (v < TOK_IDENT) {
549550 /* search in two bytes table */
@@ -1791,7 +1792,7 @@ ST_FUNC void preprocess(int is_bof) · 1241 unmodified lines
17911792 if (c != '\"')
17921793 continue;
17931794 /* https://savannah.nongnu.org/bugs/index.php?50847 */
1794− path = file->filename2;
1795+ path = file->true_filename;
17951796 pstrncpy(buf1, path, tcc_basename(path) - path);
17961797
17971798 } else {
@@ -1921,9 +1922,11 @@ include_done: · 123 unmodified lines
19211922 _line_num:
19221923 next();
19231924 if (tok != TOK_LINEFEED) {
1924− if (tok == TOK_STR)
1925+ if (tok == TOK_STR) {
1926+ if (file->true_filename == file->filename)
1927+ file->true_filename = tcc_strdup(file->filename);
19251928 pstrcpy(file->filename, sizeof(file->filename), (char *)tokc.str.data);
1926− else if (parse_flags & PARSE_FLAG_ASM_FILE)
1929+ } else if (parse_flags & PARSE_FLAG_ASM_FILE)
19271930 break;
19281931 else
19291932 goto _line_err;
tcctools.c+1−2
@@ -363,9 +363,8 @@ usage: · 362 unmodified lines
363363 ret = tcc_get_dllexports(file, &p);
364364 if (ret || !p) {
365365 fprintf(stderr, "tcc: impdef: %s '%s'\n",
366− ret == 32 ? "can't read symbols from 32bit" :
367− ret == 64 ? "can't read symbols from 64bit" :
368366 ret == -1 ? "can't find file" :
367+ ret == 1 ? "can't read symbols" :
369368 ret == 0 ? "no symbols found in" :
370369 "unknown file type", file);
371370 ret = 1;
x86_64-gen.c+27−8
@@ -728,13 +728,13 @@ static int arg_prepare_reg(int idx) { · 727 unmodified lines
728728 return arg_regs[idx];
729729 }
730730
731−static int func_scratch;
731+static int func_scratch, func_alloca;
732732
733733 /* Generate function call. The function address is pushed first, then
734734 all the parameters in call order. This functions pops all the
735735 parameters and the function address. */
736736
737−void gen_offs_sp(int b, int r, int d)
737+static void gen_offs_sp(int b, int r, int d)
738738 {
739739 orex(1,0,r & 0x100 ? 0 : r, b);
740740 if (d == (char)d) {
@@ -746,6 +746,11 @@ void gen_offs_sp(int b, int r, int d) · 5 unmodified lines
746746 }
747747 }
748748
749+static int using_regs(int size)
750+{
751+ return !(size > 8 || (size & (size - 1)));
752+}
753+
749754 /* Return the number of registers needed to return the struct, or 0 if
750755 returning via struct pointer. */
751756 ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *ret_align, int *regsize)
@@ -754,7 +759,7 @@ ST_FUNC int gfunc_sret(CType *vt, int variadic, CType *ret, int *ret_align, int · 2 unmodified lines
754759 *ret_align = 1; // Never have to re-align return values for x86-64
755760 *regsize = 8;
756761 size = type_size(vt, &align);
757− if (size > 8 || (size & (size - 1)))
762+ if (!using_regs(size))
758763 return 0;
759764 if (size == 8)
760765 ret->t = VT_LLONG;
@@ -774,7 +779,7 @@ static int is_sse_float(int t) { · 13 unmodified lines
774779 return bt == VT_DOUBLE || bt == VT_FLOAT;
775780 }
776781
777−int gfunc_arg_size(CType *type) {
782+static int gfunc_arg_size(CType *type) {
778783 int align;
779784 if (type->t & (VT_ARRAY|VT_BITFIELD))
780785 return 8;
@@ -801,7 +806,7 @@ void gfunc_call(int nb_args) · 20 unmodified lines
801806 bt = (sv->type.t & VT_BTYPE);
802807 size = gfunc_arg_size(&sv->type);
803808
804− if (size <= 8)
809+ if (using_regs(size))
805810 continue; /* arguments smaller than 8 bytes passed in registers or on stack */
806811
807812 if (bt == VT_STRUCT) {
@@ -835,7 +840,7 @@ void gfunc_call(int nb_args) · 27 unmodified lines
835840 bt = (vtop->type.t & VT_BTYPE);
836841
837842 size = gfunc_arg_size(&vtop->type);
838− if (size > 8) {
843+ if (!using_regs(size)) {
839844 /* align to stack align size */
840845 size = (size + 15) & ~15;
841846 if (arg >= REGN) {
@@ -895,6 +900,12 @@ void gfunc_call(int nb_args) · 53 unmodified lines
895900 }
896901
897902 gcall_or_jmp(0);
903+
904+ if ((vtop->r & VT_SYM) && vtop->sym->v == TOK_alloca) {
905+ /* need to add the "func_scratch" area after alloca */
906+ o(0x0548), gen_le32(func_alloca), func_alloca = ind - 4;
907+ }
908+
898909 /* other compilers don't clear the upper bits when returning char/short */
899910 bt = vtop->type.ref->type.t & (VT_BTYPE | VT_UNSIGNED);
900911 if (bt == (VT_BYTE | VT_UNSIGNED))
@@ -926,6 +937,7 @@ void gfunc_prolog(CType *func_type) · 25 unmodified lines
926937
927938 func_ret_sub = 0;
928939 func_scratch = 0;
940+ func_alloca = 0;
929941 loc = 0;
930942
931943 addr = PTR_SIZE * 2;
@@ -940,7 +952,7 @@ void gfunc_prolog(CType *func_type) · 8 unmodified lines
940952 func_vt = sym->type;
941953 func_var = (sym->c == FUNC_ELLIPSIS);
942954 size = gfunc_arg_size(&func_vt);
943− if (size > 8) {
955+ if (!using_regs(size)) {
944956 gen_modrm64(0x89, arg_regs[reg_param_index], VT_LOCAL, NULL, addr);
945957 func_vc = addr;
946958 reg_param_index++;
@@ -952,7 +964,7 @@ void gfunc_prolog(CType *func_type) · 5 unmodified lines
952964 type = &sym->type;
953965 bt = type->t & VT_BTYPE;
954966 size = gfunc_arg_size(type);
955− if (size > 8) {
967+ if (!using_regs(size)) {
956968 if (reg_param_index < REGN) {
957969 gen_modrm64(0x89, arg_regs[reg_param_index], VT_LOCAL, NULL, addr);
958970 }
@@ -1015,6 +1027,13 @@ void gfunc_epilog(void) · 56 unmodified lines
10151027 gen_le32(v);
10161028 }
10171029
1030+ /* add the "func_scratch" area after each alloca seen */
1031+ while (func_alloca) {
1032+ unsigned char *ptr = cur_text_section->data + func_alloca;
1033+ func_alloca = read32le(ptr);
1034+ write32le(ptr, func_scratch);
1035+ }
1036+
10181037 cur_text_section->data_offset = saved_ind;
10191038 pe_add_unwind_data(ind, saved_ind, v);
10201039 ind = cur_text_section->data_offset;

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