Skip to content

Instantly share code, notes, and snippets.

@sv99
Last active February 12, 2023 21:45
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sv99/c9d8c155db7db83325847bd33b25e1d0 to your computer and use it in GitHub Desktop.
Save sv99/c9d8c155db7db83325847bd33b25e1d0 to your computer and use it in GitHub Desktop.
OSX Regenerate text-based stub file for remove ld: warning: text-based stub file

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.

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 !!

#! /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
#! /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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment