Skip to content

Instantly share code, notes, and snippets.

@evandcoleman
Created May 29, 2020 17:01
Show Gist options
  • Save evandcoleman/aa7f634d229f7e2ce5b691957f862275 to your computer and use it in GitHub Desktop.
Save evandcoleman/aa7f634d229f7e2ce5b691957f862275 to your computer and use it in GitHub Desktop.

A fix for debugging shared precompiled binaries from Carthage.

error: Couldn't IRGen expression, no additional error

Usage

./build.sh --platform ios MyCoolFramework

#!/bin/sh -e
XCCONFIG=$(mktemp /tmp/static.xcconfig.XXXXXX)
trap 'rm -f "$XCCONFIG"' INT TERM HUP EXIT
echo "SWIFT_SERIALIZE_DEBUGGING_OPTIONS = NO" >> $XCCONFIG
export XCODE_XCCONFIG_FILE="$XCCONFIG"
carthage build "$@"
@aakarsh-sasi
Copy link

aakarsh-sasi commented Apr 29, 2021

This is what my script looks like (with xcode 12 workaround included)

#!/usr/bin/env bash
# carthage.sh
# Usage example: ./carthage.sh build --platform iOS

set -euo pipefail

xcconfig=$(mktemp /tmp/static.xcconfig.XXXXXX)
trap 'rm -f "$xcconfig"' INT TERM HUP EXIT

# For Xcode 12 make sure EXCLUDED_ARCHS is set to arm architectures otherwise
# the build will fail on lipo due to duplicate architectures.

CURRENT_XCODE_VERSION=$(xcodebuild -version | grep "Build version" | cut -d' ' -f3)

echo "EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200__BUILD_$CURRENT_XCODE_VERSION = arm64 arm64e armv7 armv7s armv6 armv8" >> $xcconfig

echo 'EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200 = $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_simulator__NATIVE_ARCH_64_BIT_x86_64__XCODE_1200__BUILD_$(XCODE_PRODUCT_BUILD_VERSION))' >> $xcconfig
echo 'EXCLUDED_ARCHS = $(inherited) $(EXCLUDED_ARCHS__EFFECTIVE_PLATFORM_SUFFIX_$(EFFECTIVE_PLATFORM_SUFFIX)__NATIVE_ARCH_64_BIT_$(NATIVE_ARCH_64_BIT)__XCODE_$(XCODE_VERSION_MAJOR))' >> $xcconfig
echo "SWIFT_SERIALIZE_DEBUGGING_OPTIONS = NO" >> $xcconfig
echo "OTHER_SWIFT_FLAGS = $(inherited) -Xfrontend -no-serialize-debugging-options" >> $xcconfig

export XCODE_XCCONFIG_FILE="$xcconfig"
carthage "$@"

@psolt-gpsw
Copy link

psolt-gpsw commented Apr 29, 2021

