I found the issue, it was the msvcrt, compiling with --nomsvcrt it works fine. There is some incompatible ABI call from libstdc++ to msvcrt that causes a segfault in malloc/free. I am not sure if is possible to fix, since it will require to change the calling convection inside libstdc++