Hi Andrew, It is a good point, see the updated patch. BTW: The patch focus on return address function and is not going to add macro for __builtin_frame_address, or other built in functions.
Thanks, Star From: Andrew Fish [mailto:af...@apple.com] Sent: Sunday, November 09, 2014 6:06 AM To: edk2-devel@lists.sourceforge.net Subject: Re: [edk2] [PATCH] Add RETURN_ADDRESS macro into Base.h On compilers, like clang, that support frame pointers it is possible to walk the frame programmatically. So __builtin_return_address(n) works on the entire frame. So why don’t we add an argument to RETURN_ADDRESS(). For VC++ you can do this: #define RETURN_ADDRESS(_level) ((_level == 0) ? _ReturnAddress() : 0) We should also add FRAME_ADDRESS() __builtin_frame_address Thanks, Andrew Fish On Nov 7, 2014, at 3:04 AM, Zeng, Star <star.z...@intel.com<mailto:star.z...@intel.com>> wrote: Hi, Please help review this patch. MdePkg: Add RETURN_ADDRESS macro into Base.h Based on compiler intrinsic function. MSVC: _ReturnAddress GCC: __builtin_return_address Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Zeng, Star <star.z...@intel.com<mailto:star.z...@intel.com>> Index: MdePkg/Include/Base.h =================================================================== --- MdePkg/Include/Base.h (revision 16230) +++ MdePkg/Include/Base.h (working copy) @@ -6,7 +6,7 @@ environment. There are a set of base libraries in the Mde Package that can be used to implement base modules. -Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR> +Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR> Portions copyright (c) 2008 - 2009, Apple Inc. All rights reserved.<BR> This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License @@ -1016,5 +1016,26 @@ #define SIGNATURE_64(A, B, C, D, E, F, G, H) \ (SIGNATURE_32 (A, B, C, D) | ((UINT64) (SIGNATURE_32 (E, F, G, H)) << 32)) +#if defined(_MSC_EXTENSIONS) + // + // Intrinsic function provides the address of the instruction in the calling + // function that will be executed after control returns to the caller. + // + #pragma intrinsic(_ReturnAddress) + #define RETURN_ADDRESS _ReturnAddress() +#elif defined(__GNUC__) + // + // Built-in Function returns the return address of the current function, + // or of one of its callers. + // + void * __builtin_return_address (unsigned int level); + #define RETURN_ADDRESS __builtin_return_address (0) +#else + // + // Compilers don't support this feature. + // + #define RETURN_ADDRESS ((VOID *) 0) #endif +#endif + <RETURN_ADDRESS.patch>------------------------------------------------------------------------------ _______________________________________________ edk2-devel mailing list edk2-devel@lists.sourceforge.net<mailto:edk2-devel@lists.sourceforge.net> https://lists.sourceforge.net/lists/listinfo/edk2-devel
RETURN_ADDRESS_v2.patch
Description: RETURN_ADDRESS_v2.patch
------------------------------------------------------------------------------
_______________________________________________ edk2-devel mailing list edk2-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/edk2-devel