|
|
Wkdunreal
|
Hi,
Am using the native compiler (aCC) to compile.
In my source code at one instance , there is a need for __builtin_return_address to give me the return address of the function.
Using gcc it gets compiled but using aCC I seem to be having a lil bit of problem.
Can someone guide me whether there is a function similar to __builtin_return_address which can give me the function's return address on aCC compiler.
__builtin_return_address(LEVEL)
if i pass LEVEL=1 i get the address of a function a step higher in the stack .
Am using the HP-US 11.31 ia64.
Thanks in advance to all the Stalwarts of this community :)
Regards
|
|
|
Note: If you are the author of this question and wish to assign points to any of the answers, please login first.For more information on assigning points ,click
here
|
|
|
Sort Answers By:
Date or Points
|
|
Dennis Handly
|
|
Nov 2, 2009 08:07:25 GMT
10 pts
|
|
|
|
Wkdunreal
|
|
Nov 2, 2009 09:17:59 GMT
N/A: Question Author
|
|
BINGO!!!!
Thanks Dennis :D Thanks a million The _Asm_get_rp(void); worked.
As soon as I run into other dead ends here will get back here :D.
Thanks again :):):) |
|
|
Wkdunreal
|
|
Nov 4, 2009 10:24:49 GMT
N/A: Question Author
|
|
Hello again :) I seem to have bumped into a problem using _Asm_get_rp().
I created a test shared object file lib.so
#include<stdio.h> #include<dlfcn.h> #include <machine/sys/inline.h>
void mycall() { void *p=_Asm_get_rp(); printf("%lx\n",p); Dl_info info; dladdr(p,&info); printf("%s : %s\n",info.dli_sname,info.dli_fname); }
And i created a try.c that would use this lib.so
#include <machine/sys/inline.h> #include<dlfcn.h> #include<stdio.h> void Iwillallocate(); void func(); main() { func(); }
void func(){ Iwillallocate(); }
void Iwillallocate(){ mycall(); } --------------------------------------------
I am compiling this using aCC Created .so using aCC and all object files.
Te problem that i am facing is... The return function name is coming out as main() instead of Iwillallocate()
Could you please tell me what might I be doing wrong?
Thanks a million Regards |
|
Dennis Handly
|
|
Nov 4, 2009 10:37:03 GMT
9 pts
|
|
>Could you please tell me what might I be doing wrong?
You are optimizing and that inlines everything: $ aCC -AA +DD64 itrc_get_rp.c -g $ a.out 4000000000001290 _Z13Iwillallocatev: ./a.out $ aCC -AA +DD64 itrc_get_rp.c -g +O2 +Oinfo procedure func: info #20023-D: Inlined call to Iwillallocate procedure main: info #20023-D: Inlined call to func $ a.out 4000000000000e80 main: ./a.out
>printf("%lx\n", p);
You should use %p for pointers. |
|
|
Wkdunreal
|
|
Nov 4, 2009 11:08:53 GMT
N/A: Question Author
|
|
Thanks for reply Dennis.
Are you creating a .so file (a library which contains mycall() ) or areyou inclusing mycall() in itrc_get_rp.c itself?
Could you show the exact contents of your vitrc_get_rp.c file?
Cause when I do not create an SO and include all the code in one file itself, it seems to give the right answer...
The problem comes when i create a separate library and try to call functions from this library (as I had shown in the code above.. the lib.c is the library file and try.c is the caller file.)
Thanks and regards |
|
Dennis Handly
|
|
Nov 4, 2009 11:50:46 GMT
9 pts
|
|
>Are you creating a .so file (a library which contains mycall()) or are you including mycall() in itrc_get_rp.c itself?
The latter, the former is too hard. ;-)
>Could you show the exact contents of your vitrc_get_rp.c file?
All of your source in one file.
>when I do not create an SO and include all the code in one file itself, it seems to give the right answer.
Not when I optimize.
>The problem comes when i create a separate library and try to call functions from this library
That only fails when I optimize the executable. You can add +d to stop inlining. |
|
|
Wkdunreal
|
|
Nov 5, 2009 05:37:36 GMT
N/A: Question Author
|
|
:D
I suppose the former is indeed hard, sadly that is the only way I can proceed .... by making a library file....
When using gcc I never had these issues... aCC seems a bit grumpy :|:|
I tried using the +d option as you had suggested... removing the inlining optimization... but then again when trying to use the "library creation method and calling the library function in a caller file" the +d gave the same result always pointing to main....
I really wonder what might be causing this problem ... Is it some other optimization that Is doing this... or maybe the way the .so file is made or called?
Very pinching indeed :|
Thanks a lot Dennis :D:D |
|
Dennis Handly
|
|
Nov 5, 2009 09:33:24 GMT
Unassigned
|
|
>by making a library file.
I couldn't duplicate it when I made a shlib.
>When using gcc I never had these issues... aCC seems a bit grumpy
This likely nothing to do with aC++ if +d doesn't fix it.
>I really wonder what might be causing this problem
You should also use gdb and set a breakpoint where you call _Asm_get_rp and see what it thinks is the caller.
It could be dladdr(3) is broken. |
|