Jump to content
 English      
???en.wpa.text.hpweb2003.home??? ???en.wpa.text.hpweb2003.prodserv??? ???en.wpa.text.hpweb2003.support??? ???en.wpa.text.hpweb2003.solutions??? ???en.wpa.text.hpweb2003.buy???
» ???en.wpa.text.hpweb2003.contact???
     Forums advanced search
HP.com Home
IT Resource Center Forums > HP-UX > general

An __builtin_return_address problem?

» 

IT Resource Center

» Login
» Register
» My profile
» Search knowledge base
» Forums
» Patch database
» Download drivers, software and firmware
» Warranty check
» Support Case Manager
» Software Update Manager
» Training and Education
» More maintenance and support options
» Online help
» Site map

Member icons
 
 HP moderator  HP moderator
 Expert in this area  Expert in this area
Member status
ITRC Pro ITRC Pro
250 points
ITRC Graduate ITRC Graduate
500 points
ITRC Wizard ITRC Wizard
1000 points
ITRC Royalty ITRC Royalty
2500 points
ITRC Pharaoh ITRC Pharaoh
7500 points
Olympian Olympian
20000 points
1-Star Olympian 1-Star Olympian
40000 points
2-Star Olympian 2-Star Olympian
80000 points
»  How to earn points
»  Support forums FAQs
Question status
Magical answer Magical answer
Message with a response that solved the author's question
Favorites status
Add to my favorites Add to my favorites
Delete from my favorites Delete from my favorites
This thread has been closed Thread closed
 

Content starts here
   Create a new message    Receive e-mail notification if a new reply is posted  Reply to this message
Author Subject: An __builtin_return_address problem?      Add to my favorites
Wkdunreal
Nov 2, 2009 07:32:16 GMT   

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 Expert in this area This member has accumulated 40000 or more points
Nov 2, 2009 08:07:25 GMT  10 pts

>whether there is a function similar to __builtin_return_address

Go through the aC++ documentation:
http://www.hp.com/go/cpp
Inline assembly for Itanium-based HP-UX
http://h21007.www2.hp.com/portal/site/dspp/menuitem.863c3e4cbcdc3f3515b49c108973a801/?ciid=4308e2f5bde02110e2f5bde02110275d6e10RCRD
Table 1-7 Miscellaneous Opcodes
Table 1-40 Miscellaneous Opcodes
#include <machine/sys/inline.h>
_Asm_get_rp(void);

>if I pass LEVEL=1 I get the address of a function a step higher in the stack.

Chances are, not even GNU can do any levels higher than 0, except for every simple architectures, like HP 3000.

You'll need to use libunwind to get higher than 0. Your previous thread:
http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1369744
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 Expert in this area This member has accumulated 40000 or more points
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 Expert in this area This member has accumulated 40000 or more points
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 Expert in this area This member has accumulated 40000 or more points
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.
 
Create a new message    Receive e-mail notification if a new reply is posted   Reply to this message
 
 
Printable version
Privacy statement Using this site means you accept its terms
© 2009 Hewlett-Packard Development Company, L.P.