Swift 1.2 segmentation fault on compile of Release scheme - ios

I've just upgraded to Swift 1.2 and when I attempt to compile the iOS application using the Release scheme I receive a "segmentation fault: 11".
0 swift 0x00000001105a9a08 llvm::sys::PrintStackTrace(__sFILE*) + 40
1 swift 0x00000001105a9ee4 SignalHandler(int) + 452
2 libsystem_platform.dylib 0x00007fff9a724f1a _sigtramp + 26
3 libsystem_platform.dylib 0x00007fff4fd6f6b0 _sigtramp + 3043272624
4 swift 0x00000001100e837a (anonymous namespace)::DCE::markControllingTerminatorsLive(swift::SILBasicBlock*) + 346
5 swift 0x00000001100e8109 (anonymous namespace)::DCE::markValueLive(swift::ValueBase*) + 201
6 swift 0x00000001100e791f (anonymous namespace)::DCE::run() + 1983
7 swift 0x000000011008f55e swift::SILPassManager::runFunctionPasses(llvm::ArrayRef<swift::SILFunctionTransform*>) + 1310
8 swift 0x000000011008ffe9 swift::SILPassManager::runOneIteration() + 633
9 swift 0x000000011008ea56 swift::runSILOptimizationPasses(swift::SILModule&) + 790
10 swift 0x000000010fe92ee7 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 4695
11 swift 0x000000010fe91ae6 main + 1814
12 libdyld.dylib 0x00007fff995665c9 start + 1
The application compiles and runs perfectly when I use the Dev/Debug scheme.
I have narrowed the compiler issue down to a single file and a couple lines of code.
let directPhoneType = PhoneNumber.Codes.Contacts["D"]
phoneTypes = phoneTypes.filter { $0 != directPhoneType }
I've tried changing the filtering code around (using "element in", etc), but each attempt causes the segmentation fault still. There is other filtering logic throughout our application that compiles fine.
If I remove the filtering code or change it to a loop that manually filters the phone types, the Application runs fine in the Release scheme.
I've tried setting the optimization level to "Fastest, Unchecked" or "Fastest", the segmentation fault still occurs. If I set the optimization level to "None"; the project builds.
This code worked fine before Swift 1.2 in both schemes.
Anyone have any insight into what is going on here?
UPDATE: It looks like Xcode 6.3.1 has fixed my seg fault issues.

Ran into the same problem, without having code similar to yours. Turning off whole module optimization (which is off by default) solved the issue for me, meaning I'm still able to archive with fastest optimization settings.

Unfortunately we have these sorts of issues all the time. The fault is not with you and they are frustratingly difficult to track down. Usually somewhat arbitrary code changes eventually solve things.
Various superstitions we have developed include: reducing use of unowned where possible, reducing use of weak where possible, being cautious of the ?? operator, being cautious of "too much" stuff in one line (like max(min(x,y),z)), switching let to var, etc.
In your code I might try switching your let to a var, or try removing the filter and doing an old school
var resultList = [MyType]()
for type in phoneTypes {
if type != directPhoneType {
resultList.append(type)
}
}
or change PhoneNumber.Codes.Contacts["D"] to access that differently.
Good luck! Happy hunting.

I had this problem when switching to Swift 1.2 and not just for release scheme. While migrating, I had changed a recommended "as!" to "as?" thinking that it was what I wanted. That seems to have caused the problem; I went back and changed to "as!" and it worked.

Related

Abort Trap: 6 error in the new Swift 3.1/Xcode 8.3

