Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

_AddressOfReturnAddress() equivalent in Clang/LLVM?

Visual C++ has an intrinsic function called _AddressOfReturnAddress which returns the address of the current function's return address on the stack.

Note that this is not the same as _ReturnAddress, which only returns a copy of the return address.

Is there any equivalent for _AddressOfReturnAddress in Clang/LLVM?

like image 485
user541686 Avatar asked Apr 11 '13 08:04

user541686


2 Answers

As rustyx pointed out, Clang/LLVM (and gcc) provides __builtin_return_address() which is equivalent to _ReturnAddress(). Clang/LLVM also provides __builtin_frame_address() which (depending on the particulars of your ABI, architecture, etc.) may be somewhat analogous to _AddressOfReturnAddress().

As an example, the following code...

std::cout<< ((int64_t) __builtin_return_address(0)) << ' '
         << ((int64_t) __builtin_frame_address (0)) << ' '
         <<*((int64_t*)__builtin_frame_address (0)+1)<<'\n';

...prints the following on an OSX machine.

140735807202733 140734600362944 140735807202733
like image 194
ceilingcat Avatar answered Sep 26 '22 01:09

ceilingcat


No. LLVM IR does not provide an intrinsic for this.

like image 40
Michael Spencer Avatar answered Sep 26 '22 01:09

Michael Spencer