Skip to content

Commit

Permalink
fix mips/mips64 builds
Browse files Browse the repository at this point in the history
  • Loading branch information
busterb committed Mar 23, 2023
1 parent 59261d0 commit 73d924f
Show file tree
Hide file tree
Showing 8 changed files with 327 additions and 44 deletions.
15 changes: 9 additions & 6 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,9 @@ AS_CASE([$host_cpu],
[arm64], [host_cpu=aarch64],
[*arm*], [host_cpu=arm],
[*amd64*], [host_cpu=x86_64 HOSTARCH=intel],
[i?86], [host_cpu=i386 HOSTARCH=intel],
[mipsel*], [host_cpu=mips],
[mips64el*], [host_cpu=mips64],
[i?86], [host_cpu=i386 HOSTARCH=intel enable_asm=no],
[mips64*], [host_cpu=mips64 enable_asm=no],
[mips*], [host_cpu=mips enable_asm=no],
[powerpc*], [host_cpu=powerpc],
[ppc64*], [host_cpu=powerpc64],
[x86_64], [HOSTARCH=intel]
Expand Down Expand Up @@ -109,13 +109,16 @@ int main() {return 0;}
AC_MSG_RESULT(no)
])

AC_ARG_ENABLE([asm],
AS_HELP_STRING([--disable-asm], [Disable assembly]))
AM_CONDITIONAL([OPENSSL_NO_ASM], [test "x$enable_asm" = "xno" -o "$host_cpu" = "i386"])
AC_ARG_ENABLE([asm], AS_HELP_STRING([--disable-asm], [Disable assembly]))
AM_CONDITIONAL([OPENSSL_NO_ASM], [test "x$enable_asm" = "xno"])