Make sure you delete all Carthage cached data and Xcode DerivedData before building, or I have found it may corrupt the build.

  1. You need to also remove any offending library that still linked to your build paths by searching and deleting (empty trash) – if that's not possible you may need to do what Strava did.

  2. I was able to test if it worked by deleting all the Carthage build folders and cache folder

    rm -rf ~/Library/Caches/org.carthage.CarthageKit
    rm -rf Carthage
  3. All I had to do was set a breakpoint in another internal framework/library that we had in the app, in lldb run po self – if that failed due to IRGen, then the issue wasn't fixed.

  4. lldb image list helped me see where it's loading from.

    (lldb) image list
    [  0] B430E131-7C63-32B0-B7F1-F937935A9C10 0x0000000102df4000 /Users/psolt/Library/Developer/Xcode/DerivedData/AppName-cgccgwlpvbsiwfhggackekkmufqs/Build/Products/Debug-iphoneos/AppName.app/AppName 
          /Users/psolt/Library/Developer/Xcode/DerivedData/AppName-cgccgwlpvbsiwfhggackekkmufqs/Build/Products/Debug-iphoneos/AppName.app.dSYM/Contents/Resources/DWARF/AppName
    [  1] 1F4D7499-EE60-3C5D-9D54-2CD29E4E537C 0x00000001070dc000 /Users/psolt/Library/Developer/Xcode/iOS DeviceSupport/14.4.2 (18D70) arm64e/Symbols/usr/lib/dyld 
    [  2] 5B7E6F77-8C66-315F-9282-98895A6EBE31 0x00000001076fc000 /Users/psolt/Library/Developer/Xcode/DerivedData/AppName-cgccgwlpvbsiwfhggackekkmufqs/Build/Products/Debug-iphoneos/AppName.app/Frameworks/FBSDKCoreKit.framework/FBSDKCoreKit 
          /System/Volumes/Data/Users/psolt/dev/Facebook/FacebookSDK/Carthage/Build/FBSDKCoreKit.xcframework/ios-arm64_armv7/dSYMs/FBSDKCoreKit.framework.dSYM/Contents/Resources/DWARF/FBSDKCoreKit
    ...
  5. The key is looking for where it loads the framework, which is that indented path for each entry: /System/Volumes/Data/Users/psolt/dev/Facebook/FacebookSDK/Carthage/Build/FBSDKCoreKit.xcframework/ios-arm64_armv7/dSYMs/FBSDKCoreKit.framework.dSYM/Contents/Resources/DWARF/FBSDKCoreKit

    1. This is telling me it found the dSYM file in my Carthage Build folder, if that dSYM has hard coded paths, deleting that build folder will cause the IRGen issue to appear.
  6. You can track down these unexpected locations of dSYM files if they're problematic for the architecture you're building:

    xcrun dwarfdump --uuid FBSDKCoreKit.xcframework/ios-arm64_armv7/FBSDKCoreKit.framework/FBSDKCoreKit
    
    UUID: 9B015D0E-D9CF-3660-AB4E-13BEF02FF1D5 (armv7) FBSDKCoreKit.xcframework/ios-arm64_armv7/FBSDKCoreKit.framework/FBSDKCoreKit
    UUID: 5B7E6F77-8C66-315F-9282-98895A6EBE31 (arm64) FBSDKCoreKit.xcframework/ios-arm64_armv7/FBSDKCoreKit.framework/FBSDKCoreKit
    1. That gives you insight into the UUID (lets look at the arm64: 5B7E6F77-8C66-315F-9282-98895A6EBE31), which you use to track down locations:
  7. Find those locations by UUID, older versions (with hard coded paths) may still be present on your machine, which you'll need to remove.

    mdfind "com_apple_xcode_dsym_uuids == 5B7E6F77-8C66-315F-9282-98895A6EBE31"
    
    /Users/psolt/dev/codereview/libs/public/ios/FacebookSDK-ios/local 9.1.0 ios only/FBSDKCoreKit.xcframework/ios-arm64_armv7/dSYMs/FBSDKCoreKit.framework.dSYM
    /Users/psolt/dev/codereview/libs/public/ios/FacebookSDK-ios/FBSDKCoreKit.xcframework/ios-arm64_armv7/dSYMs/FBSDKCoreKit.framework.dSYM
    /Users/psolt/dev/Facebook/FacebookSDK/Carthage/Build/FBSDKCoreKit.xcframework/ios-arm64_armv7/dSYMs/FBSDKCoreKit.framework.dSYM
    1. This is telling me that my library workspace has two copies of the dSYM, one in the expected spot, and another duplicate I was testing. It also found the build folder for Carthage.
    2. If any of these locations is not the fresh build with the flags above, and it gets loaded (image list) you will see path issues on another development machine, or if you clear your build folders for Carthage/Xcode derived data.

NOTE: If there are no library code changes, the UUID may be the same value between builds. I bumped our Facebook SDK version to prevent this apparent issue, but that might not be possible depending on the library you're using (see what Strava did).

@caioremedio
Copy link

@aakarsh-sasi Did you solve your issue? I'm facing exactly the same thing and I can't get my username out of the BCSymbolMaps files.

@psolt-gpsw I did everything, every kind of clean, but my username still shows up as path.

I even checked the Carthage build log, and its passing the two variables correctly, even on swiftc.

I'm using Xcode 13.2 btw.

@aakarsh-sasi
Copy link

@caioremedio no I couldn’t fix the path after multiple trials and then I gave up in the end. If using both the flag solved this, would have saved a lot of time

@psolt-gpsw
Copy link

@caioremedio I fixed our issue. Bumping the Facebook SDK version was important to make it different from previously used versions on our developer's machines. Otherwise, it may still reference the old build from the previous UUID and the hard-coded paths.

Did you walk through all of my steps?

@aakarsh-sasi
Copy link

@psolt-gpsw anyway to cleanup those paths without doing a version bump?

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