Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fails to parse parse dynamic framework if it contains new arm64_32 arch slice #113

Closed
shekhar-suman opened this issue Sep 25, 2018 · 3 comments · Fixed by #114
Closed

Fails to parse parse dynamic framework if it contains new arm64_32 arch slice #113

shekhar-suman opened this issue Sep 25, 2018 · 3 comments · Fixed by #114
Assignees

Comments

@shekhar-suman
Copy link

Apple has added a new arm64_32 arch for WatchOS 5.0 SDK (Xcode 10.0). If a a dynamic framework has this arch, ruby-macho is not able to read it. This is breaking Cocoapod project because it thinks that framework is static and not dynamic. But this framework is a valid dynamic framework.

$> file openssl.framework/openssl

openssl.framework/openssl: Mach-O universal binary with 3 architectures: [i386:Mach-O dynamically linked shared library i386] [arm64_32_v8]
openssl.framework/openssl (for architecture i386):	Mach-O dynamically linked shared library i386
openssl.framework/openssl (for architecture armv7k):	Mach-O dynamically linked shared library arm_v7k
openssl.framework/openssl (for architecture cputype (33554444) cpusubtype (1)):	Mach-O dynamically linked shared library arm64_32_v8

$> lipo -info openssl.framework/openssl 

Architectures in the fat file: openssl.framework/openssl are: i386 armv7k arm64_32 

macho library fails to read this framework.

Test Script

require 'macho'
  
file = MachO.open("openssl.framework/openssl")
puts file.filetype

This throws an error.

~/.rvm/gems/ruby-2.4.0@global/gems/ruby-macho-1.1.0/lib/macho/macho_file.rb:457:in `check_cputype': Unrecognized CPU type: 0x0200000c (MachO::CPUTypeError)
	from /Users/shekhar.suman/.rvm/gems/ruby-2.4.0@global/gems/ruby-macho-1.1.0/lib/macho/macho_file.rb:429:in `populate_mach_header'
	from /Users/shekhar.suman/.rvm/gems/ruby-2.4.0@global/gems/ruby-macho-1.1.0/lib/macho/macho_file.rb:234:in `populate_fields'
	from /Users/shekhar.suman/.rvm/gems/ruby-2.4.0@global/gems/ruby-macho-1.1.0/lib/macho/macho_file.rb:55:in `initialize_from_bin'
	from /Users/shekhar.suman/.rvm/gems/ruby-2.4.0@global/gems/ruby-macho-1.1.0/lib/macho/macho_file.rb:33:in `new_from_bin'
	from /Users/shekhar.suman/.rvm/gems/ruby-2.4.0@global/gems/ruby-macho-1.1.0/lib/macho/fat_file.rb:324:in `block in populate_machos'
	from /Users/shekhar.suman/.rvm/gems/ruby-2.4.0@global/gems/ruby-macho-1.1.0/lib/macho/fat_file.rb:323:in `each'
	from /Users/shekhar.suman/.rvm/gems/ruby-2.4.0@global/gems/ruby-macho-1.1.0/lib/macho/fat_file.rb:323:in `populate_machos'
	from /Users/shekhar.suman/.rvm/gems/ruby-2.4.0@global/gems/ruby-macho-1.1.0/lib/macho/fat_file.rb:124:in `populate_fields'
	from /Users/shekhar.suman/.rvm/gems/ruby-2.4.0@global/gems/ruby-macho-1.1.0/lib/macho/fat_file.rb:63:in `initialize'
	from /Users/shekhar.suman/.rvm/gems/ruby-2.4.0@global/gems/ruby-macho-1.1.0/lib/macho.rb:31:in `new'
	from /Users/shekhar.suman/.rvm/gems/ruby-2.4.0@global/gems/ruby-macho-1.1.0/lib/macho.rb:31:in `open'
	from temp.rb:4:in `<main>'

I have tested, if framework does not include arm64_32 slice, then it successfully reads the framework.
I have attached openssl.framework.zip so you can test on your end. I'm on MacOS 10.13.6.

@shekhar-suman
Copy link
Author

$> lipo -detailed_info openssl.framework/openssl
Fat header in: openssl.framework/openssl
fat_magic 0xcafebabe
nfat_arch 3
architecture i386
    cputype CPU_TYPE_I386
    cpusubtype CPU_SUBTYPE_I386_ALL
    offset 4096
    size 2419696
    align 2^12 (4096)
architecture armv7k
    cputype CPU_TYPE_ARM
    cpusubtype CPU_SUBTYPE_ARM_V7K
    offset 2424832
    size 9152820
    align 2^14 (16384)
architecture arm64_32
    cputype CPU_TYPE_ARM64_32
    cpusubtype CPU_SUBTYPE_ARM64_32_V8
    offset 11599872
    size 9526584
    align 2^15 (32768)

@woodruffw woodruffw added the bug label Sep 25, 2018
@woodruffw
Copy link
Member

woodruffw commented Sep 25, 2018

Thanks for the report! I'm guessing Apple added a new cputype and subtype without telling anybody, so this should be a relatively quick fix. I'll make the changes tonight.

@woodruffw woodruffw self-assigned this Sep 25, 2018
@shekhar-suman
Copy link
Author

Thanks @woodruffw for quick reply. will wait for your fix.

woodruffw added a commit that referenced this issue Sep 26, 2018
Based on binary samples, it looks like CPU_TYPE_ARM64_32 is the same
constant as CPU_TYPE_ARM, ORed with a new ABI flag
(0x02000000, instead of 0x01000000 for CPU_ARCH_ABI64). Similarly,
the only CPU subtype seen so far appears to be a direct copy of
CPU_SUBTYPE_ARM64_V8 and CPU_SUBTYPE_ARM_V8.

Fixes #113.
woodruffw added a commit that referenced this issue Sep 26, 2018
Based on binary samples, it looks like CPU_TYPE_ARM64_32 is the same
constant as CPU_TYPE_ARM, ORed with a new ABI flag
(0x02000000, instead of 0x01000000 for CPU_ARCH_ABI64). Similarly,
the only CPU subtype seen so far appears to be a direct copy of
CPU_SUBTYPE_ARM64_V8 and CPU_SUBTYPE_ARM_V8.

Fixes #113.
@lock lock bot added the outdated label Jan 1, 2020
@lock lock bot locked as resolved and limited conversation to collaborators Jan 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants