Skip to content

Instantly share code, notes, and snippets.

@sv99
Last active February 12, 2023 21:45
Show Gist options
  • Select an option

  • Save sv99/c9d8c155db7db83325847bd33b25e1d0 to your computer and use it in GitHub Desktop.

Select an option

Save sv99/c9d8c155db7db83325847bd33b25e1d0 to your computer and use it in GitHub Desktop.

Revisions

  1. sv99 revised this gist Jun 27, 2019. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion readme.md
    Original file line number Diff line number Diff line change
    @@ -6,10 +6,15 @@ Example ld:warning
    and library file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation are out of sync.
    Falling back to library file for linking.

    Need "stubify" libs with utility **tapi** from default toolchain.

    xcrun -r tapi stubify --help
    xcrun -r tapi stubify [lib] -o [tbd]

    Frameworks located in /System/Library/Frameworks/ and /System/Library/PrivateFrameworks/

    1. switch **csrutil disable** in recovery mode (reboot with [CMD]+R)
    2. run sudo regenerate_all_tbd.rb
    3. revert **csrutil enable** in recovery mode (reboot with [CMD]+R)

    !! Exists orfaned .tbd files without appropriate libs
    !! Exists orfaned .tbd files without appropriate libs !!
  2. sv99 renamed this gist Jun 27, 2019. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  3. sv99 created this gist Jun 27, 2019.
    47 changes: 47 additions & 0 deletions regenerate_all_tbd.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,47 @@
    #! /usr/bin/env ruby
    # -*- coding: UTF-8
    #
    # regenerate text-based stub files for frameworks in the /System/Library/Frameworks/
    # for supress ld warning. Need switch csrutil disable in recovery mode (reboot with [cmd]+R
    #
    # 27.06.2019
    #
    $tapi = `xcrun -f tapi`.strip()

    def stubify (tbd)
    if !File.symlink?(tbd)
    name = File.basename(tbd, ".tbd")
    lib = File.join(File.dirname(tbd), name)
    # maybi .dylib
    if !File.exist?(lib)
    if File.exists?(lib + ".dylib")
    lib = lib + ".dylib"
    else
    # orfaned .tld file - not exist lib with this name!!
    # found library OpenGL.framework/Versions/A/Libraries/libCoreVMClient.mono.tbd for lib libCoreVMClient.dylib
    # PrivateFrameworks CoreThemeDefinition.framework - CoreThemeDefinition.tbd and CoreThemeDefinition_debug.tbd for singl lib!!
    # PrintingPrivate.framework PrintingPrivate_profile.tbd
    # error install?? or old version
    File.delete(tbd)
    puts "problem: #{name} delete orfaned #{tbd} for lib #{lib}"
    return
    end
    end
    if File.exists?(lib)
    puts "stubify: #{lib} -o #{tbd}"
    `#${tapi} stubify #{lib} -o #{tbd}`
    else
    puts "problem with #{name}: lib #{lib} not found for #{tbd}"
    end
    end
    end

    Dir[ "/System/Library/Frameworks/**/*.tbd" ].each do |tbd|
    # text-based stub
    stubify tbd
    end

    Dir[ "/System/Library/PrivateFrameworks/**/*.tbd" ].each do |tbd|
    # text-based stub
    stubify tbd
    end
    15 changes: 15 additions & 0 deletions regenerate_tbd.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,15 @@
    Regenerate text-based stub files for frameworks
    ===============================================
    Example ld:warning

    ld: warning: text-based stub file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation.tbd
    and library file /System/Library/Frameworks//CoreFoundation.framework/CoreFoundation are out of sync.
    Falling back to library file for linking.

    Frameworks located in /System/Library/Frameworks/ and /System/Library/PrivateFrameworks/

    1. switch **csrutil disable** in recovery mode (reboot with [CMD]+R)
    2. run sudo regenerate_all_tbd.rb
    3. revert **csrutil enable** in recovery mode (reboot with [CMD]+R)

    !! Exists orfaned .tbd files without appropriate libs
    54 changes: 54 additions & 0 deletions regenerate_tbd.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    #! /usr/bin/env ruby
    # -*- coding: UTF-8
    #
    # regenerate text-based stub files for frameworks in the /System/Library/Frameworks/
    # for supress ld warning.
    #
    # 1. Need switch csrutil disable in recovery mode (reboot with [cmd]+R)
    # 2. regenerate .tbd
    # 3. csrutil enable
    #
    # 27.06.2019
    #

    require 'ostruct'
    require 'optparse'

    Version = '0.0.1'
    options = OpenStruct.new

    opts = OptionParser.new do |opts|
    opts.banner = "stubify cpecified framework
    Usage: #$0 [options]
    "
    opts.on('-f','--framework FRAMEWORK_PATH', String,
    'Framework path') do |framework|
    options.framework = File.absolute_path(framework)
    end

    opts.on_tail("--version", "Show version") do
    puts Version
    end
    end
    opts.parse!

    tapi = `xcrun -f tapi`.strip()

    framework = options.framework

    if Dir.exist?(framework )
    # framework
    name = File.basename(framework, ".framework")
    tbd = "#{framework}/#{name}.tbd"
    if File.exist?(tbd)
    if File.symlink?(tbd)
    tbd = File.join(File.dirname(tbd), File.readlink(tbd))
    end
    puts "stubify: #{framework} -o #{tbd}"
    `#{tapi} stubify #{framework}/#{name} -o #{tbd}`
    # `#{tapi} stubify #{framework}/#{name}`
    else
    puts "#{tbd} not exists"
    end
    end