Skip to content

Commit 16a10bd

Browse files
committed
Update Defines to exclude Swift symbols from all mangling
1 parent 8067662 commit 16a10bd

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

lib/cocoapods_mangle/defines.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def self.mangling_defines(prefix, binaries_to_mangle)
2323
# @return [Array<String>] The classes defined in the binaries
2424
def self.classes(binaries)
2525
all_symbols = run_nm(binaries, '-gU')
26+
all_symbols = all_symbols.reject { |symbol| swift_symbol?(symbol) }
27+
2628
class_symbols = all_symbols.select do |symbol|
2729
symbol[/OBJC_CLASS_\$_/]
2830
end
@@ -36,6 +38,8 @@ def self.classes(binaries)
3638
# @return [Array<String>] The constants defined in the binaries
3739
def self.constants(binaries)
3840
all_symbols = run_nm(binaries, '-gU')
41+
all_symbols = all_symbols.reject { |symbol| swift_symbol?(symbol) }
42+
3943
consts = all_symbols.select { |const| const[/ S /] }
4044
consts = consts.reject { |const| const[/_OBJC_/] }
4145
consts = consts.reject { |const| const[/__block_descriptor.*/] }
@@ -110,6 +114,31 @@ def self.prefix_selectors(prefix, selectors)
110114
defines
111115
end
112116

117+
# Is symbol a Swift symbol? This is used to avoid mangling Swift.
118+
# @param [String] symbol
119+
# The symbol to check
120+
# @return [Boolean] true if it is a Swift symbol, false otherwise
121+
def self.swift_symbol?(symbol)
122+
# Swift binaries have many symbols starting with $s_ that should be excluded
123+
# e.g. '0000000000000258 S _$s9ManglePod9SomeClassCMF'
124+
symbol[/ _\$s/] ||
125+
# Internal Swift symbols starting with __swift or ___swift such as should not be mangled
126+
# e.g. '00000000000050ac S ___swift_reflection_version'
127+
symbol[/ __(_)?swift/] ||
128+
# Swift symbols starting with _symbolic should be ignored
129+
# e.g. '0000000000000248 S _symbolic _____ 9ManglePod9SomeClassC'
130+
symbol[/ _symbolic/] ||
131+
# Swift symbol references to Objective-C symbols should not be mangled
132+
# e.g. '00000000000108ca S _associated conformance So26SCNetworkReachabilityFlagsVs10SetAlgebraSCSQ'
133+
symbol[/associated conformance/] ||
134+
# _globalinit symbols should be skipped
135+
# e.g. 0000000000000000 T _globalinit_33_A313450CFC1FC3D0CBEF4411412DB9E8_func0
136+
symbol[/ _globalinit/] ||
137+
# Swift classes inheriting from Objective-C classes should not be mangled
138+
# e.g. '0000000000000290 S _OBJC_CLASS_$__TtC9ManglePod19SomeFoundationClass'
139+
symbol[/_OBJC_CLASS_\$__/]
140+
end
141+
113142
def self.run_nm(binaries, flags)
114143
`nm #{flags} #{binaries.join(' ')}`.split("\n")
115144
end

0 commit comments

Comments
 (0)