Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot build 3.X.X for old versions of iOS #20687

Closed
Un1q32 opened this issue Apr 7, 2023 · 9 comments
Closed

cannot build 3.X.X for old versions of iOS #20687

Un1q32 opened this issue Apr 7, 2023 · 9 comments
Labels
triaged: question The issue contains a question

Comments

@Un1q32
Copy link

Un1q32 commented Apr 7, 2023

Using these commands I can build OpenSSL 1.1.1 for old versions of iOS using my toolchain

./Configure ios-cross --prefix=/usr --openssldir=/usr/lib/ssl CROSS_COMPILE=arm-apple-darwin9-
make CNF_CFLAGS=-fno-common

but when using the same commands for OpenSSL 3 I get a ton of errors about undefined symbols

arm-apple-darwin9-cc -fPIC -fno-common -O3 -L. -bundle -Wl,-search_paths_first  \
	-o providers/legacy.dylib \
	providers/legacy-dso-legacyprov.o \
	providers/liblegacy.a providers/libcommon.a -lcrypto  
Undefined symbols for architecture armv6:
  "___atomic_fetch_or_8", referenced from:
      _CRYPTO_atomic_or in libcrypto.a(libcrypto-lib-threads_pthread.o)
  "___atomic_is_lock_free", referenced from:
      _CRYPTO_atomic_or in libcrypto.a(libcrypto-lib-threads_pthread.o)
      _CRYPTO_atomic_load in libcrypto.a(libcrypto-lib-threads_pthread.o)
  "___atomic_load", referenced from:
      _CRYPTO_atomic_load in libcrypto.a(libcrypto-lib-threads_pthread.o)
ld: symbol(s) not found for architecture armv6
clang-15: error: linker command failed with exit code 1 (use -v to see invocation)

The iOS SDK I use (5.1) has no libatomic.
I'm using the 5.1 SDK because it's the last SDK to include armv6 libraries, meaning I can run my stuff on even the oldest idevices

@Un1q32 Un1q32 added the issue: bug report The issue was opened to report a bug label Apr 7, 2023
@blazmonster
Copy link
Contributor

  1. Can you check your library that you are linking (i.e -lcrypto) is in correct path?
  2. Can you try checking your libcrypto (-lcrypto) library is compiled with the same compiler version that you are using for this here ?

I know these are very basic steps but lets start with very basic debug.

@Un1q32
Copy link
Author

Un1q32 commented Apr 8, 2023

Isn't libcrypto part of openssl? All the libraries and stuff are straight from the iOS 5.1 SDK that I got from https://invoxiplaygames.uk/sdks/iPhoneOS5.1.sdk.tar.lzma

I don't know how Apple compiled the libraries in the 5.1 SDK

OpenSSL 1.1.1 builds fine with the unmodified 5.1 SDK

My build machine is Arch Linux with Clang 15.0.7, I've tested on MacOS 11.7.5 with the same Clang version and get the same result

My C compiler is a simple shell script wrapper around clang

#!/bin/sh
case $0 in
    *+)
        cc=clang++
    ;;
esac

tripple=${0##*/}
tripple=${tripple%-*}

exec "${cc:-clang}" -target "$tripple" -arch armv6 -miphoneos-version-min=3.0.0 -mlinker-version=609 -Wno-unused-command-line-arguement -isysroot "${_SDKPATH:-${0%/*}/../sdk}" "$@"

For this build its basically running clang -target arm-apple-darwin9 -arch armv6 -miphoneos-version-min=3.0.0 -mlinker-version=609 -Wno-unused-command-line-arguement -isysroot /path/to/ios5.1sdk "$@"

My linker and the rest of my toolchain are built from https://github.com/tpoechtrager/cctools-port, except on MacOS where they are included with Xcode

@paulidale paulidale added triaged: question The issue contains a question and removed issue: bug report The issue was opened to report a bug labels Apr 10, 2023
@paulidale
Copy link
Contributor

Which version of OpenSSL 3.0 are you using?

You need to disable atomic operations: try configuring with -DOPENSSL_DEV_NO_ATOMICS perhaps.

@Un1q32
Copy link
Author

Un1q32 commented Apr 10, 2023

I'm using 3.1.0, but I get the same error on every 3.0.X version I've tested.

Using the commands

./Configure ios-cross --prefix=/usr --openssldir=/usr/lib/ssl CROSS_COMPILE=arm-apple-darwin9- -DOPENSSL_DEV_NO_ATOMICS
make CNF_CFLAGS=-fno-common

results in the same error as before

@Un1q32
Copy link
Author

Un1q32 commented Sep 19, 2023

I tried again recently with 3.1.2

./Configure ios-cross CROSS_COMPILE=armv7-apple-darwin11-
make CNF_CFLAGS='-fno-common -DOPENSSL_DEV_NO_ATOMICS' -j12

same error

clang 16.0.6
targeting armv7 iOS 5.0 with the 5.0 SDK

@chemwolf6922
Copy link

chemwolf6922 commented Dec 11, 2023

Same error here. Configure and make process:

CC=clang CROSS_TOP=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer CROSS_SDK=iPhoneOS.sdk ./Configure ios-cross no-asm

Produces error in the linking process:

Undefined symbols for architecture armv7:
  "___atomic_fetch_or_8", referenced from:
      _CRYPTO_atomic_or in libcrypto.a(libcrypto-lib-threads_pthread.o)
  "___atomic_load", referenced from:
      _CRYPTO_atomic_load in libcrypto.a(libcrypto-lib-threads_pthread.o)
ld: symbol(s) not found for architecture armv7
clang: error: linker command failed with exit code 1 (use -v to see invocation)

Adding -latomic or -DOPENSSL_DEV_NO_ATOMICS does not work.
openssl version: 3.1.4

@chemwolf6922
Copy link

After digging the code. Found a solution:
Add -DBROKEN_CLANG_ATOMICS to the config options. This will prevent crypto/threads_pthread.c from using atomic operations.
However I am not sure if this will affect the function / performance.

@tom-cosgrove-arm
Copy link
Contributor

Specifying -DBROKEN_CLANG_ATOMICS will cause the compiler to fall back to using a slower locking mechanism. Correctness should be preserved, although performance is likely to be a bit worse.

@Un1q32
Copy link
Author

Un1q32 commented Dec 11, 2023

./Configure ios-cross CROSS_COMPILE=armv7-apple-darwin11-
make CNF_CFLAGS='-fno-common -DBROKEN_CLANG_ATOMICS' -j12

Can build 3.1.2 (static library only), 3.1.3 and newer require adding no-asm to the ./Configure command

Using Clang 17.0.6 with the iOS 5.0 SDK

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triaged: question The issue contains a question
Projects
None yet
Development

No branches or pull requests

5 participants