[fpc-devel] Creating a Cocoa Application

Jonas Maebe jonas.maebe at elis.ugent.be
Sun Jan 6 12:36:15 CET 2008

On 06 Jan 2008, at 11:39, Felipe Monteiro de Carvalho wrote:

> I read the corresponding assembler code, but it's *very* confusing.
> The order in which CALL's are made is:
>        // NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
> 	call	L_objc_getClass$stub
> 	call	L_objc_msgSend$stub
> 	call	L_objc_msgSend$stub
>        // The 2 simple procedures afaik
> 	call	L_NSApplicationLoad$stub
> 	call	L_NSRunAlertPanel$stub
>        // [pool release];
> 	call	L_objc_msgSend$stub
> So, getting which procedures are called where isn't that hard, but I
> couldn't understand what is filled on the parameters. Any ideas?

As the API explains, objc_getClass has one parameter: a char* pointing  
to the class name. In this case, the class name is  
"NSAutoreleasePool", and the first parameter is indeed simply a  
pointer to that (null terminated) string.

objc_msgSend wants as first parameter the target (in this case: the  
result of objc_getClass), then the selector for the method to call (a  
selector is simply a char** pointing to the method name here, but for  
forward compatibility it is safer to call  
sel_registerName(fullyQualifiedMethodName) and use its result;  
optimizations can always be done later)


> By the way, what does the instruction "leal" do?? I don't remember
> anything similar from intel intructions tables:
> 	leal	L_OBJC_SELECTOR_REFERENCES_0-"L00000000001$pb"(%ebx), %eax

lea means "load effective address". The "l" suffix in AT&T assembler  
syntax means "long", which always corresponds to "32 bit value".

The construct above is simple PIC. Just search for the symbol before  
the "-" to find out what it references.


More information about the fpc-devel mailing list