See thread "win32: -Wl,-nostdlib: undefined symbol 'memset'" This patch has been tested on x86-64 Alpine (musl) and all tests are passed. I do not have a Windows platform, so many thanks if someone could help me test it.
--- tccgen.c | 5 +++++ x86_64-gen.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/tccgen.c b/tccgen.c index fd0680f..da07675 100644 --- a/tccgen.c +++ b/tccgen.c @@ -7373,6 +7373,10 @@ static void init_putz(init_params *p, unsigned long c, int size) if (p->sec) { /* nothing to do because globals are already set to zero */ } else { +#ifdef TCC_TARGET_NATIVE_PUT_ZERO + vseti(VT_LOCAL, c); + gen_put_zero(size); +#else vpush_helper_func(TOK_memset); vseti(VT_LOCAL, c); #ifdef TCC_TARGET_ARM @@ -7383,6 +7387,7 @@ static void init_putz(init_params *p, unsigned long c, int size) vpushs(size); #endif gfunc_call(3); +#endif } } diff --git a/x86_64-gen.c b/x86_64-gen.c index e04df10..fae6f54 100644 --- a/x86_64-gen.c +++ b/x86_64-gen.c @@ -109,7 +109,9 @@ enum { #define PROMOTE_RET #define TCC_TARGET_NATIVE_STRUCT_COPY +#define TCC_TARGET_NATIVE_PUT_ZERO ST_FUNC void gen_struct_copy(int size); +ST_FUNC void gen_put_zero(int size); /******************************************************/ #else /* ! TARGET_DEFS_ONLY */ @@ -2325,6 +2327,42 @@ ST_FUNC void gen_struct_copy(int size) vpop(); } +ST_FUNC void gen_put_zero(int size) +{ + int n = size / PTR_SIZE; + +#ifdef TCC_TARGET_PE + o(0x57); /* push rdi */ +#endif + + vpushi(0); + gv2(RC_RDI, RC_RAX); + + if (n <= 4) { + for (; n; n--) + o(0xab48); + } else { + vpushi(n); + gv(RC_RCX); + o(0xab48f3); + vpop(); + } + + if (size & 0x04) + o(0xab); + if (size & 0x02) + o(0xab66); + if (size & 0x01) + o(0xaa); + +#ifdef TCC_TARGET_PE + o(0x5f); /* pop rdi */ +#endif + + vpop(); + vpop(); +} + /* end of x86-64 code generator */ /*************************************************************/ #endif /* ! TARGET_DEFS_ONLY */ -- 2.42.0 _______________________________________________ Tinycc-devel mailing list Tinycc-devel@nongnu.org https://lists.nongnu.org/mailman/listinfo/tinycc-devel