Opened 3 years ago

Closed 11 months ago

#808 closed defect (fixed)

msys64 CPPFLAGS=-D_FORTIFY_SOURCE=[2,1] did not build

Reported by: xpbxf4 Owned by: Olly Betts
Priority: normal Milestone: 1.4.23
Component: Build system Version: 1.4.18
Severity: normal Keywords: gcc FORTIFY
Cc: Blocked By:
Blocking: Operating System: Microsoft Windows

Description

Hello, I have just started using Windows and installed msys2 to get some unix programs I want working. I am trying to build xapian-core to see if I can build mu. This page suggest FORTIFY might be an issue,

https://github.com/msys2/MINGW-packages/issues/5868

so I tried 1 and 0. 0 seems to have built without error, while 1 gave similar errors (I think, I didn't cut and paste that one.) The INSTALL file says to submit a bug if D_FORTIFY_SOURCE=2 is changed to 1 or 0 to solve problems. When I use 1 or 2, I get errors like this (I hope this formatting is alright.):

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: backends/chert/.libs/chert_btreebase.o:C:/msys64/mingw64/x86_64-w64-mingw32/include/string.h:214: undefined reference to `__memmove_chk'

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: backends/chert/.libs/chert_compact.o:C:/msys64/mingw64/x86_64-w64-mingw32/include/stdio.h:372: undefined reference to `__chk_fail'

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: backends/glass/.libs/glass_changes.o:C:/msys64/mingw64/x86_64-w64-mingw32/include/string.h:214: undefined reference to `__memmove_chk'

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: backends/glass/.libs/glass_compact.o:C:/msys64/mingw64/x86_64-w64-mingw32/include/stdio.h:372: undefined reference to `__chk_fail'

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: net/.libs/progclient.o:C:/msys64/mingw64/x86_64-w64-mingw32/include/stdio.h:372: undefined reference to `__chk_fail'

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: net/.libs/remoteconnection.o:C:/msys64/mingw64/x86_64-w64-mingw32/include/string.h:202: undefined reference to `__memcpy_chk'

C:/msys64/mingw64/bin/../lib/gcc/x86_64-w64-mingw32/10.2.0/../../../../x86_64-w64-mingw32/bin/ld.exe: unicode/.libs/description_append.o:C:/msys64/mingw64/x86_64-w64-mingw32/include/stdio.h:372: undefined reference to `__chk_fail'

collect2.exe: error: ld returned 1 exit status
make[2]: *** [Makefile:2230: libxapian.la] Error 1
make[2]: Leaving directory '/c/Users/olbxf/src/xapian-core-1.4.18'
make[1]: *** [Makefile:3278: all-recursive] Error 1
make[1]: Leaving directory '/c/Users/olbxf/src/xapian-core-1.4.18'
make: *** [Makefile:1581: all] Error 2

My msys2 is fully up to date, but I am just learning this system, so I could have missed something. Feel free to close if this is not real. Thank you for developing xapian!

Change History (7)

comment:1 by xpbxf4, 3 years ago

Trying again, but linking to libssp:

./configure LIBS=-lssp

That same thread above indicates this might fix it. Apologies if that's all I needed.

comment:2 by xpbxf4, 3 years ago

Resolution: fixed
Status: newclosed

That appears to have fixed it. Sorry to clutter your bug tracking.

comment:3 by Olly Betts, 3 years ago

Component: OtherBuild system
Milestone: 1.4.19
Resolution: fixed
Status: closedreopened

The build should really work out of the box if possible, without the user working out what additional compiler options they need. Or if that's too hard we should at least document additional options and when and where they may be needed.

It seems there are essentially the two options you identified - don't use _FORTIFY_SOURCE on mingw-w64 or automatically add -lssp to the linked libraries if it's required. Keeping _FORTIFY_SOURCE on is nice, but it's not really a must and having to probe for required libraries may be a bit fiddly. I'll take a look.

comment:4 by Olly Betts, 3 years ago

Fixed in git master by 8c417d1ff062fd24eaf6d588ddca9b993d3c4ae7.

Needs backporting for 1.4.19.

comment:5 by Olly Betts, 3 years ago

Resolution: fixed
Status: reopenedclosed

comment:6 by Olly Betts, 12 months ago

Milestone: 1.4.191.4.23
Resolution: fixed
Status: closedreopened

I discovered that fix doesn't actually work because config.status unhelpfully comments out #undef _FORTIFY_SOURCE when generating config.h from config.h.in. We already work around this in other cases by splitting the line so I've done the same in 0e1eb61f62e1c242e7f9dafb72e9ceb06eb45438 which I'll backport for 1.4.23.

comment:7 by Olly Betts, 11 months ago

Resolution: fixed
Status: reopenedclosed

Backported that as 08142926809a4baa31dc5c9a357093efc7e9a45c.

However I then found this doesn't work as intended either.

The problem is that including a header to check if we're on mingw-w64 results in processing the current _FORTIFY_SOURCE setting, and we can't then usefully change it based on whether we're on mingw-w64 or not.

I've pushed a change to just not auto-enabling _FORTIFY_SOURCE on mingw or mingw-w64. It doesn't work on the latter without -lssp, and I can't find evidence it's even supported on the former anyway. If it is, enabling manually will still work.

That's 424f7b33a00bb41b6b05056a8a9c8a4bdee38b1d, backported as 85b67415ce2f076b684c91112fddcf522c615efb.

Note: See TracTickets for help on using tickets.