In an older version of a framework there were two class, A and B, with A being a subclass of B. In the newer version B no longer exists and everything in B (ivars etc.) is now in A. An executable file is linked against the old version, so it looks for _OBJC_IVAR_$_B.ivar. However I need to it work on the new version (I can't recompile it). So is there a way to change the reference to _OBJC_IVAR_$_A.ivar?
1 Answers
There is no way to do this safely. Not only does the symbol need to be resolved, but the runtime is likely to trip over that symbol. Symbol aliasing may work, but it'll be fragile.
The executable that depends on the older version of framework to the point of referring to an ivar symbol directly will require the class layouts to be compatible and that includes having that subclass with those ivars.
When Objective-C "2.0" solved the fragile base class problem, it did not add the ability to move ivars from class to class (because both A and B could have an ivar of the same name -- perfectly valid, though suspect).
If you absolutely must go down this path, you can try aliasing the symbol in the link line. Add an appropriate alias flag to OTHER_LD_FLAGS in the build settings editor:
-alias symbol_name alternate_symbol_name
Create an alias named alternate_symbol_name for the symbol symbol_name. By default the
alias symbol has global visibility. This option was previous the -idef:indir option.

- 162,346
- 23
- 271
- 359
-
I don't mean moving the ivar, I mean changing which class the executable refers to (since B no longer exists) – user1000039 Jun 21 '13 at 16:48
-
1Doesn't matter; it is still the same problem. There may be a way to alias the symbol in the linker (search for the linker documentation at developer.apple.com), but down that path lies madness in that it is quite thoroughly an unsupported thing to do and will very likely break. – bbum Jun 21 '13 at 17:17
-
Well I'm able to change it in a hex editor assuming the names of A and B are of the same length. I'm assuming there's a value somewhere with the length of the string I need to change – user1000039 Jun 21 '13 at 17:18
-
1It may not be as simple as merely changing the symbol name; there may likely be other dependencies throughout the relatively complicated structure of information that describes the symbol. You really *really* don't want to ship a product that relies on this kind of shenanigans! – bbum Jun 21 '13 at 17:23