Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 920234

Summary: dev-libs/nettle-3.9.1[asm] - test failures (chacha, chacha-poly1305) and runtime failures (e.g. wget[19849]: illegal instruction (4) at 3fff882c2754 nip 3fff882c2754 lr 3fff882c24e8 code 1 in libnettle.so.8.8) on machines with less than POWER7 cpu
Product: Gentoo Linux Reporter: ernsteiswuerfel <erhard_f>
Component: Current packagesAssignee: Gentoo's Team for Core System packages <base-system>
Status: RESOLVED FIXED    
Severity: normal CC: erhard_f, ppc64, sam
Priority: Normal Keywords: TESTFAILURE
Version: unspecified   
Hardware: PPC64   
OS: Linux   
See Also: https://git.lysator.liu.se/nettle/nettle/-/issues/7
https://bugs.gentoo.org/show_bug.cgi?id=935410
Whiteboard:
Package list:
Runtime testing required: ---
Attachments: build.log
emerge --info

Description ernsteiswuerfel archtester 2023-12-18 01:13:13 UTC
Created attachment 879767 [details]
build.log

I experienced runtime failures on my PowerMac G5 like these:

 # eselect repository list
--2023-12-18 01:25:27--  https://qa-reports.gentoo.org/output/repos/repositories.xml
Resolving qa-reports.gentoo.org... 146.75.121.91, 2a04:4e42:8e::347
Connecting to qa-reports.gentoo.org|146.75.121.91|:443... connected.
/usr/share/eselect/modules/repository.eselect: line 45: 19849 Illegal instruction     wget -N -P "${REMOTE_LIST_CACHEDIR}" "${REMOTE_LIST_URI}"
!!! Error: unable to fetch repositories.xml

dmesg showing:
wget[19849]: illegal instruction (4) at 3fff882c2754 nip 3fff882c2754 lr 3fff882c24e8 code 1 in libnettle.so.8.8[3fff882a6000+6e000]
wget[19849]: code: 3842b5e0 38c00010 38e00020 39000030 1090038c 10ac038c 10c8038c 10e7038c 
wget[19849]: code: 39200000 7d89480c 11a3030c 118c6cc4 <7c002619> 7c262619 7c472619 7c682619


So I took a closer look on dev-libs/nettle-3.9.1. It builds just fine on the G5 but when additionally running FEATURES="test" the problem becomes more obvious. It seems to use >=POWER7 assembly on my G5 (POWER4 + Altivec) which can't work.

[...]
configure: summary of build options:

  Version:           nettle 3.9.1
  Host type:         powerpc64-gentoo-linux-musl
  ABI:               64
  Assembly files:    powerpc64/p7 powerpc64
  Install prefix:    /usr
  Library directory: /usr/lib
  Compiler:          powerpc64-gentoo-linux-musl-gcc
  Static libraries:  no
  Shared libraries:  yes
  Public key crypto: yes
  Using mini-gmp:    no
  Documentation:     no

>>> Source configured.
>>> Compiling source in /var/tmp/portage/dev-libs/nettle-3.9.1/work/nettle-3.9.1 ...
 * .ppc64: running multilib-minimal_abi_src_compile
make -j3 -l2 
make all-here
[...]
PASS: aes
PASS: aes-keywrap
PASS: arcfour
PASS: arctwo
PASS: balloon
PASS: blowfish
PASS: bcrypt
PASS: cast128
PASS: base16
PASS: base64
PASS: camellia
Illegal instruction
FAIL: chacha
[...]
PASS: poly1305
Illegal instruction
FAIL: chacha-poly1305
[...]
PASS: nettle-pbkdf2
powerpc64-gentoo-linux-musl-nm: '../libnettle.a': No such file
powerpc64-gentoo-linux-musl-nm: '../libnettle.a': No such file
PASS: symbols
PASS: dlopen
=====================
2 of 117 tests failed
=====================
make[1]: *** [Makefile:126: check] Error 1
make[1]: Leaving directory '/var/tmp/portage/dev-libs/nettle-3.9.1/work/nettle-3.9.1-.ppc64/testsuite'
make: *** [Makefile:48: check] Error 2
 * ERROR: dev-libs/nettle-3.9.1::gentoo failed (test phase):
 *   Make check failed. See above for details.
Comment 1 ernsteiswuerfel archtester 2023-12-18 01:14:34 UTC
Created attachment 879768 [details]
emerge --info
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-12-18 06:54:53 UTC
Yeah, in https://git.lysator.liu.se/nettle/nettle/-/tree/master/powerpc64, the minimum is p7.

Upstream need to add a configure check to bail out / disable asm on <p7.

On our side, it's maybe a bit more intesting about how we should handle (detect) it. Unfortunately the CHOST isn't enough.
Comment 3 ernsteiswuerfel archtester 2023-12-18 21:20:59 UTC
I did some testing with upstream nettle from git. Turns out the >=P7 assembly problem only shows up on the G5 as long as --disable-fat is set in ./configure.

I mimicked configure options from the failing nettle-3.9.1 Gentoo ebuild and used them on git nettle_3.9.1_release_20230601 but without --disable-fat:

./.bootstrap
./configure --disable-dependency-tracking CC_FOR_BUILD=powerpc64-unknown-linux-gnu-gcc --disable-arm-neon --disable-arm64-crypto --enable-power-altivec --disable-power-crypto-ext --disable-power9 --disable-x86-aesni --disable-x86-sha-ni --disable-x86-pclmul --disable-s390x-vf --disable-s390x-msa --enable-assembler --disable-documentation --enable-public-key --enable-static --disable-openssl
make -j3
make -j3 check

