How to specify mininum iOS version for linker? #109

Open
opened 2021-08-17 02:04:21 -05:00 by JCash · 0 comments
JCash commented 2021-08-17 02:04:21 -05:00 (Migrated from github.com)

Hi!

I have an issue with the latest versions of the iPhoneOS, where when I link towards the AVFoundation framework, I always also get linkage towards the AVFAudio framework, regardless of which minnimum iPhoneOS version I specify.

Since the AVFAudio framework is new since iPhoneOS 14.5, it won't work with older devices.
The apple linker checks the min iPhoneOS version and links accordingly. (See example below)

So my questions are, how do I build/configure cctools-port to do this, and what should I pass into the linker?

Any tips/hints are much appreciated!

Regards,
Mathias

Currently, I build cctools with prefix arm-apple-darwin19 and latest libtapi, and I link with:
(I removed the libraries/frameworks for brevity)

clang++ -arch arm64 -target arm-apple-darwin19 -m64 -miphoneos-version-min=8.0 -O2 -g -stdlib=libc++ -isysroot /opt/platformsdk/iPhoneOS14.5.sdk -o ./testapp -fobjc-link-runtime -dead_strip -Wl,-U,_objc_loadClassref -fno-autolink -ObjC  -lclang_rt.ios -framework AVFoundation ./main.o

Comparing with Apple clang, it's easy to switch between min iPhoneOS versions:

clang -target arm64-apple-ios10.0 -framework AVFoundation -o ./testapp

otool -L ./testapp | grep AVF

    /System/Library/Frameworks/AVFoundation.framework/AVFoundation (compatibility version 1.0.0, current version 2.0.0)

(when using verbose, the 14.3 build passes this to the apple linker: -platform_version ios 10.0.0 14.5)

versus

clang -target arm64-apple-ios14.5 -framework AVFoundation -o ./testapp

otool -L ./testapp | grep AVF

    /System/Library/Frameworks/AVFoundation.framework/AVFoundation (compatibility version 1.0.0, current version 2.0.0)
    /System/Library/Frameworks/AVFAudio.framework/AVFAudio (compatibility version 1.0.0, current version 1.0.0)

(when using verbose, the 14.3 build passes this to the apple linker: -platform_version ios 14.5.0 14.5)

Comparing the AVFoundation.tbd between versions reveals this bit, which is a clue.
Also, the `AVFAudio.tbd doesn't exist in 14.3)

AVFoundation.tbd (iPhoneOS 14.3)

...
install-name:    '/System/Library/Frameworks/AVFoundation.framework/Frameworks/AVFAudio.framework/AVFAudio'
exports:
  - targets:         [ armv7-ios, armv7s-ios ]
    objc-classes:    [ AVAudioEndpointDetector ]
    objc-ivars:      [ AVAudioEndpointDetector._impl ]
  - targets:         [ arm64-ios, arm64e-ios, armv7-ios, armv7s-ios ]
    symbols:         [ _AVAudioBitRateStrategy_Constant, _AVAudioBitRateStrategy_LongTermAverage, 
...

AVFoundation.tbd (iPhoneOS 14.5)

...
install-name:    '/System/Library/Frameworks/AVFAudio.framework/AVFAudio'
exports:
  - targets:         [ armv7-ios, armv7s-ios ]
    objc-classes:    [ AVAudioEndpointDetector ]
    objc-ivars:      [ AVAudioEndpointDetector._impl ]
  - targets:         [ arm64-ios, arm64e-ios, armv7-ios, armv7s-ios ]
    symbols:         [ '$ld$previous$/System/Library/Frameworks/AVFoundation.framework/AVFoundation$$2$1.0$14.5$$', 
                       _AVAudioBitRateStrategy_Constant, _AVAudioBitRateStrategy_LongTermAverage, 
...
Hi! I have an issue with the latest versions of the iPhoneOS, where when I link towards the `AVFoundation` framework, I always also get linkage towards the `AVFAudio` framework, regardless of which minnimum iPhoneOS version I specify. Since the `AVFAudio` framework is new since iPhoneOS 14.5, it won't work with older devices. The apple linker checks the min iPhoneOS version and links accordingly. (See example below) So my questions are, how do I build/configure cctools-port to do this, and what should I pass into the linker? Any tips/hints are much appreciated! Regards, Mathias Currently, I build cctools with prefix `arm-apple-darwin19` and latest [libtapi](https://github.com/tpoechtrager/apple-libtapi), and I link with: (I removed the libraries/frameworks for brevity) ``` clang++ -arch arm64 -target arm-apple-darwin19 -m64 -miphoneos-version-min=8.0 -O2 -g -stdlib=libc++ -isysroot /opt/platformsdk/iPhoneOS14.5.sdk -o ./testapp -fobjc-link-runtime -dead_strip -Wl,-U,_objc_loadClassref -fno-autolink -ObjC -lclang_rt.ios -framework AVFoundation ./main.o ``` Comparing with Apple clang, it's easy to switch between min iPhoneOS versions: ``` clang -target arm64-apple-ios10.0 -framework AVFoundation -o ./testapp otool -L ./testapp | grep AVF /System/Library/Frameworks/AVFoundation.framework/AVFoundation (compatibility version 1.0.0, current version 2.0.0) ``` (when using verbose, the 14.3 build passes this to the apple linker: `-platform_version ios 10.0.0 14.5`) versus ``` clang -target arm64-apple-ios14.5 -framework AVFoundation -o ./testapp otool -L ./testapp | grep AVF /System/Library/Frameworks/AVFoundation.framework/AVFoundation (compatibility version 1.0.0, current version 2.0.0) /System/Library/Frameworks/AVFAudio.framework/AVFAudio (compatibility version 1.0.0, current version 1.0.0) ``` (when using verbose, the 14.3 build passes this to the apple linker: `-platform_version ios 14.5.0 14.5`) Comparing the `AVFoundation.tbd` between versions reveals this bit, which is a clue. Also, the `AVFAudio.tbd doesn't exist in 14.3) AVFoundation.tbd (iPhoneOS 14.3) ``` ... install-name: '/System/Library/Frameworks/AVFoundation.framework/Frameworks/AVFAudio.framework/AVFAudio' exports: - targets: [ armv7-ios, armv7s-ios ] objc-classes: [ AVAudioEndpointDetector ] objc-ivars: [ AVAudioEndpointDetector._impl ] - targets: [ arm64-ios, arm64e-ios, armv7-ios, armv7s-ios ] symbols: [ _AVAudioBitRateStrategy_Constant, _AVAudioBitRateStrategy_LongTermAverage, ... ``` AVFoundation.tbd (iPhoneOS 14.5) ``` ... install-name: '/System/Library/Frameworks/AVFAudio.framework/AVFAudio' exports: - targets: [ armv7-ios, armv7s-ios ] objc-classes: [ AVAudioEndpointDetector ] objc-ivars: [ AVAudioEndpointDetector._impl ] - targets: [ arm64-ios, arm64e-ios, armv7-ios, armv7s-ios ] symbols: [ '$ld$previous$/System/Library/Frameworks/AVFoundation.framework/AVFoundation$$2$1.0$14.5$$', _AVAudioBitRateStrategy_Constant, _AVAudioBitRateStrategy_LongTermAverage, ... ```
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
miles/cctools-port#109
No description provided.