I have a finished project with about 30vcs, Firebase, Googlemaps integration, etc - ie a really big complicated project, it is a geolocation based game that I've finally finished after several months of work.
Worked and compiled just fine, until I tried to compile it in the new Swift 3.1/ Xcode 8.3.
After changing the recommended syntax on a few lines to clear the new XCODE 8.3 errors, compiling fails with "Abort Trap: 6" error.
This is the last few lines of the debugger (prior to that theres about 100 lines of incomprehensible file names/numbers etc).
0 swift 0x00000001089f1eb7
PrintStackTraceSignalHandler(void*) + 39 1 swift
0x00000001089f1366 SignalHandler(int) + 646 2
libsystem_platform.dylib 0x00007fffc602eb3a _sigtramp + 26 3
libsystem_platform.dylib 0x0000000100000001 _sigtramp + 972887265 4
libsystem_c.dylib 0x00007fffc5eb3420 abort + 129 5 swift
0x0000000106454644
swift::ModuleFile::getDecl(llvm::PointerEmbeddedInt,
llvm::Optional) + 38404 6 swift
0x00000001064564fa
swift::ModuleFile::getType(llvm::PointerEmbeddedInt)
+ 2106 7 swift 0x000000010644f373 swift::ModuleFile::getDecl(llvm::PointerEmbeddedInt,
llvm::Optional) + 17203 8 swift
0x0000000106459f24
swift::ModuleFile::maybeReadPattern(swift::DeclContext*) + 740 9
swift 0x000000010644f605
swift::ModuleFile::getDecl(llvm::PointerEmbeddedInt,
llvm::Optional) + 17861 10 swift
0x00000001064607c8 swift::ModuleFile::loadAllMembers(swift::Decl*,
unsigned long long) + 600 11 swift
0x0000000106840f0d swift::NominalTypeDecl::getMembers() const + 125 12
swift 0x0000000106828c75 (anonymous
namespace)::Traversal::visitNominalTypeDecl(swift::NominalTypeDecl*) +
869 13 swift 0x0000000106826645 (anonymous
namespace)::Traversal::doIt(swift::Decl*) + 277 14 swift
0x000000010619a75f
swift::SILPassManager::SILPassManager(swift::SILModule*,
llvm::StringRef) + 1471 15 swift 0x00000001061a135f
swift::runSILDiagnosticPasses(swift::SILModule&) + 159 16 swift
0x0000000105811282 swift::performFrontend(llvm::ArrayRef,
char const*, void*, swift::FrontendObserver*) + 42866 17 swift
0x00000001057c088c main + 9052 18 libdyld.dylib
0x00007fffc5e1f235 start + 1 Stack dump:
(here is about 150 lines of incomprehensible debugging numbers/files/alphanumericals - followed by this in the end):
While loading members for 'homePage' in module 'googleMapsPractice'
While deserializing PatternBindingDecl #295in 'googleMapsPractice'
While deserializing 'gameDBRef' (VarDecl #296)in 'googleMapsPractice'
While deserializing decl #1009 (XREF)in 'googleMapsPractice'
Cross-reference to module 'FirebaseDatabase' ... FIRDatabaseReference
I am really stuck as I don't know where to look to debug this.
'homePage.swift' is the set-up page VC of the game, and is the only VC referenced in the debugger, is there any common solutions to Abort Trap 6 errors that I could try weed out on this VC? It is probably 2000 lines of code and i'm not even sure the problem lies in that VC as the debugger is so vague.
Any help would be greatly appreciated
This happened to me because I had a private enum in both the main class, and an extension of that class. Both of these were in the same file. Tricky one!
In my case, it appears that it was due to a local project scheme missing with a build phase in my application attempting to link to the project.
I have run into the same problem. I finally figured out that it was caused by overriding 'var description' on any class that inherits from NSObject. I note that in Swift 3.1 there is a 'class func description()' on NSObject that I don't necessarily recall being in Swift 3.0 (although I could easily be mistaken in this assumption; I've never had any to look for or use it). See also https://forums.developer.apple.com/thread/75700
I faced the error because my class had a diffrent name than the filename. Corrected filename and everything worked fine then
In my case was because I put a ! symbol in a init method of a object. Like this:
init(obj1: Object1, obj2: Object2!) {
}
Remove the ! of function parameter and no more error.
I had similar issues with Swift classes that had properties with type RCTRootView from React. I fixed it by making the property private, turning something like this:
class MyViewController: UIViewController {
var rctView: RCTRootView()
}
Into something like this:
class MyViewController: UIViewController {
private var rctView: RCTRootView()
}
It seems that the error is in trying to deserialize classes from other modules/frameworks too early in compilation (in your case FirebaseDatabase and in my case React). Making this property private makes it so that the compiler doesn't need to do this till later in compilation. If I had to guess, it looks like we're sweeping some dependency/build order problems under the rug.
I fixed this by switching to a different device in the simulator - it then compiled and ran fine.
Then, when I went back to the previous device it also worked fine.
I've no explanation!

Command failed due to signal: Segmentation fault: 11 while archiving