This builds ok and passes tests on my G5 without throwing up illegal instructions.

When --disable-fat is set in ./configure I get:

chacha-test[232102]: illegal instruction (4) at 3fffa56ef714 nip 3fffa56ef714 lr 3fffa56cb604 code 1 in libnettle.so[3fffa56b0000+5a000]
chacha-test[232102]: code: 38c00010 38e00020 39000030 3941ffc0 7e8051ce 7ea651ce 7ec751ce 7ee851ce 
chacha-test[232102]: code: 1210038c 122c038c 1248038c 1267038c <7c002619> 7c862619 7d072619 7d882619 
chacha-poly1305[232473]: illegal instruction (4) at 3fffa0b9b90c nip 3fffa0b9b90c lr 3fffa0b9ba60 code 1 in libnettle.so[3fffa0b80000+5a000]
chacha-poly1305[232473]: code: 80050000 38c00010 38e00020 39000030 1090038c 10ac038c 10c8038c 10e7038c 
chacha-poly1305[232473]: code: 39200000 7d89480c 11a3030c 118c6cc4 <7c002619> 7c262619 7c472619 7c682619
Comment 4 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-06-24 00:55:15 UTC
OK, so, coming back to this:

    *powerpc64*)
      if test "$ABI" = 64 ; then
	GMP_ASM_POWERPC_R_REGISTERS
	asm_path="powerpc64"
	if test "x$enable_fat" = xyes ; then
	  asm_path="powerpc64/fat $asm_path"
	  OPT_NETTLE_SOURCES="fat-ppc.c $OPT_NETTLE_SOURCES"
	  FAT_TEST_LIST="none crypto_ext altivec power9"
	else
	  if test "$enable_power9" = yes ; then
	    asm_path="powerpc64/p9 $asm_path"
	  fi
    if test "$enable_power_crypto_ext" = yes ; then
            asm_path="powerpc64/p8 $asm_path"
	  fi
	  if test "$enable_power_altivec" = yes ; then
	    asm_path="powerpc64/p7 $asm_path"
	  fi
	fi
      fi
      ;;

On our end, I guess we can do a compile-test to see if we're at least P7, and if not, we disable the altivec flag. meh.

I would file a bug on their gitlab but it's invite-only.
Comment 5 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-06-24 00:57:28 UTC
(In reply to Sam James from comment #4)
> 
> I would file a bug on their gitlab but it's invite-only.

Ah, wait, it's not anymore! https://lists.lysator.liu.se/mailman/hyperkitty/list/nettle-bugs@lists.lysator.liu.se/thread/GJF2Q72MHYLLKV63O7GCUSVZUAWBXT6X/
Comment 6 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-06-24 01:07:32 UTC
Filed https://git.lysator.liu.se/nettle/nettle/-/issues/7.
Comment 7 Larry the Git Cow gentoo-dev 2024-06-24 01:16:15 UTC
The bug has been closed via the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=4551df6ec5cae19486cb63698e294a3f62015600

commit 4551df6ec5cae19486cb63698e294a3f62015600
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2024-06-24 01:13:55 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2024-06-24 01:15:21 +0000

    dev-libs/nettle: disable altivec for <P7
    
    Thanks to awilfox for the help with ppc cpp.
    
    Closes: https://bugs.gentoo.org/920234
    Signed-off-by: Sam James <sam@gentoo.org>

 dev-libs/nettle/{nettle-3.9.ebuild => nettle-3.9-r1.ebuild}     | 9 ++++++++-
 dev-libs/nettle/{nettle-3.9.1.ebuild => nettle-3.9.1-r1.ebuild} | 9 ++++++++-
 2 files changed, 16 insertions(+), 2 deletions(-)
Comment 8 ernsteiswuerfel archtester 2024-06-24 18:00:01 UTC
Many thanks!

Seems the patch is also needed for just released 3.10.
Comment 9 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2024-06-24 18:04:34 UTC
(In reply to ernsteiswuerfel from comment #8)
> Many thanks!
> 
> Seems the patch is also needed for just released 3.10.

yw!

I added the workaround there, right? (I did the bump after.)
Comment 10 ernsteiswuerfel archtester 2024-06-24 19:10:04 UTC
(In reply to Sam James from comment #9)
> (In reply to ernsteiswuerfel from comment #8)
> > Many thanks!
> > 
> > Seems the patch is also needed for just released 3.10.
> 
> I added the workaround there, right? (I did the bump after.)
I built 3.10 from git, didn't even realize you already bumped Gentoo to 3.10. ;) And yes, works there too.
Comment 11 Larry the Git Cow gentoo-dev 2024-07-04 01:29:47 UTC
The bug has been referenced in the following commit(s):

https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=c627cc231796bf88ce7ef664986863d32de4a5a4

commit c627cc231796bf88ce7ef664986863d32de4a5a4
Author:     Sam James <sam@gentoo.org>
AuthorDate: 2024-07-04 01:28:37 +0000
Commit:     Sam James <sam@gentoo.org>
CommitDate: 2024-07-04 01:28:37 +0000

    dev-libs/nettle: fix quoting for altivec sanity check
    
    Bug: https://bugs.gentoo.org/920234
    Closes: https://bugs.gentoo.org/935410
    Fixes: 4551df6ec5cae19486cb63698e294a3f62015600
    Thanks-to: Nick Bowler <nbowler@draconx.ca>
    Signed-off-by: Sam James <sam@gentoo.org>

 dev-libs/nettle/nettle-3.10.ebuild     | 2 +-
 dev-libs/nettle/nettle-3.9.1-r1.ebuild | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)