tinycc-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tinycc-devel] '__builtin_frame_address' warning about suspicious use of


From: Christian Jullien
Subject: [Tinycc-devel] '__builtin_frame_address' warning about suspicious use of this call
Date: Tue, 29 Nov 2016 06:51:03 +0100

I open a new thread for this issue since multi-arch is fixed.

 

On Fedora 25 with gcc 6.2 I get this warning which is new:

 

bcheck.c: In function ‘__bound_local_new’:

bcheck.c:240:18: warning: calling ‘__builtin_frame_address’ with a nonzero argument is unsafe [-Wframe-address]

     fp = (size_t)__builtin_frame_address(1);\

                  ^~~~~~~~~~~~~~~~~~~~~~~~~~

bcheck.c:249:5: note: in expansion of macro ‘GET_CALLER_FP’

     GET_CALLER_FP(fp);

     ^~~~~~~~~~~~~

bcheck.c: In function ‘__bound_local_delete’:

bcheck.c:240:18: warning: calling ‘__builtin_frame_address’ with a nonzero argument is unsafe [-Wframe-address]

     fp = (size_t)__builtin_frame_address(1);\

                  ^~~~~~~~~~~~~~~~~~~~~~~~~~

bcheck.c:266:5: note: in expansion of macro ‘GET_CALLER_FP’

     GET_CALLER_FP(fp);

     ^~~~~~~~~~~~~

 

GCC documentation says:

 

— Built-in Function: void * __builtin_return_address (unsigned int level)

This function returns the return address of the current function, or of one of its callers. The level argument is number of frames to scan up the call stack. A value of 0 yields the return address of the current function, a value of 1 yields the return address of the caller of the current function, and so forth. When inlining the expected behavior is that the function returns the address of the function that is returned to. To work around this behavior use the noinline function attribute.

The level argument must be a constant integer.

On some machines it may be impossible to determine the return address of any function other than the current one; in such cases, or when the top of the stack has been reached, this function returns 0 or a random value. In addition, __builtin_frame_address may be used to determine if the top of the stack has been reached.

Additional post-processing of the returned value may be needed, see __builtin_extract_return_addr.

Calling this function with a nonzero argument can have unpredictable effects, including crashing the calling program. As a result, calls that are considered unsafe are diagnosed when the -Wframe-address option is in effect. Such calls should only be made in debugging situations.

^^^^^ This latest sentence makes me afraid!

 

Two questions here:

Q1. Should we really call this function with one arg?

 

Q2. If safe, we should make this change to avoid this warning:

 

diff --git a/lib/bcheck.c b/lib/bcheck.c

index 756c539..8a75654 100644

--- a/lib/bcheck.c

+++ b/lib/bcheck.c

@@ -240,6 +240,9 @@ BOUND_PTR_INDIR(16)

     fp = (size_t)__builtin_frame_address(1);\

}

+#pragma GCC diagnostic push

+#pragma GCC diagnostic ignored "-Wframe-address"

+

/* called when entering a function to add all the local regions */

void FASTCALL __bound_local_new(void *p1)

 {

@@ -273,6 +276,7 @@ void FASTCALL __bound_local_delete(void *p1)

         __bound_delete_region((void *)addr);

     }

}

+#pragma GCC diagnostic pop

 static BoundEntry *__bound_new_page(void)

{


reply via email to

[Prev in Thread] Current Thread [Next in Thread]