Is it bad to enable Dead Code Stripping?
Asked Answered
A

0

6

My iOS project uses dlsym to dynamically point to an optional C library. Optional as-in the project can run with our without it, it just adds features.

For background info: Detect and use optional external C library at runtime in Objective-C

The problem is, XCode cleans up libraries that are "not used". Using dlsym means there are no direct references to my 3rd party library and XCode removes it.

I thought I found a solution, in "Other Linker Flags" I added -force_load "$(SRCROOT)/my_external.a" which worked great in the simulator. (-all_load works fine too but seemed overkill to me).

The problem is when I moved to a real device, this workaround failed and the library is not loaded (same thing with -all_load).

The only thing that worked was to disable in XCode the feature called Dead Code Stripping.

Question is: is it really bad to disable or recommend my customers to disable this feature? If so, is there a better alternative?

Arithmomancy answered 1/5, 2014 at 9:32 Comment(5)
is it really bad to disable or recommend my customers to disable this feature? Are the customers expected to build the programs themselves? If so I would say that the customer in this case is also a developer. Therefore I don't see a problem on giving developer instructions on how to build the program within the supported build environment (XCode).Verlinevermeer
Yes customers are developers, I give them a library.Arithmomancy
If the customers are developers, then telling them special instructions on how to build it should not be a problem. On the other hand, with experimentation you could probably find a clever way to make sure that your code does not get stripped even if the builder forgets to disable the "Dead Code Stripping" option.Verlinevermeer
My question was more in the line of, is there a potential problem with disabling "dead code stripping" since it is enabled by Apple by default, - not really "is it fair to ask..."Arithmomancy
Dead code stripping removes code that the compiler determines is unreachable. If you include lots of functions and code blocks in your shipped code which never get executed, then the dead code stripping could possibly remove those and produce a smaller binary. On the other hand, if your code has little or no "unreachable code", then whether dead code stripping is enabled or not should not make any difference. As a solution couldn't you provide both the source with build instructions and a binary to your customers?Verlinevermeer

© 2022 - 2024 — McMap. All rights reserved.