I tried to archive my App and get this error:
Command failed due to signal: Segmentation fault: 11
When I Build it everything went fine, also on real devices. While archiving this happens. Any Ideas how to fix ?
This is a part of the error:
0 swift 0x000000010f79f3ad PrintStackTraceSignalHandler(void*) + 45
1 swift 0x000000010f79eb56 SignalHandler(int) + 790
2 libsystem_platform.dylib 0x00007fffc82d5bba _sigtramp + 26
3 libsystem_platform.dylib 0x0000000000000040 _sigtramp + 936551584
4 swift 0x000000010cae0de3 swift::CastOptimizer::optimizeUnconditionalCheckedCastAddrInst(swift::UnconditionalCheckedCastAddrInst*) + 1699
5 swift 0x000000010cb69d4d processFunction(swift::SILFunction&, bool, unsigned int) + 1917
6 swift 0x000000010cb70c9f (anonymous namespace)::ConstantPropagation::run() + 47
7 swift 0x000000010caff89e swift::SILPassManager::runOneIteration() + 5166
8 swift 0x000000010cb051f6 swift::runSILOptimizationPasses(swift::SILModule&) + 3462
9 swift 0x000000010c7ac0e2 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 20114
10 swift 0x000000010c7a52b3 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17859
11 swift 0x000000010c7615cf main + 8239
12 libdyld.dylib 0x00007fffc80c8255 start + 1
13 libdyld.dylib 0x00000000000000ee start + 938704538
And at the end:
1. While running pass #38147 SILFunctionTransform "Constant Propagation" on SILFunction "#_TTSg5VSC29UIApplicationLaunchOptionsKeyS_s8Hashable5UIKit_P__CSo8NSObjectS2_S0_10ObjectiveC_Ps9AnyObject____TFs17_dictionaryUpCastu2_Rxs8Hashable0_S_rFGVs10Dictionaryxq__GS0_q0_q1__".
Try disabling Swift Compiler Optimization for Release
Then if you get any errors for missing files:
In the file inspector of the file click on the folder icon next to "Location" and locate the file manually
In my case, I tested all solutions including disabling optimization in the build settings:
Build Settings > Optimization Level > Release > No optimization [-Onone]
I don't recommend the above solution since this will affect your entire app and your final binary won't be optimized.
Based on contact with technical team at Apple, There are multiple reasons that could lead to this error, however there's a known bug for archiving during optimization and you need to bypass it by finding the place that compiler is failing and add #_optimize(none) at the top of your function that's causing the issue.
This attribute will tell compiler to ignore the function for optimisation.
class MyNavigationController:UINavigationController {
#_optimize(none)
init(navigationController: UINavigationController?, context: AppContextProtocol) {
// content
}
}
Check Build Settings -> Swift 3 #Objc inference. It most likely should be off.

Xcode - Compile Swift Segmentation Fault 11

