[Mingw-users] undefined reference to `__chkstk_ms'

Back to archive index
Keith Marshall keith****@users*****
Tue May 28 00:04:10 JST 2019


On 27/05/19 09:05, Rastislav Stanik wrote:
> I've hit a problem when compiling my project with
> gcc --version
> gcc (x86_64-win32-sjlj-rev0, Built by MinGW-W64 project) 8.1.0

First, let's make it completely clear: this compiler originates from a
third party project which illegally uses our registered trademark,
without our authorization; it is NOT a MinGW product, and is not
supported here.

> I'm trying to build a 32-bit (using -m32) shared library that uses
> PCRE (Perl Compatible Regular Expressions library) compiled by myself
> using the same compiler. At linking stage I get a report about
> missing symbol __chkstk_ms:
> 
> {MinGW-root}/bin/../lib/gcc/x86_64-w64-mingw32/8.1.0/../../../../x86_64-w64-mingw32/lib/../lib32/libmingw32.a(lib32_libmingw32_a-pseudo-reloc.o):pseudo-reloc.c:(.text+0x18d):
> undefined reference to `__chkstk_ms'
> 
> Reference to __chkstk_ms() is added by compiler when some function
> declares local variables exceeding page size (~4k).

Amongst other reasons.

> In my case the function that exceeds the limit is in PRCE, so I
> cannot simply work around it in my code. The function __chkstk_ms()
> is provided by libgcc.a located in directory
> 
>   {MinGW-root}/lib/gcc/x86_64-w64-mingw32/8.1.0/32/
> 
> So if I add linking of that libgcc.a then the linking stage succeeds.
> But I also have to ensure that libgcc.a is in link search path.
> 
> Questions:
> - why the compiler does not add libgcc.a by itself when it added
> __chkstk_ms() by itself?

Our distribution does exactly that; irrespective of whether or not
__chkstk_ms() is referenced, -lgcc is specified by default, and the
appropriate path is also specified.

> - if I add -lgcc, why do I also have to add path with -L? Shouldn't
> the directory be in the default linker search path? - is there a
> solution that will keep working after next release of MinGW/GCC when
> the path to libgcc changes?

You aren't using a genuine MinGW product, so who knows?  A possible
explanation could be that your build system is trying to invoke ld
directly, rather than letting gcc do the linking ... you don't show the
actual link command.  If you don't indulge in that misguided shortcut,
then this problem should not arise, with our GCC-8.2.0

-- 
Regards,
Keith.

Public key available from keys.gnupg.net
Key fingerprint: C19E C018 1547 DE50 E1D4 8F53 C0AD 36C6 347E 5A3F

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: OpenPGP digital signature
URL: <https://lists.osdn.me/mailman/archives/mingw-users/attachments/20190527/8a0c3ff6/attachment.sig>


More information about the MinGW-Users mailing list
Back to archive index