Bug 260078

Summary: security/gnutls fails to build
Product: Ports & Packages Reporter: Bjoern A. Zeeb <bz>
Component: Individual Port(s)Assignee: Tijl Coosemans <tijl>
Status: Closed FIXED    
Severity: Affects Only Me CC: bz, dim, mikael, toolchain
Priority: --- Flags: bugzilla: maintainer-feedback? (tijl)
Version: Latest   
Hardware: arm64   
OS: Any   

Description Bjoern A. Zeeb freebsd_committer freebsd_triage 2021-11-27 16:46:07 UTC
This is on a clean main world from last night; gnutls being built as dependency...

===>  Building for gnutls-3.6.16
Making all in gl
Making all in .
Making all in tests
Making all in .
Making all in lib
Making all in includes
Making all in x509
Making all in auth
Making all in ext
Making all in algorithms
Making all in extras
Making all in accelerated
Making all in aarch64
libtool: compile:  cc -Wa,-march=all -O2 -pipe -DLIBICONV_PLUG -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing -c elf/sha1-armv8.s  -fPIC -DPIC -o elf/.libs/sha1-armv8.o
PLEASE submit a bug report to https://bugs.freebsd.org/submit/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: cc -Wa,-march=all -O2 -pipe -DLIBICONV_PLUG -fstack-protector-strong -isystem /usr/local/include -fno-strict-aliasing -c elf/sha1-armv8.s -fPIC -DPIC -o elf/.libs/sha1-armv8.o
1.      Compilation construction
2.      Building compilation jobs
3.      Building compilation jobs
#0 0x00000000049e198c (/usr/bin/cc+0x49e198c)
#1 0x00000000049dfc8c (/usr/bin/cc+0x49dfc8c)
#2 0x00000000049e21b0 (/usr/bin/cc+0x49e21b0)
#3 0x00000000484060a0 (/lib/libthr.so.3+0x2a0a0)
Segmentation fault (core dumped)
gmake[9]: *** [Makefile:1775: elf/sha1-armv8.lo] Error 1
gmake[8]: *** [Makefile:1759: all-recursive] Error 1
gmake[7]: *** [Makefile:2372: all-recursive] Error 1
gmake[6]: *** [Makefile:1995: all] Error 2
gmake[5]: *** [Makefile:1765: all-recursive] Error 1
gmake[4]: *** [Makefile:1690: all] Error 2
*** Error code 1

Stop.
make[3]: stopped in /usr/ports/security/gnutls
*** Error code 1
Comment 1 Dimitry Andric freebsd_committer freebsd_triage 2021-11-28 12:08:30 UTC
I can reproduce this. The issue is that clang doesn't support "-Wa,-march=all" (at least for aarch64), but it segfaults on it instead of producing a more regular error message. I will take the segfault upstream, since that seems to be a case of dodgy command line parameter parsing.

But to work around this, you could attempt removing the -Wa,-march=all from the compilation command line, in ${WRKSRC}/lib/accelerated/aarch64/Makefile.am.
Comment 2 Bjoern A. Zeeb freebsd_committer freebsd_triage 2021-11-28 16:54:24 UTC
I can confirm that this change locally makes gnutls build for me.
It's probably not the proper way to fix this in ports.

Thanks a lot @dim for your quick diagnose and reply!

diff --git a/security/gnutls/Makefile b/security/gnutls/Makefile
index 1ed334f7ca95..cebb0d6016c3 100644
--- a/security/gnutls/Makefile
+++ b/security/gnutls/Makefile
@@ -17,7 +19,7 @@ LIB_DEPENDS=  libgmp.so:math/gmp \
                libunistring.so:devel/libunistring
 RUN_DEPENDS=   ${LOCALBASE}/share/certs/ca-root-nss.crt:security/ca_root_nss
 
-USES=          compiler:c11 cpe gmake iconv libtool localbase makeinfo \
+USES=          compiler:c11 cpe gmake iconv autoreconf libtool localbase makeinfo \
                pkgconfig tar:xz
 USE_LDCONFIG=  yes
 
diff --git a/security/gnutls/files/patch-aarch64-clang-fix-PR260078 b/security/gnutls/files/patch-aarch64-clang-fix-PR260078
new file mode 100644
index 000000000000..672c41da6065
--- /dev/null
+++ b/security/gnutls/files/patch-aarch64-clang-fix-PR260078
@@ -0,0 +1,11 @@
+--- lib/accelerated/aarch64/Makefile.am.orig   2021-04-19 07:28:28.000000000 +0000
++++ lib/accelerated/aarch64/Makefile.am        2021-11-28 16:02:10.613775000 +0000
+@@ -34,7 +34,7 @@ AM_CPPFLAGS += -I$(srcdir)/../../minitasn1
+ endif
+ 
+ #ensure that we have all aarch64 instruction sets enabled for the assembler
+-AM_CCASFLAGS = -Wa,-march=all
++#AM_CCASFLAGS = -Wa,-march=all
+ 
+ EXTRA_DIST = README
+
Comment 3 commit-hook freebsd_committer freebsd_triage 2021-11-28 20:23:06 UTC
A commit in branch main references this bug:

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

