-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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-585] Segfault on Linux in code using "catch let error as NSError" #43202
Comments
Comment by John Endres (JIRA) A note here. This crash seems to be specific to catching NSError. When throwing something based off of the ErrorType protocol, the crash does not happen. |
Comment by Vadim Eisenberg (JIRA) The problem seems to be due to the fact that in the swift-corelibs-foundation NSError does not implement ErrorType: https://github.com/apple/swift-corelibs-foundation/blob/master/Foundation/NSError.swift While https://github.com/apple/swift/blob/master/stdlib/public/SDK/Foundation/NSError.swift provides an extension that does: |
Comment by Robert Thompson (JIRA) vadim (JIRA User) Check further down in the file, extension NSError : ErrorType { } on line 168 😉 |
Comment by Vadim Eisenberg (JIRA) rothomp3 (JIRA User) Oops. So the bug is not so simple to fix 🙂 |
Comment by John Brownlee (JIRA) I wrote a test case for this and ran it in a debugger, and got the following backtrace:
I think the error is getting introduced around line ErrorObject.h:103 There's guards around that code to prevent it from being run on a "pure NSError", but the |
Comment by Mark Woollard (JIRA) I've been looking into an issue over in Foundation - SR-1547 - which led me here as its actually the same issue as here and nothing to do with |
Comment by Maksim Rogov (JIRA) Also seeing this issue on Ubuntu 16.04, hope we can get a fix by 3.1. Crashing error handling is really hard to track down 🙂 Update: This is a serious bug as Swift is pretty much unusable on Linux due to this. |
Still seeing this in the latest snapshots and on master, it's wreaking all kind of havoc. A fix would be great 🙂 Backtrace looks like this these days: * thread #​1, name = 'Test', stop reason = signal SIGSEGV: invalid address (fault address: 0x90)
* frame #​0: libswiftCore.so`swift_dynamicCast [inlined] swift::ValueWitnessFlags::getAlignmentMask() const at Metadata.h:231
frame #​1: libswiftCore.so`swift_dynamicCast [inlined] swift::ValueWitnessTable::getAlignmentMask(this=0x0000000000000000) const at Metadata.h:733
frame #​2: libswiftCore.so`swift_dynamicCast [inlined] swift::SwiftError::getValue(this=0x00000000008bf920) const at ErrorObject.h:119
frame #​3: libswiftCore.so`swift_dynamicCast at Casting.cpp:1508
frame #​4: libswiftCore.so`swift_dynamicCast(dest=<unavailable>, src=<unavailable>, srcType=<unavailable>, targetType=0x00007ffff75d5ef8, flags=Default) at Casting.cpp:2510 |
Comment by AdamDann (JIRA) I would also like to see a fix for this, thanks. |
New info - it crashes on ANY attempt to use an |
This should fix it: #7761 |
Even with the fix, though, I'd say that using NSError at all on Linux isn't a great idea. We provide the NSError bridge on Apple ObjC platforms for compatibility so that Swift code can work with the more specific |
I was finally able to get my build working with this fix and I can confirm I no longer crash on Linux!!!! |
Should be fixed in master now. |
Comment by Sergey Minakov (JIRA) Will this fix be included into 3.1 version? |
Comment by Maksim Rogov (JIRA) naithar (JIRA User) I sure hope so! Very necessary fix unless they fix corelibs-foundation on Linux for 3.1 instead (not to use NSError). |
@swift-ci create |
PR for 3.1: #7847 |
Attachment: Download
Environment
Ubuntu Linux 15.10
LLVM 3ebdbb2c7e, Clang f66c5bb67b, Swift e25cd88
Additional Detail from JIRA
md5: f2030dd3a4949c21dd4280ad4f13922d
is duplicated by:
relates to:
Issue Description:
Short example to reproduce the problem:
Backtrace from "swift errortest.swift":
The text was updated successfully, but these errors were encountered: