openssl / openssl

TLS/SSL and crypto library
https://www.openssl.org
Apache License 2.0
25.81k stars 10.13k forks source link

Branch openssl-3.3 build fails on 32bit PowerPC linux-ppc #25364

Open dani-schmitt opened 2 months ago

dani-schmitt commented 2 months ago

Hello, I am trying to cross compile branch openssl3-3 for 32bit Linux PowerPC ( MPC5200B ) (openssl-3.0.14 runs fine)

Make fails with:

powerpc-linux-gcc -fPIC -Wa,--noexecstack -Wall -O3 -DOPENSSL_USE_NODELETE -DB_ENDIAN -DOPENSSL_PIC -DOPENSSLDIR="\"/tmp/openssltest/eldk-5.5.3\"" -DENGINESDIR="\"/tmp/openssltest/eldk-5.5.3/lib/engines-3\"" -DMODULESDIR="\"/tmp/openssltest/eldk-5.5.3/lib/ossl-modules\"" -DOPENSSL_BUILDING_OPENSSL -DNDEBUG -DOPENSSL_NO_HEARTBEATS -c -o crypto/aes/libcrypto-lib-aesp8-ppc.o crypto/aes/aesp8-ppc.s
crypto/aes/aesp8-ppc.s: Assembler messages:
crypto/aes/aesp8-ppc.s:2420: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:2430: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:2441: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:2452: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:2463: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:2474: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:2519: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:2536: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:2558: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:2575: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:2592: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:2616: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:3090: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:3100: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:3111: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:3122: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:3133: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:3144: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:3189: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:3206: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:3228: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:3245: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:3262: Error: unrecognized opcode: `vpermxor'
crypto/aes/aesp8-ppc.s:3286: Error: unrecognized opcode: `vpermxor'
make[1]: *** [Makefile:14084: crypto/aes/libcrypto-lib-aesp8-ppc.o] Error 1
make[1]: Leaving directory '/home/dani/src/openssl'
make: *** [Makefile:3611: build_sw] Error 2

Config dump:

Command line (with current working directory = .):

    /usr/bin/perl ./Configure shared -DOPENSSL_NO_HEARTBEATS no-ssl3 no-weak-ssl-ciphers no-idea no-threads --prefix=/tmp/openssltest/eldk-5.5.3 --openssldir=/tmp/openssltest/eldk-5.5.3 linux-ppc

Perl information:

    /usr/bin/perl
    5.26.1 for x86_64-linux-thread-multi

Enabled features:

    afalgeng
    apps
    argon2
    aria
    asm
    async
    atexit
    autoalginit
    autoerrinit
    autoload-config
    bf
    blake2
    bulk
    cached-fetch
    camellia
    capieng
    cast
    chacha
    cmac
    cmp
    cms
    comp
    ct
    deprecated
    des
    dgram
    dh
    docs
    dsa
    dso
    dtls
    dynamic-engine
    ec
    ec2m
    ecdh
    ecdsa
    ecx
    engine
    err
    filenames
    gost
    http
    legacy
    loadereng
    makedepend
    md4
    mdc2
    module
    multiblock
    nextprotoneg
    ocb
    ocsp
    padlockeng
    pic
    pinshared
    poly1305
    posix-io
    psk
    quic
    unstable-qlog
    rc2
    rc4
    rdrand
    rfc3779
    rmd160
    scrypt
    secure-memory
    seed
    shared
    siphash
    siv
    sm2
    sm2-precomp
    sm3
    sm4
    sock
    srp
    srtp
    sse2
    ssl
    ssl-trace
    static-engine
    stdio
    tests
    tls
    ts
    ui-console
    whirlpool
    tls1
    tls1-method
    tls1_1
    tls1_1-method
    tls1_2
    tls1_2-method
    tls1_3
    dtls1
    dtls1-method
    dtls1_2
    dtls1_2-method

