* [PATCH] gcc-plugins/stackleak: Avoid assignment for unused macro argument
@ 2020-04-02 8:10 Kees Cook
2020-04-07 15:30 ` Alexander Popov
0 siblings, 1 reply; 3+ messages in thread
From: Kees Cook @ 2020-04-02 8:10 UTC (permalink / raw)
To: kernel-hardening; +Cc: Alexander Popov, Emese Revfy, linux-kernel
With GCC version >= 8, the cgraph_create_edge() macro argument using
"frequency" goes unused. Instead of assigning a temporary variable for
the argument, pass the compute_call_stmt_bb_frequency() call directly
as the macro argument so that it will just not be uncalled when it is
not wanted by the macros.
Silences the warning:
scripts/gcc-plugins/stackleak_plugin.c:54:6: warning: variable ‘frequency’ set but not used [-Wunused-but-set-variable]
Now builds cleanly with gcc-7 and gcc-9. Both boot and pass
STACKLEAK_ERASING LKDTM test.
Signed-off-by: Kees Cook <keescook@chromium.org>
---
scripts/gcc-plugins/stackleak_plugin.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/scripts/gcc-plugins/stackleak_plugin.c b/scripts/gcc-plugins/stackleak_plugin.c
index dbd37460c573..cc75eeba0be1 100644
--- a/scripts/gcc-plugins/stackleak_plugin.c
+++ b/scripts/gcc-plugins/stackleak_plugin.c
@@ -51,7 +51,6 @@ static void stackleak_add_track_stack(gimple_stmt_iterator *gsi, bool after)
gimple stmt;
gcall *stackleak_track_stack;
cgraph_node_ptr node;
- int frequency;
basic_block bb;
/* Insert call to void stackleak_track_stack(void) */
@@ -68,9 +67,9 @@ static void stackleak_add_track_stack(gimple_stmt_iterator *gsi, bool after)
bb = gimple_bb(stackleak_track_stack);
node = cgraph_get_create_node(track_function_decl);
gcc_assert(node);
- frequency = compute_call_stmt_bb_frequency(current_function_decl, bb);
cgraph_create_edge(cgraph_get_node(current_function_decl), node,
- stackleak_track_stack, bb->count, frequency);
+ stackleak_track_stack, bb->count,
+ compute_call_stmt_bb_frequency(current_function_decl, bb));
}
static bool is_alloca(gimple stmt)
--
2.20.1
--
Kees Cook
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] gcc-plugins/stackleak: Avoid assignment for unused macro argument
2020-04-02 8:10 [PATCH] gcc-plugins/stackleak: Avoid assignment for unused macro argument Kees Cook
@ 2020-04-07 15:30 ` Alexander Popov
2020-04-07 16:33 ` Kees Cook
0 siblings, 1 reply; 3+ messages in thread
From: Alexander Popov @ 2020-04-07 15:30 UTC (permalink / raw)
To: Kees Cook, kernel-hardening; +Cc: Emese Revfy, linux-kernel
Hello Kees,
On 02.04.2020 11:10, Kees Cook wrote:
> With GCC version >= 8, the cgraph_create_edge() macro argument using
> "frequency" goes unused. Instead of assigning a temporary variable for
> the argument, pass the compute_call_stmt_bb_frequency() call directly
> as the macro argument so that it will just not be uncalled when it is
> not wanted by the macros.
Do you mean "it will just not be called"?
Thanks!
> Silences the warning:
>
> scripts/gcc-plugins/stackleak_plugin.c:54:6: warning: variable ‘frequency’ set but not used [-Wunused-but-set-variable]
>
> Now builds cleanly with gcc-7 and gcc-9. Both boot and pass
> STACKLEAK_ERASING LKDTM test.
>
> Signed-off-by: Kees Cook <keescook@chromium.org>
> ---
> scripts/gcc-plugins/stackleak_plugin.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/scripts/gcc-plugins/stackleak_plugin.c b/scripts/gcc-plugins/stackleak_plugin.c
> index dbd37460c573..cc75eeba0be1 100644
> --- a/scripts/gcc-plugins/stackleak_plugin.c
> +++ b/scripts/gcc-plugins/stackleak_plugin.c
> @@ -51,7 +51,6 @@ static void stackleak_add_track_stack(gimple_stmt_iterator *gsi, bool after)
> gimple stmt;
> gcall *stackleak_track_stack;
> cgraph_node_ptr node;
> - int frequency;
> basic_block bb;
>
> /* Insert call to void stackleak_track_stack(void) */
> @@ -68,9 +67,9 @@ static void stackleak_add_track_stack(gimple_stmt_iterator *gsi, bool after)
> bb = gimple_bb(stackleak_track_stack);
> node = cgraph_get_create_node(track_function_decl);
> gcc_assert(node);
> - frequency = compute_call_stmt_bb_frequency(current_function_decl, bb);
> cgraph_create_edge(cgraph_get_node(current_function_decl), node,
> - stackleak_track_stack, bb->count, frequency);
> + stackleak_track_stack, bb->count,
> + compute_call_stmt_bb_frequency(current_function_decl, bb));
> }
>
> static bool is_alloca(gimple stmt)
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] gcc-plugins/stackleak: Avoid assignment for unused macro argument
2020-04-07 15:30 ` Alexander Popov
@ 2020-04-07 16:33 ` Kees Cook
0 siblings, 0 replies; 3+ messages in thread
From: Kees Cook @ 2020-04-07 16:33 UTC (permalink / raw)
To: Alexander Popov; +Cc: kernel-hardening, Emese Revfy, linux-kernel
On Tue, Apr 07, 2020 at 06:30:18PM +0300, Alexander Popov wrote:
> Hello Kees,
>
> On 02.04.2020 11:10, Kees Cook wrote:
> > With GCC version >= 8, the cgraph_create_edge() macro argument using
> > "frequency" goes unused. Instead of assigning a temporary variable for
> > the argument, pass the compute_call_stmt_bb_frequency() call directly
> > as the macro argument so that it will just not be uncalled when it is
> > not wanted by the macros.
>
> Do you mean "it will just not be called"?
I really did. ;) Thanks, I'll adjust this.
-Kees
>
> Thanks!
>
> > Silences the warning:
> >
> > scripts/gcc-plugins/stackleak_plugin.c:54:6: warning: variable ‘frequency’ set but not used [-Wunused-but-set-variable]
> >
> > Now builds cleanly with gcc-7 and gcc-9. Both boot and pass
> > STACKLEAK_ERASING LKDTM test.
> >
> > Signed-off-by: Kees Cook <keescook@chromium.org>
> > ---
> > scripts/gcc-plugins/stackleak_plugin.c | 5 ++---
> > 1 file changed, 2 insertions(+), 3 deletions(-)
> >
> > diff --git a/scripts/gcc-plugins/stackleak_plugin.c b/scripts/gcc-plugins/stackleak_plugin.c
> > index dbd37460c573..cc75eeba0be1 100644
> > --- a/scripts/gcc-plugins/stackleak_plugin.c
> > +++ b/scripts/gcc-plugins/stackleak_plugin.c
> > @@ -51,7 +51,6 @@ static void stackleak_add_track_stack(gimple_stmt_iterator *gsi, bool after)
> > gimple stmt;
> > gcall *stackleak_track_stack;
> > cgraph_node_ptr node;
> > - int frequency;
> > basic_block bb;
> >
> > /* Insert call to void stackleak_track_stack(void) */
> > @@ -68,9 +67,9 @@ static void stackleak_add_track_stack(gimple_stmt_iterator *gsi, bool after)
> > bb = gimple_bb(stackleak_track_stack);
> > node = cgraph_get_create_node(track_function_decl);
> > gcc_assert(node);
> > - frequency = compute_call_stmt_bb_frequency(current_function_decl, bb);
> > cgraph_create_edge(cgraph_get_node(current_function_decl), node,
> > - stackleak_track_stack, bb->count, frequency);
> > + stackleak_track_stack, bb->count,
> > + compute_call_stmt_bb_frequency(current_function_decl, bb));
> > }
> >
> > static bool is_alloca(gimple stmt)
> >
>
--
Kees Cook
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-04-07 16:33 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-02 8:10 [PATCH] gcc-plugins/stackleak: Avoid assignment for unused macro argument Kees Cook
2020-04-07 15:30 ` Alexander Popov
2020-04-07 16:33 ` Kees Cook
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).