Skip to content

Instantly share code, notes, and snippets.

@felixbuenemann
Created November 25, 2020 17:04
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save felixbuenemann/5f4dcb30ebb3b86e1302e2ec305bac89 to your computer and use it in GitHub Desktop.
Save felixbuenemann/5f4dcb30ebb3b86e1302e2ec305bac89 to your computer and use it in GitHub Desktop.
--- openssl-1.0.2u/Configure 2019-12-20 14:02:41.000000000 +0100
+++ openssl-1.0.2u/Configure 2020-11-22 16:23:13.000000000 +0100
@@ -650,7 +650,9 @@
"darwin-i386-cc","cc:-arch i386 -O3 -fomit-frame-pointer -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:".eval{my $asm=$x86_asm;$asm=~s/cast\-586\.o//;$asm}.":macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
"debug-darwin-i386-cc","cc:-arch i386 -g3 -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:${x86_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
"darwin64-x86_64-cc","cc:-arch x86_64 -O3 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:".eval{my $asm=$x86_64_asm;$asm=~s/rc4\-[^:]+//;$asm}.":macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch x86_64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+"darwin64-arm64-cc","cc:-arch arm64 -O3 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-arch arm64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
"debug-darwin64-x86_64-cc","cc:-arch x86_64 -ggdb -g2 -O0 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:".eval{my $asm=$x86_64_asm;$asm=~s/rc4\-[^:]+//;$asm}.":macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch x86_64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
+"debug-darwin64-arm64-cc","cc:-arch arm64 -ggdb -g2 -O0 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-arch arm64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
"debug-darwin-ppc-cc","cc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DB_ENDIAN -g -Wall -O::-D_REENTRANT:MACOSX::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc32_asm}:osx32:dlfcn:darwin-shared:-fPIC:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
# iPhoneOS/iOS
"iphoneos-cross","llvm-gcc:-O3 -isysroot \$(CROSS_TOP)/SDKs/\$(CROSS_SDK) -fomit-frame-pointer -fno-common::-D_REENTRANT:iOS:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
@felixbuenemann
Copy link
Author

felixbuenemann commented Nov 25, 2020

This patch allows OpenSSL 1.0.2u to be built on macOS arm64 (Apple Silicon M1) systems, but doesn't use any assembly optimizations, since the code in 1.0.2 is not compatible with Apple's clang assembly flavour.

It is possible to back port the assembly code from 1.1.1 or master and I have a working build, but that is a significant patch.

@felixbuenemann
Copy link
Author

Usage: ./Configure darwin64-arm64-cc

@eliduke
Copy link

eliduke commented Dec 18, 2020

Thanks for sharing this! Do you have any more details on the usage? I'm trying to get this installed so I can then install ruby 2.3.3 (I know) on Mac OS Arm, but I'm not sure exactly what your usage comment means. Thanks!

@eliduke
Copy link

eliduke commented Dec 18, 2020

Ooookay, I think I got a few steps closer. I figured out how to apply that patch, so, my Configure file now reads as such:

646: ##### MacOS X (a.k.a. Rhapsody or Darwin) setup
647: "rhapsody-ppc-cc","cc:-O3 -DB_ENDIAN::(unknown):MACOSX_RHAPSODY::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${no_asm}::",
648: "darwin-ppc-cc","cc:-arch ppc -O3 -DB_ENDIAN -Wa,-force_cpusubtype_ALL::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc32_asm}:osx32:dlfcn:darwin-shared:-fPIC -fno-common:-arch ppc -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
649: "darwin64-ppc-cc","cc:-arch ppc64 -O3 -DB_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc64_asm}:osx64:dlfcn:darwin-shared:-fPIC -fno-common:-arch ppc64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
650: "darwin-i386-cc","cc:-arch i386 -O3 -fomit-frame-pointer -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:".eval{my $asm=$x86_asm;$asm=~s/cast\-586\.o//;$asm}.":macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
651: "debug-darwin-i386-cc","cc:-arch i386 -g3 -DL_ENDIAN::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:BN_LLONG RC4_INT RC4_CHUNK DES_UNROLL BF_PTR:${x86_asm}:macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch i386 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
652: "darwin64-x86_64-cc","cc:-arch x86_64 -O3 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:".eval{my $asm=$x86_64_asm;$asm=~s/rc4\-[^:]+//;$asm}.":macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch x86_64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
653: "darwin64-arm64-cc","cc:-arch arm64 -O3 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-arch arm64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
654: "debug-darwin64-x86_64-cc","cc:-arch x86_64 -ggdb -g2 -O0 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:".eval{my $asm=$x86_64_asm;$asm=~s/rc4\-[^:]+//;$asm}.":macosx:dlfcn:darwin-shared:-fPIC -fno-common:-arch x86_64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
655: "debug-darwin64-arm64-cc","cc:-arch arm64 -ggdb -g2 -O0 -DL_ENDIAN -Wall::-D_REENTRANT:MACOSX:-Wl,-search_paths_first%:SIXTY_FOUR_BIT_LONG RC4_CHUNK DES_INT DES_UNROLL:${no_asm}:dlfcn:darwin-shared:-fPIC -fno-common:-arch arm64 -dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",
656: "debug-darwin-ppc-cc","cc:-DBN_DEBUG -DREF_CHECK -DCONF_DEBUG -DCRYPTO_MDEBUG -DB_ENDIAN -g -Wall -O::-D_REENTRANT:MACOSX::BN_LLONG RC4_CHAR RC4_CHUNK DES_UNROLL BF_PTR:${ppc32_asm}:osx32:dlfcn:darwin-shared:-fPIC:-dynamiclib:.\$(SHLIB_MAJOR).\$(SHLIB_MINOR).dylib",

I run ./Configure darwin64-arm64-cc and I get -> Configured for darwin64-arm64-cc..

Then I run make and get this:

making all in crypto...
/usr/bin/perl ../util/mkbuildinf.pl "cc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch arm64 -O3 -DL_ENDIAN -Wall" "darwin64-arm64-cc" >buildinf.h
cc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch arm64 -O3 -DL_ENDIAN -Wall   -c -o cryptlib.o cryptlib.c
cc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch arm64 -O3 -DL_ENDIAN -Wall   -c -o mem.o mem.c
cc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch arm64 -O3 -DL_ENDIAN -Wall   -c -o mem_dbg.o mem_dbg.c
cc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch arm64 -O3 -DL_ENDIAN -Wall   -c -o cversion.o cversion.c
cc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch arm64 -O3 -DL_ENDIAN -Wall   -c -o ex_data.o ex_data.c
cc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch arm64 -O3 -DL_ENDIAN -Wall   -c -o cpt_err.o cpt_err.c
cc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch arm64 -O3 -DL_ENDIAN -Wall   -c -o ebcdic.o ebcdic.c
cc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch arm64 -O3 -DL_ENDIAN -Wall   -c -o uid.o uid.c
cc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch arm64 -O3 -DL_ENDIAN -Wall   -c -o o_time.o o_time.c
cc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch arm64 -O3 -DL_ENDIAN -Wall   -c -o o_str.o o_str.c
cc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch arm64 -O3 -DL_ENDIAN -Wall   -c -o o_dir.o o_dir.c
cc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch arm64 -O3 -DL_ENDIAN -Wall   -c -o o_fips.o o_fips.c
cc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch arm64 -O3 -DL_ENDIAN -Wall   -c -o o_init.o o_init.c
cc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch arm64 -O3 -DL_ENDIAN -Wall   -c -o fips_ers.o fips_ers.c
cc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch arm64 -O3 -DL_ENDIAN -Wall   -c -o getenv.o getenv.c
cc -I. -I.. -I../include  -DOPENSSL_THREADS -D_REENTRANT -DDSO_DLFCN -DHAVE_DLFCN_H -arch arm64 -O3 -DL_ENDIAN -Wall   -c -o mem_clr.o mem_clr.c
ar  r ../libcrypto.a cryptlib.o mem.o mem_dbg.o cversion.o ex_data.o cpt_err.o ebcdic.o uid.o o_time.o o_str.o o_dir.o o_fips.o o_init.o fips_ers.o getenv.o mem_clr.o
ar: ../libcrypto.a is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
ar: ../libcrypto.a: Inappropriate file type or format
make[1]: *** [../libcrypto.a] Error 1
make: *** [build_crypto] Error 1

Did I do all the things right?

@felixbuenemann
Copy link
Author

felixbuenemann commented Dec 20, 2020

@eliduke Not sure why it is failing for you.

Maybe you don't have Xcode command line tools installed or they are outdated, try xcode-select --install and make sure your shell is running natively and not in Rosetta 2 (uname -m should return arm64).

The easiest way to install is probably via Homebrew. You can download the formula from my PR rbenv/homebrew-tap#2:

curl -Lo openssl@1.0.rb https://raw.githubusercontent.com/rbenv/homebrew-tap/e472b7861b49cc082d1db0f66f265368da107589/Formula/openssl%401.0.rb
brew install ./openssl@1.0.rb

That is assuming you have an arm64 Homebrew install in /opt/homebrew.

@tant42
Copy link

tant42 commented Dec 21, 2020

@eliduke I think I had this error (cleared the screen so I can't check), but make clean before running make again and see if that helps.

@stevenjohn
Copy link

@felixbuenemann
Copy link
Author

Thanks, glad you find it useful.

@kule
Copy link

kule commented May 9, 2021

Thank you very much @felixbuenemann !

FYI anyone having trouble installing ruby 2.2 with rbenv on an m1 mac - this'll hopefully point you in the right direction: rbenv/ruby-build#1742 (comment)

@HsiangHo
Copy link

Thank you so much! :) @felixbuenemann

@kamilturek
Copy link

kamilturek commented Oct 17, 2021

@felixbuenemann You rock! I had been struggling with it for a few days until I found your gist 🙂

@myalcinkuru
Copy link

myalcinkuru commented Jan 5, 2022

@felixbuenemann thank u so much 👍

@skycocker
Copy link

@felixbuenemann thank you! for anyone having issues with makedepend not being found: run brew install makedepend, then add

depends_on "makedepend"

to the formula body provided in this comment https://gist.github.com/felixbuenemann/5f4dcb30ebb3b86e1302e2ec305bac89#gistcomment-3567911

@CrimsonCleaver
Copy link

On fresh Ventura builds with latest Homebrew I seem to be getting errors along lines of:
elliptic curve routines

This seems to be in the make test portion of installing openssl1.0, does anyone else have this issue?

I can now no longer install it on a M based Mac

@danekszy
Copy link

On fresh Ventura builds with latest Homebrew I seem to be getting errors along lines of:
elliptic curve routines

@CrimsonCleaver same here...

@HannahFromAland
Copy link

@danekszy @CrimsonCleaver
Same on Ventura with the elliptic curve routines error in make test.

Downloaded the formula and commented the make test line then using brew install /path/to/formula.rb worked. Just a work around way to skip the test at this moment.

Hope it helps!

@Deinrk2
Copy link

Deinrk2 commented May 16, 2023

I have the same issue, do you mind expatiating a little bit , I'm not too sure how to download the formula and i'm still stuck on the elliptic curve routines error. Thanks

@ImprobableGenius
Copy link

ImprobableGenius commented Jul 19, 2023

Same error on M2 mac running Ventura OS, fails on Make Test with elliptic curve routines:EC_POINT_set_affine_coordinates_GF2m:point is not on curve:ec_lib.c:994. Anyone found a solution for this? I am trying to install ruby 2.3.1 and it requires openssl@1.0. Any help is greatly appreciated. Thanks!

Update #1: Followed @HannahFromAland's advice and was able to install openssl@1.0 by commenting the 'system make test line' from the configuration. I however wasn't able to link this formula as default using brew link openssl@1.0. The work around to install older version of ruby using rvm would be to use --with-openssl-dir flag:

CPPFLAGS=-DUSE_FFI_CLOSURE_ALLOC rvm_rubygems_version=2.7.3 rvm reinstall ruby-2.3.1 --with-openssl-dir=/usr/local/Cellar/openssl@1.0/1.0.2u --with-openssl-lib=/usr/local/Cellar/openssl@1.0/1.0.2u/lib --with-openssl-include=/usr/local/Cellar/openssl@1.0/1.0.2u/include

If you are using rbenv then:

CFLAGS="-Wno-error=implicit-function-declaration" RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl@1.0)" rbenv install 2.3.1

@CrimsonCleaver
Copy link

I found removing make test would get openssl1.0 installed, and then could install ruby 2.3.1, however soon as try to install a gem it fails with a SSL error - no one else experiencing that?

@oh-ok
Copy link

oh-ok commented Mar 26, 2024

Also experiencing this on Ruby 2.3.1.

You can disable the elliptical curve routines with the no-ec flag in configure. Though compiling with this still does not pass the cms‑test (so may be unstable), but it does compile and allow you to at least install gems.

EDIT 1:
Managed to compile a functional OpenSSL 1.0.2u with elliptical curve routines using Xcode 13 by downloading it, xcode-select --switch /path/to/new/Xcode.app/Contents/Developer/, then do a HOMEBREW_FAKE_MACOS="11.3" brew install rbenv/tap/openssl@1.0, and then xcode-select back to your native version. No guarantees of stability since this would fail the same cms‑test as above, but will at least have working elliptical curve routines and also be able to access rubygems.

EDIT 2:
Seems test_cms is expected to fail since the certs being tested have expired. Setting the system clock back to 2022 for make test fixes it 🤷‍♀️ otherwise, these solutions pass all tests.
The elliptical curve thing seems to be an LLVM-ism since I also managed to get it to compile perfectly with llvm@13 clang, but anything above that would fail.

EDIT 3:
After some more poking around, it turns out the elliptical curve issue was due to over-aggressive optimization by clang 14 and up. Fixed in https://github.com/rbenv/homebrew-tap/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment