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

[SR-10526] Runtime crash w/ Swift 5.0 and 5.0.1 - swift_checkMetadataState #52926

Open
swift-ci opened this issue Apr 20, 2019 · 4 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-10526
Radar None
Original Reporter mlwoollard (JIRA User)
Type Bug
Environment

macOS 10.14.4, Xcode 10.2.1, iOS simulator 12.2

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, RunTimeCrash
Assignee None
Priority Medium

md5: 15cdba57ea2ecad522ff54dc3b4d8e44

Issue Description:

We are seeing a runtime crash with Swift 5 compiler (in Swift 4.2 mode) that doesn't occur when same code compiled with Swift 4.2 compiler. Its occurring in a unit test module that uses the Quick library when Quick is initialising and making this call:

objc_getClassList(NULL, 0)

Which results in the following stack trace:

Thread 1 Queue : com.apple.main-thread (serial)Thread 1 Queue : com.apple.main-thread (serial)#0 0x00000001224b802f in swift_checkMetadataState ()#1 0x00000001224bbcd6 in bool findAnyTransitiveMetadata<checkTransitiveCompleteness(swift::TargetMetadata<swift::InProcess> const*)::$_14&>(swift::TargetMetadata<swift::InProcess> const*, checkTransitiveCompleteness(swift::TargetMetadata<swift::InProcess> const*)::$_14&) ()#2 0x00000001224bbbbe in checkTransitiveCompleteness(swift::TargetMetadata<swift::InProcess> const*) ()#3 0x00000001224bc9b8 in swift::MetadataCacheEntryBase<(anonymous namespace)::SingletonMetadataCacheEntry, int>::doInitialization(swift::ConcurrencyControl&, swift::MetadataCompletionQueueEntry*, swift::MetadataRequest) ()#4 0x00000001224b2213 in swift_getSingletonMetadata ()#5 0x0000000120852388 in type metadata accessor for MainScheduler ()#6 0x0000000120853c8c in ObjC metadata update function for MainScheduler ()#7 0x0000000106318d7f in realizeClassMaybeSwiftMaybeRelock(objc_class*, mutex_tt<false>&, bool) ()#8 0x000000010630fb98 in realizeAllClasses() ()#9 0x00000001063118f6 in objc_getClassList ()#10 0x000000011e421dd0 in qck_enumerateSubclasses at /Users/markw/UrbanThings/uttransitapi_apple/Pods/Quick/Sources/QuickObjectiveC/Configuration/QuickConfiguration.m:21#11 0x000000011e422083 in __32+[QuickConfiguration initialize]_block_invoke at /Users/markw/UrbanThings/uttransitapi_apple/Pods/Quick/Sources/QuickObjectiveC/Configuration/QuickConfiguration.m:74#12 0x0000000108e85d02 in _dispatch_client_callout ()#13 0x0000000108e874ce in _dispatch_once_callout ()#14 0x000000011e422025 in dispatch_once [inlined] at /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator12.2.sdk/usr/include/dispatch/once.h:84#15 0x000000011e42200a in +[QuickConfiguration initialize] at /Users/markw/UrbanThings/uttransitapi_apple/Pods/Quick/Sources/QuickObjectiveC/Configuration/QuickConfiguration.m:73#16 0x000000010630c698 in CALLING_SOME+initialize_METHOD ()#17 0x000000010630ca2a in initializeNonMetaClass ()#18 0x000000010630d54f in initializeAndMaybeRelock(objc_class*, objc_object*, mutex_tt<false>&, bool) ()#19 0x00000001063133e2 in lookUpImpOrForward ()#20 0x00000001063210d4 in objc_msgSend_uncached ()#21 0x000000011e42224f in +[QuickSpec initialize] at /Users/markw/UrbanThings/uttransitapi_apple/Pods/Quick/Sources/QuickObjectiveC/QuickSpec.m:29#22 0x000000010630c698 in CALLING_SOME+initialize_METHOD ()#23 0x000000010630ca2a in initializeNonMetaClass ()#24 0x000000010630c969 in initializeNonMetaClass ()#25 0x000000010630d54f in initializeAndMaybeRelock(objc_class*, objc_object*, mutex_tt<false>&, bool) ()#26 0x00000001063133e2 in lookUpImpOrForward ()#27 0x00000001063210d4 in _objc_msgSend_uncached ()#28 0x0000000105ba9d41 in -[NSBundle loadAndReturnError:] ()#29 0x000000010620223d in _XCTestMain ()#30 0x0000000105880cb9 in main ()#31 0x0000000108ef3541 in start ()#32 0x0000000108ef3541 in start ()

Since this doesn't occur with all our unit test modules based around Quick there is something more subtle but to provide a complete case to reproduce would be involved (but can do if needed).

@belkadan
Copy link
Contributor

I mean, this seems kind of correct: it's saying you can't get a list of all classes while in the process of initializing one of those classes. But +initialize is supposed to be the last thing that happens in class initialization, so…

@rjmccall, @mikeash, any insights?

@mikeash
Copy link
Contributor

mikeash commented Apr 22, 2019

It should be OK to do this. objc_getClassList forces all classes to be realized, but it doesn't force +initialize. That's done lazily on the first message send, even when making this call.

Might be that Swift is less happy about reentering its metadata initialization stuff. John probably knows better than I.

@rjmccall
Copy link
Member

Swift has a concept of abstract vs. fully-initialized type metadata that's probably roughly analogous to what Mike is describing, but I didn't realize that ObjC exposed such a difference so I didn't think to make sure that the ObjC/Swift runtime interactions could support request incomplete metadata, which means we probably just have to call this unsupportable.

@swift-ci
Copy link
Collaborator Author

Comment by Mark Woollard (JIRA)

The above comments gave me a bit more insight and have resolved issue which turned out to be ObjC classes being linked into both the test harness and framework under test. Thus for ObjC there were duplicate classes loaded - am assuming it is this that is confusing the metadata validation ! Removing the duplication and unit tests now run fine.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software run-time crash Bug → crash: Swift code crashed during execution
Projects
None yet
Development

No branches or pull requests

5 participants