InterposeKit icon indicating copy to clipboard operation
InterposeKit copied to clipboard

Fix crash due to IKTAddSuperImplementationToClass being stripped

Open Thomvis opened this issue 4 years ago • 7 comments

This fixes https://github.com/steipete/InterposeKit/issues/29 for me. I think without the used attribute, the compiler optimizes the function away as it appears to be unused.

Thomvis avatar Mar 28 '21 19:03 Thomvis

This doesn't fix the issue completely, unfortunately. While the crash is gone when build & running from Xcode (even Release configuration), it is still present with a build through TestFlight.

Thomvis avatar Mar 29 '21 19:03 Thomvis

I've pushed a fix that actually works when archiving the app too. It seems that the compiler (or linker?) is eager to strip away IKTAddSuperImplementationToClass as it seems unused. No amount of attributes could convince the compiler to keep it. So that's why I updated the implementation to directly call SuperBuilder.addSuperInstanceMethod. It seems to work, but there must be a good reason why you went with dlopen/dlsym so I guess I'm missing something.

Thomvis avatar Mar 30 '21 18:03 Thomvis

The failed CI tasks answer my question, I think. SuperBuilder has to be a separate target for SPM because it's Objective-C. You don't want it to be a separate target for CocoaPods, so there SuperBuilder is part of the main target. So you can't use import SuperBuilder but instead load the class dynamically.

My fix makes it work for SPM, but breaks it for the Xcode project and CocoaPods. I'm not yet sure how to proceed.

Thomvis avatar Mar 30 '21 18:03 Thomvis

Thanks for this! I'll look into this this week.

steipete avatar Apr 05 '21 08:04 steipete

Any change of merging this pr in repo? We rely on the fix suggested by @Thomvis but we had to use a fork in order to fix crash in our app)

Overcot avatar Oct 05 '21 14:10 Overcot

@steipete any news? this is still occurring as of Swift 5.10

piercifani avatar Apr 03 '24 13:04 piercifani

Same here, I went the fork route with the patch from @Thomvis for now, but having this upstream would be great.

lukaskubanek avatar Apr 04 '24 09:04 lukaskubanek