commit 7f765b2b68c15dae2d53461ed68e4516457ae496
Author:     Tijl Coosemans <tijl@FreeBSD.org>
AuthorDate: 2021-11-28 19:33:56 +0000
Commit:     Tijl Coosemans <tijl@FreeBSD.org>
CommitDate: 2021-11-28 20:21:54 +0000

    security/gnutls: Remove -Wa,-march=all for clang on aarch64

    PR:             260078

 security/gnutls/Makefile | 3 +++
 1 file changed, 3 insertions(+)
Comment 4 Dimitry Andric freebsd_committer freebsd_triage 2021-11-28 21:26:30 UTC
Fixed upstream in https://github.com/llvm/llvm-project/commit/df08b2fe8b35cb63dfb3b49738a3494b9b4e6f8e . I will pull this revision into our version, after it has baked for a while.
Comment 5 commit-hook freebsd_committer freebsd_triage 2021-12-05 17:56:25 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=a9cd5c30d64e213c537c76c2a261f7a222f348bf

commit a9cd5c30d64e213c537c76c2a261f7a222f348bf
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2021-12-05 17:54:13 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-12-05 17:54:13 +0000

    Apply fix for clang crashing on invalid -Wa,-march= values

    Merge commit df08b2fe8b35 from llvm git (by Dimitry Andric):

      [AArch64] Avoid crashing on invalid -Wa,-march= values

      As reported in https://bugs.freebsd.org/260078, the gnutls Makefiles
      pass -Wa,-march=all to compile a number of assembly files. Clang does
      not support this -march value, but because of a mistake in handling
      the arguments, an unitialized Arg pointer is dereferenced, which can
      cause a segfault.

      Work around this by adding a check if the local WaMArch variable is
      initialized, and if so, using its value in the diagnostic message.

      Reviewed By: tschuett

      Differential Revision: https://reviews.llvm.org/D114677

    PR:             260078
    Reported by:    bz
    MFC after:      3 days

 .../clang/lib/Driver/ToolChains/Arch/AArch64.cpp          | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2021-12-10 21:30:13 UTC
A commit in branch stable/13 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=e4bde9c969cc1d079403850e964d9548316968a1

commit e4bde9c969cc1d079403850e964d9548316968a1
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2021-12-05 17:54:13 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-12-10 21:28:56 +0000

    Apply fix for clang crashing on invalid -Wa,-march= values

    Merge commit df08b2fe8b35 from llvm git (by Dimitry Andric):

      [AArch64] Avoid crashing on invalid -Wa,-march= values

      As reported in https://bugs.freebsd.org/260078, the gnutls Makefiles
      pass -Wa,-march=all to compile a number of assembly files. Clang does
      not support this -march value, but because of a mistake in handling
      the arguments, an unitialized Arg pointer is dereferenced, which can
      cause a segfault.

      Work around this by adding a check if the local WaMArch variable is
      initialized, and if so, using its value in the diagnostic message.

      Reviewed By: tschuett

      Differential Revision: https://reviews.llvm.org/D114677

    PR:             260078
    Reported by:    bz
    MFC after:      3 days

    (cherry picked from commit a9cd5c30d64e213c537c76c2a261f7a222f348bf)

 .../clang/lib/Driver/ToolChains/Arch/AArch64.cpp          | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
Comment 7 commit-hook freebsd_committer freebsd_triage 2021-12-25 11:57:39 UTC
A commit in branch stable/12 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=367dea5f853f1193fd1cc722f85e132f323c22db

commit 367dea5f853f1193fd1cc722f85e132f323c22db
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2021-12-05 17:54:13 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-12-25 11:51:42 +0000

    Apply fix for clang crashing on invalid -Wa,-march= values

    Merge commit df08b2fe8b35 from llvm git (by Dimitry Andric):

      [AArch64] Avoid crashing on invalid -Wa,-march= values

      As reported in https://bugs.freebsd.org/260078, the gnutls Makefiles
      pass -Wa,-march=all to compile a number of assembly files. Clang does
      not support this -march value, but because of a mistake in handling
      the arguments, an unitialized Arg pointer is dereferenced, which can
      cause a segfault.

      Work around this by adding a check if the local WaMArch variable is
      initialized, and if so, using its value in the diagnostic message.

      Reviewed By: tschuett

      Differential Revision: https://reviews.llvm.org/D114677

    PR:             260078
    Reported by:    bz
    MFC after:      3 days

    (cherry picked from commit a9cd5c30d64e213c537c76c2a261f7a222f348bf)

 .../clang/lib/Driver/ToolChains/Arch/AArch64.cpp          | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)