Avoid setting section offsets if the S_ZEROFILL flag is set #8
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First off, the work done here is absolutely fantastic! 👏🏻 Never got it to fully work for my use-case in the past but with the recent release of Xcode 13.3 beta 1 I could finally get a hint as to what was wrong with my initial attempt:
After a few minutes of thinking I brought out
otool
and had a look. Here's the__DATA
section:It indeed has a non-zero offset and judging by that above error (which I might be reading too much into..) it shouldn't have. Now I just needed to figure out how the tool would be able to know that 🤔
After some sleuthing I realised that the
flags 0x00000001
is the key - if it's set to 1 then it matches theS_ZEROFILL
constant from MachO.loader. Using this info the offset-manipulating code can be changed to avoid setting the offset if theS_ZEROFILL
flag is set:Much to my surprise the above seems to work and the error in Xcode is gone! This also makes the resulting library work for my use-case 🎉
I do realise that the solution might be a bit naïve; it should probably do some bitmask checking on the flags to see if the
S_ZEROFILL
flag is set but that didn't seem to be necessary at least for my use-case 🤔