Bug 257765 - databases/mongodb44: Fix crash on aarch64
Summary: databases/mongodb44: Fix crash on aarch64
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: arm64 Any
: --- Affects Some People
Assignee: Mikael Urankar
URL:
Keywords: crash, easy
Depends on:
Blocks:
 
Reported: 2021-08-11 10:26 UTC by Ronald Klop
Modified: 2021-08-28 13:44 UTC (History)
1 user (show)

See Also:
koobs: merge-quarterly-


Attachments
git diff (1.08 KB, patch)
2021-08-11 10:26 UTC, Ronald Klop
ronald-lists: maintainer-approval+
Details | Diff
git diff mongodb42 (1001 bytes, patch)
2021-08-27 21:26 UTC, Ronald Klop
ronald-lists: maintainer-approval+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ronald Klop 2021-08-11 10:26:32 UTC
Created attachment 227110 [details]
git diff

Hi,

As mentioned in a mail[1] this port build crashes on aarch64/14-current.

Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file /usr/local/poudriere/jails/main-arm64/usr/src/contrib/llvm-project/llvm/include/llvm/Support/Casting.h, line 269.

I want to try if disabling LTO fixes this. I can't test it locally. My RPI4 does not have enough memory to build with LTO anyway.
As the build crashes disabling LTO for aarch64/14 is no regression and we don't need a portrevision bump.

Plus I get portscout mails about new version 5.0.X which is already in databases/mongodb50. So limit the portscout check.

[1] https://lists.freebsd.org/archives/freebsd-ports/2021-August/000531.html
Comment 1 Ronald Klop 2021-08-11 20:43:11 UTC
By adding a lot of swap space to my RPI4 I succeeded in reproducing the assertion failure with LTO enabled. So I'm quite sure LTO is the cause of the issue.
Comment 2 Mikael Urankar freebsd_committer freebsd_triage 2021-08-17 17:02:27 UTC
Does it happen only with clang12?

These ports are also affected:
databases/mongodb42
databases/mongodb49
databases/mongodb50
Comment 3 Ronald Klop 2021-08-18 11:33:54 UTC
(In reply to Mikael Urankar from comment #2)
Yes, it only happens with clang12 on aarch64/arm64. We might also hardcode llvm11 in the port.

The other mongodb ports are also affected. I thought to first try to fix it for one, before expanding to the others. But YMMV.
BTW: mongodb49 is expired and will be removed soon.

In the meantime another issue arose in bug #257925 which prevents easy testing of this issue. So make sure scons is the right version before testing.
Comment 4 Ronald Klop 2021-08-18 11:36:11 UTC
No need to merge-quarterly. Arm64 does only build quarterlies on FreeBSD versions with clang11 or lower. So the issue does not occur there.
But it will not hurt and I'm ok with it either way.
Comment 5 Kubilay Kocak freebsd_committer freebsd_triage 2021-08-18 23:44:43 UTC
^Triage: Track explicit MFH: No (rather than unset)
Comment 6 Mikael Urankar freebsd_committer freebsd_triage 2021-08-20 12:36:26 UTC
(In reply to Ronald Klop from comment #3)
We should exclude LTO based on the compiler version not on the FreeBSD version.
I tried this but it doesn't work :(

.include <bsd.port.pre.mk>

.if ${ARCH} == aarch64 && ${COMPILER_TYPE} == clang && ${COMPILER_VERSION} == 120
OPTIONS_EXCLUDE=       LTO # Does not work with llvm12 on aarch64.
.endif


is it worth keeping LTO on aarch64? What are the benefits? Should we put a dep on llvm11 instead (it'll increase build time unfortunately)?
Comment 7 Mikael Urankar freebsd_committer freebsd_triage 2021-08-20 12:40:35 UTC
It's lame but we can use this:
.include <bsd.port.pre.mk>

.if ${ARCH} == aarch64 && ${COMPILER_TYPE} == clang && ${COMPILER_VERSION} == 120
# We can't use OPTIONS_EXCLUDE here :(
LTO_MAKE_ARGS=  --lto=off
.endif
Comment 8 Ronald Klop 2021-08-20 13:30:08 UTC
(In reply to Mikael Urankar from comment #6)
Hi,

I appreciate the effort you are putting into this, but I wouldn't make it too complicated to create something future proof. Possible YAGNI [1] :-)

If the next version of llvm/clang does work with LTO on aarch64 I'm happy to enable the LTO option again.

> is it worth keeping LTO on aarch64?
I understand the theoretical gain of LTO. I don't know if it gives a measurable profit. It was added via a request in bug #253421 and committed using the wrong PR number in ports r565315 (svn).

Regards,
Ronald.

[1] https://en.wikipedia.org/wiki/You_aren%27t_gonna_need_it
Comment 9 commit-hook freebsd_committer freebsd_triage 2021-08-27 12:26:32 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=ed95a0e1749ec562cdc347b87e2c0afead356c74

commit ed95a0e1749ec562cdc347b87e2c0afead356c74
Author:     Ronald Klop <ronald-lists@klop.ws>
AuthorDate: 2021-08-27 12:23:53 +0000
Commit:     Mikael Urankar <mikael@FreeBSD.org>
CommitDate: 2021-08-27 12:25:29 +0000

    databases/mongodb44: Fix crash on aarch64

      - Disable LTO on aarch64/14-current (clang12 is crashing)
      - Limit the portscout check to 4.4.x

    PR:             257765

 databases/mongodb44/Makefile | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
Comment 10 Mikael Urankar freebsd_committer freebsd_triage 2021-08-27 12:27:54 UTC
Do you have a patch for:
databases/mongodb42
databases/mongodb50

Thanks!
Comment 11 Ronald Klop 2021-08-27 20:39:39 UTC
(In reply to Mikael Urankar from comment #10)
Thanks a lot.
A fix for mongodb50 is in bug #257925.
I will try to come up with a patch for mongodb42 if time permits.
Comment 12 Ronald Klop 2021-08-27 21:26:06 UTC
Created attachment 227493 [details]
git diff mongodb42

Add a patch for mongodb42. Also fixes a portlint warning.
Comment 13 commit-hook freebsd_committer freebsd_triage 2021-08-28 13:43:20 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/ports/commit/?id=54df4eaababcbb48d982f6af70483c610e6f17b6

commit 54df4eaababcbb48d982f6af70483c610e6f17b6
Author:     Ronald Klop <ronald-lists@klop.ws>
AuthorDate: 2021-08-28 13:12:45 +0000
Commit:     Mikael Urankar <mikael@FreeBSD.org>
CommitDate: 2021-08-28 13:42:10 +0000

    databases/mongodb42: Fix crash on aarch64

    Disable LTO on aarch64/14-current (clang12 is crashing)

    PR:             257765

 databases/mongodb42/Makefile | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
Comment 14 Mikael Urankar freebsd_committer freebsd_triage 2021-08-28 13:44:27 UTC
Thanks!