Re: Callling clib from assembly language
Re: Callling clib from assembly language
- Subject: Re: Callling clib from assembly language
- From: Matt Watson <email@hidden>
- Date: Fri, 14 Apr 2006 13:17:51 -0700
That's a fine way to do it for non-PIC executables.
Your code is identical to the following when compiled under GCC with -
mdynamic-no-pic:
#include <math.h>
static double (*mysqrtptr)(double) = sqrt;
double mysqrt(double d)
{
return mysqrtptr(d);
}
On Apr 14, 2006, at 12:53 PM, David N. Williams wrote:
I'm porting the assembly language part of a Forth compiler
(kForth) to OS X ppc. This is my first serious attempt at ppc
assembly language programming. I've been using a "simplified"
linkage to clib functions, which is contrasted with the normal
linkage below.
My question is, what are the disadvantages of my approach? I'm
wondering whether I'm going to regret not having done it the
normal way, somewhere down the line!
-- David W.
Here's the gcc 4.0.1 assembly language output for a C call to
sqrt():
----------------------
...
bl L_sqrt$stub
...
.section
__TEXT,__picsymbolstub1,symbol_stubs,pure_instructions,32
.align 5
L_sqrt$stub:
.indirect_symbol _sqrt
mflr r0
bcl 20,31,"L00000000001$spb"
"L00000000001$spb":
mflr r11
addis r11,r11,ha16(L_sqrt$lazy_ptr-"L00000000001$spb")
mtlr r0
lwzu r12,lo16(L_sqrt$lazy_ptr-"L00000000001$spb")(r11)
mtctr r12
bctr
.lazy_symbol_pointer
L_sqrt$lazy_ptr:
.indirect_symbol _sqrt
.long dyld_stub_binding_helper
----------------------
Here's what I'm using:
---------------------
.data
kf_sqrt: .long _sqrt
.text
...
addis r2,0,ha16(kf_sqrt)
lwz r0,lo16(kf_sqrt)(r2)
mtctr r0
bctrl
...
---------------------
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Darwin-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden