* Menglong Dong:
Hello,
On Mon, Aug 22, 2022 at 4:01 PM Florian Weimer [off-list ref] wrote:
quoted
* Menglong Dong:
quoted
/*
* Used by functions that use '__builtin_return_address'. These function
* don't want to be splited or made inline, which can make
* the '__builtin_return_address' got unexpected address.
*/
#define __fix_address noinline __noclone
You need something on the function *declaration* as well, to inhibit
sibcalls.
I did some research on the 'sibcalls' you mentioned above. Feel like
It's a little similar to 'inline', and makes the callee use the same stack
frame with the caller, which obviously will influence the result of
'__builtin_return_address'.
Hmm......but I'm not able to find any attribute to disable this optimization.
Do you have any ideas?
Unless something changed quite recently, GCC does not allow disabling
the optimization with a simple attribute (which would have to apply to
function pointers as well, not functions). asm ("") barriers that move
out a call out of the tail position are supposed to prevent the
optimization.
Thanks,
Florian
On Tue, Sep 06, 2022 at 02:37:47PM +0200, Florian Weimer wrote:
quoted
On Mon, Aug 22, 2022 at 4:01 PM Florian Weimer [off-list ref] wrote:
I did some research on the 'sibcalls' you mentioned above. Feel like
It's a little similar to 'inline', and makes the callee use the same stack
frame with the caller, which obviously will influence the result of
'__builtin_return_address'.
Sibling calls are essentially calls that can be replaced by jumps (aka
"tail call"), without needing a separate entry point to the callee.
Different targets can have a slightly different implementation and
definition of what exactly is a sibling call, but that's the gist.
quoted
Hmm......but I'm not able to find any attribute to disable this optimization.
Do you have any ideas?
Unless something changed quite recently, GCC does not allow disabling
the optimization with a simple attribute (which would have to apply to
function pointers as well, not functions).
It isn't specified what a sibling call exactly *is*, certainly not on C
level (only in the generated machine code), and the details differs per
target.
asm ("") barriers that move
out a call out of the tail position are supposed to prevent the
optimization.
Not just "supposed": they work 100%. The asm has to stay after the
function call by the fundamental rules of C (the function call having a
sequence point, and the asm a side effect).
void g(void);
void f(void)
{
g(); // This can not be optimised to a jump...
asm(""); // ... because it has to stay before this.
}
Segher