Disabled features:

    acvp-tests          [cascade]        OPENSSL_NO_ACVP_TESTS
    asan                [default]        OPENSSL_NO_ASAN
    brotli              [default]        OPENSSL_NO_BROTLI
    brotli-dynamic      [default]        OPENSSL_NO_BROTLI_DYNAMIC
    buildtest-c++       [default]        
    winstore            [not-windows]    OPENSSL_NO_WINSTORE
    crypto-mdebug       [default]        OPENSSL_NO_CRYPTO_MDEBUG
    default-thread-pool [cascade]        OPENSSL_NO_DEFAULT_THREAD_POOL
    devcryptoeng        [default]        OPENSSL_NO_DEVCRYPTOENG
    ec_nistp_64_gcc_128 [default]        OPENSSL_NO_EC_NISTP_64_GCC_128
    egd                 [default]        OPENSSL_NO_EGD
    external-tests      [default]        OPENSSL_NO_EXTERNAL_TESTS
    fips                [default]        
    fips-securitychecks [cascade]        OPENSSL_NO_FIPS_SECURITYCHECKS
    fuzz-afl            [default]        OPENSSL_NO_FUZZ_AFL
    fuzz-libfuzzer      [default]        OPENSSL_NO_FUZZ_LIBFUZZER
    idea                [option]         OPENSSL_NO_IDEA (skip crypto/idea)
    ktls                [default]        OPENSSL_NO_KTLS
    md2                 [default]        OPENSSL_NO_MD2 (skip crypto/md2)
    msan                [default]        OPENSSL_NO_MSAN
    rc5                 [default]        OPENSSL_NO_RC5 (skip crypto/rc5)
    sctp                [default]        OPENSSL_NO_SCTP
    tfo                 [default]        OPENSSL_NO_TFO
    thread-pool         [cascade]        OPENSSL_NO_THREAD_POOL
    threads             [option]         
    trace               [default]        OPENSSL_NO_TRACE
    ubsan               [default]        OPENSSL_NO_UBSAN
    unit-test           [default]        OPENSSL_NO_UNIT_TEST
    uplink              [no uplink_arch] OPENSSL_NO_UPLINK
    weak-ssl-ciphers    [option]         OPENSSL_NO_WEAK_SSL_CIPHERS
    zlib                [default]        OPENSSL_NO_ZLIB
    zlib-dynamic        [default]        OPENSSL_NO_ZLIB_DYNAMIC
    zstd                [default]        OPENSSL_NO_ZSTD
    zstd-dynamic        [default]        OPENSSL_NO_ZSTD_DYNAMIC
    ssl3                [option]         OPENSSL_NO_SSL3
    ssl3-method         [default]        OPENSSL_NO_SSL3_METHOD

Config target attributes:

    AR => "ar",
    ARFLAGS => "qc",
    CC => "gcc",
    CFLAGS => "-Wall -O3",
    CXX => "g++",
    CXXFLAGS => "-Wall -O3",
    HASHBANGPERL => "/usr/bin/env perl",
    RANLIB => "ranlib",
    RC => "windres",
    asm_arch => "ppc32",
    bn_ops => "BN_LLONG RC4_CHAR",
    build_file => "Makefile",
    build_scheme => [ "unified", "unix" ],
    cflags => "",
    cppflags => "",
    cxxflags => "-std=c++11",
    defines => [ "OPENSSL_BUILDING_OPENSSL" ],
    disable => [  ],
    dso_ldflags => "-Wl,-z,defs",
    dso_scheme => "dlfcn",
    enable => [ "afalgeng" ],
    ex_libs => "-ldl",
    includes => [  ],
    lflags => "",
    lib_cflags => "",
    lib_cppflags => "-DOPENSSL_USE_NODELETE -DB_ENDIAN",
    lib_defines => [  ],
    module_cflags => "-fPIC",
    module_cxxflags => undef,
    module_ldflags => "-Wl,-znodelete -shared -Wl,-Bsymbolic",
    perl_platform => "Unix",
    perlasm_scheme => "linux32",
    shared_cflag => "-fPIC",
    shared_defflag => "-Wl,--version-script=",
    shared_defines => [  ],
    shared_ldflag => "-Wl,-znodelete -shared -Wl,-Bsymbolic",
    shared_rcflag => "",
    shared_sonameflag => "-Wl,-soname=",
    shared_target => "linux-shared",
    thread_defines => [  ],
    thread_scheme => "pthreads",
    unistd => "<unistd.h>",

Recorded environment:

    AR = 
    BUILDFILE = 
    CC = 
    CFLAGS = 
    CPPFLAGS = 
    CROSS_COMPILE = powerpc-linux-
    CXX = 
    CXXFLAGS = 
    HASHBANGPERL = 
    LDFLAGS = 
    LDLIBS = 
    OPENSSL_LOCAL_CONFIG_DIR = 
    PERL = 
    RANLIB = 
    RC = 
    RCFLAGS = 
    WINDRES = 
    __CNF_CFLAGS = 
    __CNF_CPPDEFINES = 
    __CNF_CPPFLAGS = 
    __CNF_CPPINCLUDES = 
    __CNF_CXXFLAGS = 
    __CNF_LDFLAGS = 
    __CNF_LDLIBS = 

