I got the following error building libscrypt with MinGW-w64 7.0.0 under MSYS2:
d:/prog/winlibs32-9.2.0-7.0.0/mingw32/i686-w64-mingw32/include/string.h:228: undefined reference to `__strcpy_chk'
In the makefile the compiler flag -D_FORTIFY_SOURCE=2 was set.
Changing this to -D_FORTIFY_SOURCE=1 still gave the same error.
However after changing this to -D_FORTIFY_SOURCE=0 the build completed without errors.
This can be reproducred with the following commands:
wget -c https://github.com/technion/libscrypt/archive/v1.21.tar.gz
tar xfz v1.21.tar.gz
cd libscrypt-1.21
sed -e "s/-fstack-protector\|-fPIC\|-Wl,-z,now\|-Wl,-z,relro\|-lc//g; s/-Wl,-soname,\([a-z]*\)\.so\.[0-9]*/-s -Wl,--out-implib,\1.dll.a/; s/\.so\.[0-9]*/.dll/g; s/ln -s/echo SKIPPING &/g" Makefile > Makefile.mingw
make -f Makefile.mingw CC=gcc
This command fixes it:
sed -i.bak -e "s/\(-D_FORTIFY_SOURCE=\)2/\10/" Makefile.mingw
Thanks in advance for looking into this.
Seems similar to this post in the mailing list:
https://sourceforge.net/p/mingw-w64/mailman/message/36764708/
At the end of the thread there was a mention of a patch being pushed.
Was this not included in release 7.0.0 released at the following link?
http://sourceforge.net/projects/mingw-w64/files/mingw-w64/mingw-w64-release/
Why did you remove
-fstack-protector? In mingw-w64_FORTIFY_SOURCErequires either-lsspor-fstack-protectorto work.Because then I had other issues. If I leave it in I get:
Check your linker command line to make sure
-lsspexists (note it is a GCC library so it must exist unless your toolchain is broken). You probably have to add it inLDADDif you also have-nostdlib.With
-lsspI still getundefined reference to '__strcpy_chk'When using
-fstack-protector -lsspI get:d:/prog/winlibs64-9.2.0-7.0.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: sha256.o: in function 'libscrypt_SHA256_Final': R:\winlibs64-9.2.0-7.0.0\libscrypt-1.21/sha256.c:290: undefined reference to '__stack_chk_fail' d:/prog/winlibs64-9.2.0-7.0.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: sha256.o: in function 'libscrypt_HMAC_SHA256_Init': R:\winlibs64-9.2.0-7.0.0\libscrypt-1.21/sha256.c:326: undefined reference to '__stack_chk_fail' d:/prog/winlibs64-9.2.0-7.0.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: sha256.o: in function 'libscrypt_HMAC_SHA256_Final': R:\winlibs64-9.2.0-7.0.0\libscrypt-1.21/sha256.c:354: undefined reference to '__stack_chk_fail' d:/prog/winlibs64-9.2.0-7.0.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: sha256.o: in function 'libscrypt_PBKDF2_SHA256': R:\winlibs64-9.2.0-7.0.0\libscrypt-1.21/sha256.c:411: undefined reference to '__stack_chk_fail' d:/prog/winlibs64-9.2.0-7.0.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: sha256.o:sha256.c:(.rdata$.refptr.__stack_chk_guard[.refptr.__stack_chk_guard]+0x0): undefined reference to '__stack_chk_guard' d:/prog/winlibs64-9.2.0-7.0.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: crypto-scrypt-saltgen.o: in function 'libscrypt_salt_gen': R:\winlibs64-9.2.0-7.0.0\libscrypt-1.21/crypto-scrypt-saltgen.c:48: undefined reference to '__stack_chk_fail' d:/prog/winlibs64-9.2.0-7.0.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: crypto_scrypt-check.o: in function 'libscrypt_check': R:\winlibs64-9.2.0-7.0.0\libscrypt-1.21/crypto_scrypt-check.c:104: undefined reference to '__stack_chk_fail' d:/prog/winlibs64-9.2.0-7.0.0/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/9.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: crypto_scrypt-hash.o: in function 'libscrypt_hash': R:\winlibs64-9.2.0-7.0.0\libscrypt-1.21/crypto_scrypt-hash.c:44: undefined reference to '__stack_chk_fail'Note that
-nostdlibis not used.Please provide the full linker command line. The order of
-loptions is significant hence-lsspmust follow all .o files.When I add this to Makefile.mingw to make sure the compiler options is specified after the .o files:
this is the output:
No this is the recipe for
.ofiles. You must append-lsspto the recipe for the DLL.Just noticed building cairo (v1.16.0) with MinGW-w64 7.0.0 also fails with
undefined reference to '__strncat_chk'I did some more tests and figured out
-fstack-protectoris also needed when linking, not just when compiling.Several projects don't seem to configure their build systems like this (so for I found this to be true for libscrypt and cairo).
These libraries did build against MinGW-w64 6.0.0 with the same compiler (GCC 9.2).
What exactly changed?
Last edit: Brecht Sanders 2019-11-16
See https://github.com/msys2/MINGW-packages/issues/5803.
What will be done to solve this issue?
In the meantime I also noticed the following packages also won't build with MinGW-w64 7.0.0:
Some of these were mentioned in #5803.
So it' clearly breaking multiple builds that were working before (with MinGW-w64 6.0.0).
Last edit: Brecht Sanders 2019-11-20
The best suggestion would be tampering with GCC default libs and enfore
-lsspthere, but it looks so wrong to me, because for example on Linux if you need math functions you must link your program against-lmwhich GCC doesn't do by default (G++ adds it however). Probably we should have documented such requirements of_FORTIFY_SOURCEsomewhere.Could it be an option to always export the
__*_chkfunctions so these link errors can be avoided if any component in the link process needs them?No, because libssp is a GCC library which we don't provide.
I get that, but I'm still confused.
If I used the same GCC version with MinGW-w64 6.0.0 it worked, but with MinGW-w64 7.0.0 it's broken. If this new version broke it, why can't it be fixed there?
Isn't it a goal of MinGW-w64 to be able to compile sources for Windows with as little changes as possible to the source packages?
Okay. I will change my building recipes to work around the problem by linking with -lssp whenever needed.
In many cases adding this after the ./configure line works:
LIBS="-Wl,--as-needed -lssp"For example mono builds fine now after only adding this. On the other had gdb needed a lot more tweaking, but I got it to build in the end.
I have added this solution to the web page of my personal standalone build at: http://winlibs.com/.
You can go ahead and close this ticket.
For your reference, we have had
-fstack-protectorinLDFLAGSfor GDB which implies-lsspin MSYS2.I just found out GCC can be built with an option
--enable-default-ssp.I will try that and see if my entire package collection builds fine with a GCC built like that.
Thank you for reminding that thing to me. Now I am considering whether it is a good thing to have by default, as it introduces another DLL dependency in addition to libgcc and libstdc++.
I just wanted to let you know that I have built GCC 9.2.0 with
--enable-default-sspand used that to build a number of libraries. It appears however this does not resolve the problem, i.e. linking still requires-fstack-protectoror-lsspto resolve the undefined references.I presume you were using libtool to build dynamic libraries? Then unfortunately you have to add
sspin configure.ac usingAC_CHECK_LIB, as libtool performs autocratic (punning intended) linking so you might have to tell it to link against libssp explicitly.No, some projects were not using autoconf/libtool. That is why I was using libscrypt as an interesting case to reproduce ths problem.
The steps to reproduce are:
When using gcc built with
--enable-default-sspthis now results in undefined references to__stack_chk_guardand__stack_chk_fail, which is different than before.