objc_copyClassNamesForImage not working on device
| Originator: | d4rkf1br3 | ||
| Number: | rdar://29103196 | Date Originated: | 04/11/2016 |
| Status: | Open | Resolved: | |
| Product: | iOS | Product Version: | 10.1 |
| Classification: | Serious Bug | Reproducible: | Always |
Summary:
The test app attached includes 2 frameworks I've built. The frameworks are copied using a copy files phase into the Frameworks directory of the app. I have the following app delegate code:
#import "AppDelegate.h"
@import ObjectiveC;
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[NSBundle allFrameworks] enumerateObjectsUsingBlock:^(NSBundle *framework, NSUInteger idx, BOOL *stop) {
unsigned int count = 0;
__unused const char** classes = objc_copyClassNamesForImage([[framework executablePath] UTF8String], &count);
NSRange inFramework = [framework.executablePath rangeOfString:@".app/Frameworks"];
if (inFramework.length > 0) {
NSLog(@"Framework %@, classes: %i", framework.executablePath.lastPathComponent, count);
}
}];
return YES;
}
@end
Which prints out the frameworks from the Frameworks directory and the number of classes contained in each.
When I run this code in the simulator I get the following results:
2016-11-04 12:02:17.682 RuntimeTest[54326:623229] Framework PEGKit, classes: 24
2016-11-04 12:02:17.707 RuntimeTest[54326:623229] Framework StoryTeller, classes: 10
However when I run it on a device I get:
2016-11-04 12:07:04.215417 RuntimeTest[1035:365233] Framework PEGKit, classes: 0
2016-11-04 12:07:04.254946 RuntimeTest[1035:365233] Framework StoryTeller, classes: 0
The device is an iPhone 7 with iOS 10.1. I'm pretty sure that this code has worked in the past and it appears that `objc_copyClassNamesForImage` is somehow broken.
My working theory is that this could be some 10.1 bug. Or perhaps something that is set/not set in the build properties.
Steps to Reproduce:
1. Open the test app.
2. run the app.
3. Examine console output.
4. Compare simulator results to device results.
Expected Results:
Both frameworks are listed with their correct number of classes.
Actual Results:
In simulator the numbers are correct. On the device the console shows 0 classes in both frameworks.
Version:
OS X 10.12
Notes:
Configuration:
Xcode 8.1 GM, iPhone 7 with 10.1
Attachments:
'RuntimeTest.zip' was successfully uploaded.
Comments
Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!