Re: Cocoa and dead-code stripping
Re: Cocoa and dead-code stripping
- Subject: Re: Cocoa and dead-code stripping
- From: Steve Christensen <email@hidden>
- Date: Sun, 1 Jul 2007 19:31:44 -0700
On Jul 1, 2007, at 7:16 PM, Chris Suter wrote:
On 02/07/2007, at 12:05 PM, Steve Christensen wrote:
Since I have a large number of targets that share a bunch of
common code, I currently build a static library with the common
bits and then link that against all of the other targets. This
works pretty well for C++/Carbon.
I'm starting to incorporate Cocoa pieces into the shared library
and was wondering if I'll start running into code bloat if I
create full-featured classes but, for example, only end up using a
couple of methods in a particular target. Does the linker
correctly determine which methods are actually used and just
including them (and methods they call, etc.)?
No, that's impossible. There's no way for the linker to know what
methods might get called.
Or am I going to find that all class methods are included because
the linker can't tell which methods might be called?
Normal linker rules apply for when a module is included in a link
i.e. you have to reference something in a file (e.g. a class name)
before it will be included. Note that calling a method doesn't do
anything for the linker since it's fixed up at run-time.
For that reason you should isolate your code into different files/
modules as much as possible. You might need to be careful to make
sure a file that only has category methods is linked in when required.
So it sounds like, if I want to end up with reasonably-sized code,
that I should create just the classes (and methods) that I need for a
particular task. When I want to do something similar, it sounds like
I should copy the class sources into another target, add some
methods, etc., and then compile/link that version?
By the way, this is the same as for Carbon/C++ since as far as I
know, the OS X linker doesn't support function level linking.
Actually in that case the linker generally knows who's calling what
and can strip out the unused methods and classes. From what I've
seen, gcc still has some issues with this, but at least a lot of
stuff -is- stripped out...
steve
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden