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

Fix crash due to IKTAddSuperImplementationToClass being stripped #30

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Thomvis
Copy link

@Thomvis Thomvis commented Mar 28, 2021

This fixes #29 for me. I think without the used attribute, the compiler optimizes the function away as it appears to be unused.

@Thomvis
Copy link
Author

Thomvis commented Mar 29, 2021

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 Thomvis changed the title Mark IKTAddSuperImplementationToClass as used Fix crash due to IKTAddSuperImplementationToClass being stripped Mar 30, 2021
@Thomvis
Copy link
Author

Thomvis commented Mar 30, 2021

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
Copy link
Author

Thomvis commented Mar 30, 2021

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.

@steipete
Copy link
Owner

steipete commented Apr 5, 2021

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

@Overcot
Copy link

Overcot commented Oct 5, 2021

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)

lukaskubanek pushed a commit to structuredpath/InterposeKit that referenced this pull request Nov 28, 2023
@piercifani
Copy link

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

@lukaskubanek
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IKTAddSuperImplementationToClass cannot be found on device/release config
5 participants