# Conditionally enable assembly by default
AM_CONDITIONAL([HOST_ASM_ELF_ARM],
[test "x$HOST_ABI" = "xelf" -a "$host_cpu" = "arm" -a "x$enable_asm" != "xno"])
AM_CONDITIONAL([HOST_ASM_ELF_MIPS],
[test "x$HOST_ABI" = "xelf" -a "$host_cpu" = "mips" -a "x$enable_asm" != "xno"])
AM_CONDITIONAL([HOST_ASM_ELF_MIPS64],
[test "x$HOST_ABI" = "xelf" -a "$host_cpu" = "mips64" -a "x$enable_asm" != "xno"])
AM_CONDITIONAL([HOST_ASM_ELF_X86_64],
[test "x$HOST_ABI" = "xelf" -a "$host_cpu" = "x86_64" -a "x$enable_asm" != "xno"])
AM_CONDITIONAL([HOST_ASM_MACOSX_X86_64],
Expand Down
16 changes: 12 additions & 4 deletions crypto/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ endif
libcrypto_la_CPPFLAGS = -I$(top_srcdir)/crypto/hidden ${AM_CPPFLAGS}
libcrypto_la_CPPFLAGS += -DLIBRESSL_INTERNAL
libcrypto_la_CPPFLAGS += -DOPENSSL_NO_HW_PADLOCK
if OPENSSL_NO_ASM
libcrypto_la_CPPFLAGS += -DOPENSSL_NO_ASM
else
endif

if OPENSSLDIR_DEFINED
libcrypto_la_CPPFLAGS += -DOPENSSLDIR=\"@OPENSSLDIR@\"
Expand Down Expand Up @@ -247,16 +243,21 @@ libcrypto_la_SOURCES =
EXTRA_libcrypto_la_SOURCES =

include Makefile.am.elf-arm
include Makefile.am.elf-mips
include Makefile.am.elf-mips64
include Makefile.am.elf-x86_64
include Makefile.am.macosx-x86_64
include Makefile.am.masm-x86_64
include Makefile.am.mingw64-x86_64

if !HOST_ASM_ELF_ARM
if !HOST_ASM_ELF_MIPS
if !HOST_ASM_ELF_MIPS64
if !HOST_ASM_ELF_X86_64
if !HOST_ASM_MACOSX_X86_64
if !HOST_ASM_MASM_X86_64
if !HOST_ASM_MINGW64_X86_64
libcrypto_la_CPPFLAGS += -DOPENSSL_NO_ASM
libcrypto_la_SOURCES += aes/aes_cbc.c
libcrypto_la_SOURCES += aes/aes_core.c
libcrypto_la_SOURCES += camellia/camellia.c
Expand All @@ -269,6 +270,8 @@ endif
endif
endif
endif
endif
endif

libcrypto_la_SOURCES += cpt_err.c
libcrypto_la_SOURCES += cryptlib.c
Expand Down Expand Up @@ -459,6 +462,11 @@ libcrypto_la_CPPFLAGS += -I$(top_srcdir)/crypto/bn/arch/i386/
endif
noinst_HEADERS += bn/arch/i386/bn_arch.h

if HOST_MIPS
libcrypto_la_CPPFLAGS += -I$(top_srcdir)/crypto/bn/arch/mips/
endif
noinst_HEADERS += bn/arch/mips/bn_arch.h

if HOST_MIPS64
libcrypto_la_CPPFLAGS += -I$(top_srcdir)/crypto/bn/arch/mips64/
endif
Expand Down
24 changes: 24 additions & 0 deletions crypto/Makefile.am.elf-mips
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ASM_MIPS_ELF = aes/aes-mips.S
ASM_MIPS_ELF += bn/bn-mips.S
ASM_MIPS_ELF += bn/mont-mips.S
ASM_MIPS_ELF += sha/sha1-mips.S
ASM_MIPS_ELF += sha/sha512-mips.S
ASM_MIPS_ELF += sha/sha256-mips.S

ASM_MIPS_ELF += aes/aes_cbc.c
ASM_MIPS_ELF += camellia/camellia.c
ASM_MIPS_ELF += camellia/cmll_cbc.c
ASM_MIPS_ELF += rc4/rc4_enc.c
ASM_MIPS_ELF += rc4/rc4_skey.c
ASM_MIPS_ELF += whrlpool/wp_block.c

EXTRA_DIST += $(ASM_MIPS_ELF)

if HOST_ASM_ELF_MIPS
libcrypto_la_CPPFLAGS += -DAES_ASM
libcrypto_la_CPPFLAGS += -DOPENSSL_BN_ASM_MONT
libcrypto_la_CPPFLAGS += -DSHA1_ASM
libcrypto_la_CPPFLAGS += -DSHA256_ASM
libcrypto_la_CPPFLAGS += -DSHA512_ASM
libcrypto_la_SOURCES += $(ASM_MIPS_ELF)
endif
24 changes: 24 additions & 0 deletions crypto/Makefile.am.elf-mips64
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
ASM_MIPS64_ELF = aes/aes-mips.S
ASM_MIPS64_ELF += bn/bn-mips.S
ASM_MIPS64_ELF += bn/mont-mips.S
ASM_MIPS64_ELF += sha/sha1-mips.S
ASM_MIPS64_ELF += sha/sha512-mips.S
ASM_MIPS64_ELF += sha/sha256-mips.S

ASM_MIPS64_ELF += aes/aes_cbc.c
ASM_MIPS64_ELF += camellia/camellia.c
ASM_MIPS64_ELF += camellia/cmll_cbc.c
ASM_MIPS64_ELF += rc4/rc4_enc.c
ASM_MIPS64_ELF += rc4/rc4_skey.c
ASM_MIPS64_ELF += whrlpool/wp_block.c

EXTRA_DIST += $(ASM_MIPS64_ELF)

if HOST_ASM_ELF_MIPS64
libcrypto_la_CPPFLAGS += -DAES_ASM
libcrypto_la_CPPFLAGS += -DOPENSSL_BN_ASM_MONT
libcrypto_la_CPPFLAGS += -DSHA1_ASM
libcrypto_la_CPPFLAGS += -DSHA256_ASM
libcrypto_la_CPPFLAGS += -DSHA512_ASM
libcrypto_la_SOURCES += $(ASM_MIPS64_ELF)
endif
24 changes: 24 additions & 0 deletions crypto/bn/arch/mips/bn_arch.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* $OpenBSD: bn_arch.h,v 1.1 2023/01/20 10:04:34 jsing Exp $ */
/*
* Copyright (c) 2023 Joel Sing <jsing@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/

#ifndef HEADER_BN_ARCH_H
#define HEADER_BN_ARCH_H

#ifndef OPENSSL_NO_ASM

#endif
#endif
154 changes: 154 additions & 0 deletions include/arch/mips/opensslconf.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
#include <openssl/opensslfeatures.h>
/* crypto/opensslconf.h.in */

#if defined(HEADER_CRYPTLIB_H) && !defined(OPENSSLDIR)
#define OPENSSLDIR "/etc/ssl"
#endif

#undef OPENSSL_UNISTD
#define OPENSSL_UNISTD <unistd.h>

#undef OPENSSL_EXPORT_VAR_AS_FUNCTION

#if defined(HEADER_IDEA_H) && !defined(IDEA_INT)
#define IDEA_INT unsigned int
#endif

#if defined(HEADER_MD2_H) && !defined(MD2_INT)
#define MD2_INT unsigned int
#endif

#if defined(HEADER_RC2_H) && !defined(RC2_INT)
/* I need to put in a mod for the alpha - eay */
#define RC2_INT unsigned int
#endif

#if defined(HEADER_RC4_H)
#if !defined(RC4_INT)
/* using int types make the structure larger but make the code faster
* on most boxes I have tested - up to %20 faster. */
/*
* I don't know what does "most" mean, but declaring "int" is a must on:
* - Intel P6 because partial register stalls are very expensive;
* - elder Alpha because it lacks byte load/store instructions;
*/
#define RC4_INT unsigned int
#endif
#if !defined(RC4_CHUNK)
/*
* This enables code handling data aligned at natural CPU word
* boundary. See crypto/rc4/rc4_enc.c for further details.
*/
#undef RC4_CHUNK
#endif
#endif

#if (defined(HEADER_NEW_DES_H) || defined(HEADER_DES_H)) && !defined(DES_LONG)
/* If this is set to 'unsigned int' on a DEC Alpha, this gives about a
* %20 speed up (longs are 8 bytes, int's are 4). */
#ifndef DES_LONG
#define DES_LONG unsigned int
#endif
#endif

#if defined(HEADER_BN_H) && !defined(CONFIG_HEADER_BN_H)
#define CONFIG_HEADER_BN_H
#define BN_LLONG

/* Should we define BN_DIV2W here? */

/* Only one for the following should be defined */
/* The prime number generation stuff may not work when
* EIGHT_BIT but I don't care since I've only used this mode
* for debugging the bignum libraries */
#undef SIXTY_FOUR_BIT_LONG
#undef SIXTY_FOUR_BIT
#define THIRTY_TWO_BIT
#undef SIXTEEN_BIT
#undef EIGHT_BIT
#endif

#if defined(HEADER_RC4_LOCL_H) && !defined(CONFIG_HEADER_RC4_LOCL_H)
#define CONFIG_HEADER_RC4_LOCL_H
/* if this is defined data[i] is used instead of *data, this is a %20
* speedup on x86 */
#define RC4_INDEX
#endif

#if defined(HEADER_BF_LOCL_H) && !defined(CONFIG_HEADER_BF_LOCL_H)
#define CONFIG_HEADER_BF_LOCL_H
#undef BF_PTR
#endif /* HEADER_BF_LOCL_H */

#if defined(HEADER_DES_LOCL_H) && !defined(CONFIG_HEADER_DES_LOCL_H)
#define CONFIG_HEADER_DES_LOCL_H
#ifndef DES_DEFAULT_OPTIONS
/* the following is tweaked from a config script, that is why it is a
* protected undef/define */
#ifndef DES_PTR
#undef DES_PTR
#endif

/* This helps C compiler generate the correct code for multiple functional
* units. It reduces register dependencies at the expense of 2 more
* registers */
#ifndef DES_RISC1
#undef DES_RISC1
#endif

#ifndef DES_RISC2
#undef DES_RISC2
#endif

#if defined(DES_RISC1) && defined(DES_RISC2)
YOU SHOULD NOT HAVE BOTH DES_RISC1 AND DES_RISC2 DEFINED!!!!!
#endif

/* Unroll the inner loop, this sometimes helps, sometimes hinders.
* Very much CPU dependent */
#ifndef DES_UNROLL
#define DES_UNROLL
#endif

/* These default values were supplied by
* Peter Gutman <pgut001@cs.auckland.ac.nz>
* They are only used if nothing else has been defined */
#if !defined(DES_PTR) && !defined(DES_RISC1) && !defined(DES_RISC2) && !defined(DES_UNROLL)
/* Special defines which change the way the code is built depending on the
CPU and OS. For SGI machines you can use _MIPS_SZLONG (32 or 64) to find
even newer MIPS CPU's, but at the moment one size fits all for
optimization options. Older Sparc's work better with only UNROLL, but
there's no way to tell at compile time what it is you're running on */

#if defined( sun ) /* Newer Sparc's */
# define DES_PTR
# define DES_RISC1
# define DES_UNROLL
#elif defined( __ultrix ) /* Older MIPS */
# define DES_PTR
# define DES_RISC2
# define DES_UNROLL
#elif defined( __osf1__ ) /* Alpha */
# define DES_PTR
# define DES_RISC2
#elif defined ( _AIX ) /* RS6000 */
/* Unknown */
#elif defined( __hpux ) /* HP-PA */
/* Unknown */
#elif defined( __aux ) /* 68K */
/* Unknown */
#elif defined( __dgux ) /* 88K (but P6 in latest boxes) */
# define DES_UNROLL
#elif defined( __sgi ) /* Newer MIPS */
# define DES_PTR
# define DES_RISC2
# define DES_UNROLL
#elif defined(i386) || defined(__i386__) /* x86 boxes, should be gcc */
# define DES_PTR
# define DES_RISC1
# define DES_UNROLL
#endif /* Systems-specific speed defines */
#endif

#endif /* DES_DEFAULT_OPTIONS */
#endif /* HEADER_DES_LOCL_H */
17 changes: 17 additions & 0 deletions scripts/test
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,23 @@ elif [ "x$ARCH" = "xarm32" -o "x$ARCH" = "xarm64" ]; then

file apps/openssl/.libs/openssl

elif [ "x$ARCH" = "xmipsel" -o "x$ARCH" = "xmips64el" ]; then
sudo apt-get install -y qemu-user-static binfmt-support

if [ "x$ARCH" = "xmipsel" ]; then
sudo apt-get install -y g++-mips-linux-gnu
sudo ln -sf /usr/mipsel-linux-gnu/lib/ld.so.1 /lib/
./configure --host=mipsel-linux-gnu
LD_LIBRARY_PATH=/usr/mipsel-linux-gnu/lib make -j 4 check
else
sudo apt-get install -y g++-mips64el-linux-gnuabi64
sudo ln -sf /usr/mips64el-linux-gnuabi64/lib64/ld.so.1 /lib64
./configure --host=mips64el-linux-gnuabi64
LD_LIBRARY_PATH=/usr/mips64el-linux-gnuabi64/lib make -j 4 check
fi

file apps/openssl/.libs/openssl

elif [ "x$ARCH" = "xandroid" ]; then
export TC_FILE=$ANDROID_NDK_HOME/build/cmake/android.toolchain.cmake

Expand Down
Loading

0 comments on commit 73d924f

Please sign in to comment.