Makevars:

    AR              = powerpc-linux-ar
    ARFLAGS         = qc
    ASFLAGS         = 
    CC              = powerpc-linux-gcc
    CFLAGS          = -Wall -O3
    CPPDEFINES      = OPENSSL_NO_HEARTBEATS
    CPPFLAGS        = 
    CPPINCLUDES     = 
    CROSS_COMPILE   = powerpc-linux-
    CXX             = powerpc-linux-g++
    CXXFLAGS        = -Wall -O3
    HASHBANGPERL    = /usr/bin/env perl
    LDFLAGS         = 
    LDLIBS          = 
    PERL            = /usr/bin/perl
    RANLIB          = powerpc-linux-ranlib
    RC              = powerpc-linux-windres
    RCFLAGS         = 

NOTE: These variables only represent the configuration view.  The build file
template may have processed these variables further, please have a look at the
build file for more exact data:
    Makefile

build file:

    Makefile

build file templates:

    Configurations/common0.tmpl
    Configurations/unix-Makefile.tmpl

openssl33_cfg_dump.txt

Based on https://github.com/openssl/openssl/commit/493ad484e9312b54d177d85e2f4aa0b636e708f0

I made a "brute-force" patch, which works for me, but I don't know how to "fine tune" this-

diff --git a/crypto/aes/build.info b/crypto/aes/build.info
index 43c600acf6..9d400a74b7 100644
--- a/crypto/aes/build.info
+++ b/crypto/aes/build.info
@@ -38,7 +38,7 @@ IF[{- !$disabled{asm} -}]
   $AESASM_parisc20_64=$AESASM_parisc11
   $AESDEF_parisc20_64=$AESDEF_parisc11

-  IF[{- $target{sys_id} ne "MACOSX" && $target{asm_arch} ne "ppc32" -}]
+  IF[{- $target{sys_id} ne "MACOSX" -}]
     $AESASM_ppc32=aes_core.c aes_cbc.c aes-ppc.s vpaes-ppc.s aesp8-ppc.s
   ELSE
     $AESASM_ppc32=aes_core.c aes_cbc.c aes-ppc.s vpaes-ppc.s
diff --git a/include/crypto/aes_platform.h b/include/crypto/aes_platform.h
index 4ae9f77633..65fd694a60 100644
--- a/include/crypto/aes_platform.h
+++ b/include/crypto/aes_platform.h
@@ -65,7 +65,7 @@ void AES_xts_decrypt(const unsigned char *inp, unsigned char *out, size_t len,
 #   ifdef VPAES_ASM
 #    define VPAES_CAPABLE (OPENSSL_ppccap_P & PPC_ALTIVEC)
 #   endif
-#   if !defined(OPENSSL_SYS_MACOSX) && !defined(OPENSSL_SYS_LINUX)
+#   if !defined(OPENSSL_SYS_MACOSX)
 #    define HWAES_CAPABLE  (OPENSSL_ppccap_P & PPC_CRYPTO207)
 #    define HWAES_set_encrypt_key aes_p8_set_encrypt_key
 #    define HWAES_set_decrypt_key aes_p8_set_decrypt_key
@@ -76,7 +76,7 @@ void AES_xts_decrypt(const unsigned char *inp, unsigned char *out, size_t len,
 #    define HWAES_xts_encrypt aes_p8_xts_encrypt
 #    define HWAES_xts_decrypt aes_p8_xts_decrypt
 #   endif /* OPENSSL_SYS_MACOSX */
-#   if !defined(OPENSSL_SYS_AIX) && !defined(OPENSSL_SYS_MACOSX) && !defined(OPENSSL_SYS_LINUX)
+#   if !defined(OPENSSL_SYS_AIX) && !defined(OPENSSL_SYS_MACOSX)
 #    define PPC_AES_GCM_CAPABLE (OPENSSL_ppccap_P & PPC_MADD300)
 #    define AES_GCM_ENC_BYTES 128
 #    define AES_GCM_DEC_BYTES 128
vdukhovni commented 1 month ago

Have you looked at: https://github.com/openssl/openssl/issues/22818 ?

dani-schmitt commented 1 month ago

Have you looked at: #22818 ?

Yes, my “bute force” fix is based on this. I am changing all asm_arch ppc32 builds and all Linux builds. Is there a way to make this better, more granular and merge it into the 3.3 branch?