New clear Objective-C

I have come here to chew bubblegum and write code ... and I'm all out of bubblegum.

Sunday, February 05, 2006

-fnext-runtime vs. -fgnu-runtime smackdown, #3, symbol tables

While the GNU runtime interface is thrusting it's arms in the air chanting victory to the crowd, the NeXT runtime interface stands up and gives the GNU runtime a one-two punch to the kidneys. Ouch, that's gotta hurt folks. Watch your back GNU runtime interface!

Sometime after the original GNU runtime was written, NeXT added constant strings and protocols to the language. This consisted in a subtle change in the Objective-C symbol table.

Speaking in object code here, an Objective-C program consists of one or more object files (think .o's), inside each object file is an array of Objective-C modules, these modules are the main entry point into the compile time data structures. The runtime is given these modules at startup and it traverses the modules, plucking out selectors, classes, categories, constant strings and protocols to initialize and put in the runtime information.

Each module has some information like a version, size, name and then a symbol table. The symbol table is where the bulk of the information lives.

This is what the symbol table looks like:


typedef struct OBJCSymbolTable {
unsigned long selectorRefCount;
SEL *selectorReferences;
unsigned short classDefCount;
unsigned short categoryDefCount;
#ifndef USE_GNU_RUNTIME
int objectDefCount;
int protocolDefCount;
#endif
void *defs[1]; /* variable size */
} OBJCSymbolTable;


The GNU runtime does not use objectDefCount and protocolDefCount. They never updated to it, no idea why not. But at some point they did add constant strings and protocols, just not here.

Instead of adding objectDefCount, they tacked the constant string information onto the end of defs as a null terminated array. Oof. NeXT runtime gets a backstabbing punch to the left kidney.

Instead of adding protocolDefCount, they initialize protocols off the class structure. This means that a protocol can not exist if it not tied to a class. Oof Oof. The NeXT runtime get in a second punch to the right kidney.

Update: The static instances array in the GNU runtime actually does put Protocols in there, yet there are no other classes supported. So this is the same thing as the NeXT runtime, done differently. Why? GNU runtime still loses.

The worst part about this is that when they added constant strings to the symbol table they actually enhanced the feature so that it could accomodate constants of other classes, array, dictionary, etc. But that never went anywhere. If they had just put the effort into updating the symbol table!

GNU runtime folks, please update the symbol table. Really, it's just not that big of a deal to change. Don't be afraid of change!

Smackdown results;

-fnext-runtime: 2
-fgnu-runtime: 1

0 Comments:

Post a Comment

<< Home