Project configuration:
Xcode 7.3.1
min iOS version 7.1
iOS SDK 9.3
cocoapods
While trying to compile mixed Objective-C/Swift project - getting error Segmentation Fault 11, with the next build log:
Compile *.swift
Command failed due to signal: Segmentation Fault 11
In details of, error I can see really long output with some useful info:
CompileSwift normal arm64 filePath/*.swift
0 swift 0x000000010b73266b llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 43
1 swift 0x000000010b731956 llvm::sys::RunSignalHandlers() + 70
2 swift 0x000000010b732ccf SignalHandler(int) + 287
3 libsystem_platform.dylib 0x00007fff8b49e52a _sigtramp + 26
4 libsystem_platform.dylib 0x00007fa8f989d5e0 _sigtramp + 1849684176
5 swift 0x000000010994d737 swift::ClangImporter::Implementation::addEntryToLookupTable(clang::Sema&, swift::SwiftLookupTable&, clang::NamedDecl*) + 151
6 swift 0x000000010994d802 swift::ClangImporter::Implementation::addEntryToLookupTable(clang::Sema&, swift::SwiftLookupTable&, clang::NamedDecl*) + 354
7 swift 0x000000010994e44c swift::ClangImporter::Implementation::importHeader(swift::ModuleDecl*, llvm::StringRef, swift::SourceLoc, bool, std::__1::unique_ptr<llvm::MemoryBuffer, std::__1::default_delete<llvm::MemoryBuffer> >) + 1468
8 swift 0x000000010994ebc6 swift::ClangImporter::importBridgingHeader(llvm::StringRef, swift::ModuleDecl*, swift::SourceLoc, bool) + 502
9 swift 0x000000010993ef2d swift::CompilerInstance::performSema() + 605
10 swift 0x0000000109482596 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&) + 934
11 swift 0x000000010948168d frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2781
12 swift 0x000000010947d0ac main + 1932
13 libdyld.dylib 0x00007fff887b05ad start + 1
14 libdyld.dylib 0x000000000000026b start + 2005204159
And architecture compile error changes, if I switch from device to simulator and backwards, so shouldn't be architecture problem.
Reading Mac Console output I can see, crashes in SourceKit Service, at the same moment:
Thread 4 Crashed:: Dispatch queue: com.apple.root.default-qos
0 com.apple.SourceKitService.703.0.18.8 0x0000000106f1ca63 swift::ClangNode::getLocation() const + 19
1 com.apple.SourceKitService.703.0.18.8 0x0000000106c22a0f swift::ClangImporter::lookupBridgingHeaderDecls(llvm::function_ref<bool (swift::ClangNode)>, llvm::function_ref<void (swift::Decl*)>) const + 111
2 com.apple.SourceKitService.703.0.18.8 0x0000000106c22cb8 swift::ClangImporter::lookupDeclsFromHeader(llvm::StringRef, llvm::function_ref<bool (swift::ClangNode)>, llvm::function_ref<void (swift::Decl*)>) const + 216
3 com.apple.SourceKitService.703.0.18.8 0x00000001069a9034 swift::ide::printHeaderInterface(llvm::StringRef, swift::ASTContext&, swift::ASTPrinter&, swift::PrintOptions const&) + 852
4 com.apple.SourceKitService.703.0.18.8 0x00000001068bf368 SourceKit::SwiftInterfaceGenContext::create(llvm::StringRef, bool, llvm::StringRef, swift::CompilerInvocation, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&) + 1992
5 com.apple.SourceKitService.703.0.18.8 0x00000001068c1de8 SourceKit::SwiftLangSupport::editorOpenHeaderInterface(SourceKit::EditorConsumer&, llvm::StringRef, llvm::StringRef, llvm::ArrayRef<char const*>) + 1704
6 com.apple.SourceKitService.703.0.18.8 0x00000001068d7895 handleRequestImpl(void*, std::__1::function<void (void*)>) + 6773
7 com.apple.SourceKitService.703.0.18.8 0x00000001068d5dc4 sourcekitd::handleRequest(void*, std::__1::function<void (void*)>) + 420
Problem has occurred absolutely randomly project was always working fine, and at one point just stopped running on simulator, but continued running fine on device. After that it just stopped running anyway. Going back commit by commit, I can see, that this problem existed during the last couple of weeks, and checking every change it is quite a bit job and doesn't give any results.
Apparently it is some Xcode issue, but cleaning, removing derived data, module caches, Xcode settings, reinstalling Xcode, using beta version and previous version of Xcode, removing Source Kit Service, disabling/enabling modules support, bitcode, increasing/decreasing deployment target and any other suggestions, that can be googled - give the same result.
Reading internet comments - the problem should be in some part of the code, related with swift, but completely commenting or removing all swift related code gives another error:
cyclic dependency in module 'darwin'
And this way any of the frameworks like Foundation or UIKit, cannot be compiled, and I'm getting hundreds of errors, related to unknown classes.
Creating new project and adding files there one by one, didn't give any result as well - after adding all files and installing cocoapods, project has worked fine for some time, but after that - the same problem has started again.
So I see no way, how to find the exact part of code, which causes the problem (which really is Xcode bug, but there is almost no hope, that it will be fixed in Xcode 8, because it still exists in Beta version).
Will be glad to hear any help regarding this issue, I just can't sleep for a couple of days because of it :)
Found what has caused my issue:
I've had "Math.h" custom file and class in project, importing and using it caused an issue.
The strangest thing, that this file was in project during last 18 days, but everything worked fine. I guess, that it depends on how I'm using it, using it in Objective-C project, doesn't cause any issue.

Understanding iOS Crash [SIGABRT ABORT]

I just received my first crash report from Crashlytics and am attempting to correct the issue. Unfortunately it is only with a line of code that runs on older devices so I can't test it on my iPhone 6.
The crash report from Crashlytics highlights two threads, the first reads:
Fatal Exception: NSInvalidArgumentException
-[CABasicAnimation altitude]: unrecognized selector sent to instance 0x17734440
While the second reads:
Crashed: Map Update :: NSOperation 0x1a839470
SIGABRT ABORT at 0x316a3dfc
The indicated line of code for both threads is:
let relativeAlt = mylocation.altitude - appDelegate.elevation
Where:
let mylocation = self.mapView.myLocation
let appDelegate = (UIApplication.sharedApplication().delegate as AppDelegate)
I'm trying to understand what I'm reading in the crash report. The way I see it the program doesn't understand the altitude reference made for some reason? This doesn't make sense to me since this crash seems to occur after that app has been running for several minutes without error, the highlighted line of code is run possibly hundreds of times before the app crashed. What is really happening here?
Additional Information:
Since writing, I have received additional crashes that I believe stem from the same issue:
Crashed: Map Update :: NSOperation 0x19fb2d50
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x11d077ca
Crashed: Map Update :: NSOperation 0x145ced50
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x81450a64
The first highlighted the following line in my code (I believe since I had worked on the app since this beta release and the line numbers have changed slightly):
self.lastLocation = (self.mapView.myLocation as CLLocation).coordinate
While the second crash just gave me:
libobjc.A.dylib
objc_msgSend + 5
The first of the new crashes (That provided a line of code) provided this report:
Thread : Crashed: Map Update :: NSOperation 0x19fb2d50
0 libobjc.A.dylib 0x3105c708 objc_release + 7
1 FlightTracker 0x000ba830 FlightTracker.MapViewController. (locationManager (FlightTracker.MapViewController) -> (Swift.ImplicitlyUnwrappedOptional<ObjectiveC.CLLocationManager>, didUpdateLocations : Swift.ImplicitlyUnwrappedOptional<Swift.Array<Swift.AnyObject>>) -> ()).(closure #1) (MapViewController.swift:168)
2 Foundation 0x244ce0fd __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 8
3 Foundation 0x24438fc5 -[NSBlockOperation main] + 148
4 Foundation 0x2442b845 -[__NSOperationInternal _start:] + 768
5 Foundation 0x244d0a57 __NSOQSchedule_f + 186
6 libdispatch.dylib 0x315ad5d9 _dispatch_queue_drain$VARIANT$mp + 948
7 libdispatch.dylib 0x315ad0a9 _dispatch_queue_invoke$VARIANT$mp + 84
8 libdispatch.dylib 0x315af0d3 _dispatch_root_queue_drain + 330
9 libdispatch.dylib 0x315b01fb _dispatch_worker_thread3 + 106
10 libsystem_pthread.dylib 0x31720e25 _pthread_wqthread + 668
Probably not your problem, but I just had a SIGABRT that was driving me nuts (that's how I ended up looking at this question) and I'll post my solution in case it helps some future S.O. spelunker.
In my (iPad, not that it matters) app, you can push a button that results in the creation of a not-full-screen UIViewController which contains a UITableView, and this viewController is presented via UIPopoverController.
In my case I had a screw-up in my loading of the tableView items which, at the time of creating the tableView cell I ended up trying to add a null value into a dictionary. (It's a long story, having to do with an infrastructure class that expects the data to be in a certain format.)
Anyway, attempting to access newViewController.view caused the SIGABRT on that line, with no clue that the problem was related to filling the tableView cell. Nothing tableView-related was evident in the stack trace, so it took me quite a while to narrow things down. I eventually just guessed "maybe it's the tableview" and disconnected the IBOutlet and delegate/dataSource to see if the crash went away.
...And it did. Which lead me down the path of finding the real problem.
Anyway, that's my story. Hope it's helpful to someone.
Due to the lack of a full/proper crash report and the lack of more code and architecture, the following is an assumption using the little bits of information that are available.
You are accessing a variable in a background thread (NSOperation queue) that got released on another thread and now isn't available any longer, so the pointer shows to some other random object in the memory. And that random object surely has no idea what to do with the altitude message which is then causing the crash.
You have to make sure that all variables used in the background thread, are available and not released in another thread.
Wow, I just had another "impossible to track down" solution to this that was driving me bonkers.
Earlier in the day, I'd done a major refactor as some of the objects in my game had names like RFCFoo and some were like RfcBar and I wanted to standardize the capitalization.
So I used XCode's Refactor->Rename... tool, and it worked great, except for one thing:
It failed to rename one specific .xib file, which remained as "RFCBlahBlah.xib" when I was trying to load it as "RfcBlahBlah.xib"
Again, I hope this proves useful for some future SO searcher.

Bad memory alignment iOS

I am stuck with the following crash report:
Date/Time: 2013-09-12 22:39:54 +0000
OS Version: iPhone OS 6.1.3 (10B329)
Report Version: 104
Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR at 0xa0000008
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x39a3c564 _cache_getImp + 4
1 libobjc.A.dylib 0x39a3e1d7 class_respondsToSelector + 31
2 CoreFoundation 0x31b96605 objectIsKindOfClass + 37
3 CoreFoundation 0x31b9635d __handleUncaughtException + 69
4 libobjc.A.dylib 0x39a41a65 _objc_terminate() + 129
5 libc++abi.dylib 0x3948e07b safe_handler_caller(void (*)()) + 79
6 libc++abi.dylib 0x3948e114 std::terminate() + 20
7 libc++abi.dylib 0x3948f599 __cxa_current_exception_type + 1
8 libobjc.A.dylib 0x39a419d1 objc_exception_rethrow + 13
9 CoreFoundation 0x31adcf21 CFRunLoopRunSpecific + 457
10 CoreFoundation 0x31adcd49 CFRunLoopRunInMode + 105
11 GraphicsServices 0x356a82eb GSEventRunModal + 75
12 UIKit 0x339f2301 UIApplicationMain + 1121
13 Our App 0x0003bc27 main (main.m:15)
After different attempts to fix the bug causing this error I keep receiving this crashlog again and again from PLCrashReporter (from our adhoc builds from the beta testers). The different exception codes vary from SIGSEGV/SEGV_ACCERR to SIGBUS/BUS_ADRALN to EXC_BAD_ACCESS/KERN_INVALID_ADDRESS
I am using the rapidjson library on iOS (armv7 and armv7s) with the padding fix as described here (#8) and I use the objective-c runtime functions to add method implementation on runtime (using class_addMethod).
Our codebase exists of mostly Objective-C code with some Obj-C++ and some C code. Memory Management is done by ARC except for the Obj-C++ and C parts which is handled manually. I looked into every malloc/free call and I extensively used libgmalloc to determine memory issues but there is nothing which does not seem correct to me.
I cannot reproduce this crashlogs myself, not in debug or release mode, but our beta testers keep sending me this crashlog once in a while (1 in about 50 runs). As our product (hopefully) will run on many iOS devices soon, this is not something we can left broken.
After reading a lot of memory management articles I suspect this issue is caused by bad memory alignment. Therefore I suspect rapidjson to be the cause of this bug. My lack of knowledge about memory alignment on iOS / armv7 does not allow me to fix this crashlog. Can someone explain me more about this subject on iOS? Or am I looking in the wrong place and is this another memory issue?
I hope someone can point me in the right direction.
If more info is needed I am happy to provide it.
Note: I am not looking for answers as using JSONKit or another library to replace rapidjson. Thanks :)
This issue was previously addressed here: https://devforums.apple.com/message/807860
In short, the original Objective-C exception has been released (eg, by an autorelease pool) prior to it being dereferenced in the uncaught exception handler. As such, __handleUncaughtException() dereferences a now-dead pointer, and you see the crash in your exception handler.
First, the address 0xa0000008 does not look misaligned, and SEGV_ACCERR does not mean an alignment problem, but a memory access permission problem (from sys/signal.h):
#define SEGV_ACCERR 2 /* [XSI] invalid permission for mapped object */
Considering you are using class_addMethod() and the crash is in _cache_getImp(), which is part of retrieving a method, my largely unfounded suspicion would be that you passed some invalid pointers to class_addMethod(), or overwrote that information later on.
Something to check would be whether you are using either globals or malloc()ed memory, because the runtime functions do not make copies for you.
Second, the crash you are seeing is secondary, you are crashing while running the top-level exception handler that is already terminating (_objc_terminate()) your program from an earlier exception, but in this case it's not a Unix signal, but an Objective-C exception: objc_exception_rethrow().
So you probably need to figure out that primary error first, for example from logs of the exception (just a backtrace isn't enough in many cases).

Resources