diff mbox series

[v2,01/16] powerpc: Replace unreachable() with it's builtin variant in __WARN_FLAGS()

Message ID 20220829055223.24767-2-sv@linux.ibm.com (mailing list archive)
State Superseded
Headers show
Series objtool: Enable and implement --mcount option on powerpc | expand

Commit Message

Sathvika Vasireddy Aug. 29, 2022, 5:52 a.m. UTC
objtool is throwing *unannotated intra-function call* warnings in
.c files with a few instructions that are marked unreachable. The
problem comes from the annotate_unreachable() macro that is
called by unreachable(). This annotation is adding a call to a
function with size 0, and objtool does not add such symbols
to the rbtree. Due to this reason, find_call_destination() function
is not able to find the destination symbol for that call.

With the annotation (annotate_unreachable()), gcc seems to
generate a 'bl' to unreachable symbol with size 0. But with
the builtin variant of unreachable (__builtin_unreachable()),
gcc does not emit calls to such symbols and the warnings
go away. Given that the codegen remains same, and that
there are no 'bl' instructions to such symbols emitted, fix
these warnings by replacing unreachable() with it's builtin
variant in __WARN_FLAGS().

Also, add barrier_before_unreachable() before __builtin_unreachable()
to work around a gcc bug [1], for the problem reported at [2].

[1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106751
[2]: https://lkml.org/lkml/2022/8/25/418

Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>
---
 arch/powerpc/include/asm/bug.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Comments

Christophe Leroy Aug. 30, 2022, 6:15 a.m. UTC | #1
Le 29/08/2022 à 07:52, Sathvika Vasireddy a écrit :
> objtool is throwing *unannotated intra-function call* warnings in
> .c files with a few instructions that are marked unreachable. The
> problem comes from the annotate_unreachable() macro that is
> called by unreachable(). This annotation is adding a call to a
> function with size 0, and objtool does not add such symbols
> to the rbtree. Due to this reason, find_call_destination() function
> is not able to find the destination symbol for that call.
> 
> With the annotation (annotate_unreachable()), gcc seems to
> generate a 'bl' to unreachable symbol with size 0. But with
> the builtin variant of unreachable (__builtin_unreachable()),
> gcc does not emit calls to such symbols and the warnings
> go away. Given that the codegen remains same, and that
> there are no 'bl' instructions to such symbols emitted, fix
> these warnings by replacing unreachable() with it's builtin
> variant in __WARN_FLAGS().

How can you say that the codegen remains the same if with the original 
you get stale 'bl' instructions and with the alternative you don't ?

> 
> Also, add barrier_before_unreachable() before __builtin_unreachable()
> to work around a gcc bug [1], for the problem reported at [2].

Here my comment was not related to the gcc bug [1] but to gcc bug 
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82365 , which was worked 
around by commit 173a3efd3edb ("bug.h: work around GCC PR82365 in BUG()")

By chance it also solve the problem [1] as you mention.

> 
> [1]: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106751
> [2]: https://lkml.org/lkml/2022/8/25/418
> 
> Signed-off-by: Sathvika Vasireddy <sv@linux.ibm.com>

Reviewed-by: Christophe Leroy <christophe.leroy@csgroup.eu>

> ---
>   arch/powerpc/include/asm/bug.h | 3 ++-
>   1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/arch/powerpc/include/asm/bug.h b/arch/powerpc/include/asm/bug.h
> index 61a4736355c2..ef42adb44aa3 100644
> --- a/arch/powerpc/include/asm/bug.h
> +++ b/arch/powerpc/include/asm/bug.h
> @@ -99,7 +99,8 @@
>   	__label__ __label_warn_on;				\
>   								\
>   	WARN_ENTRY("twi 31, 0, 0", BUGFLAG_WARNING | (flags), __label_warn_on); \
> -	unreachable();						\
> +	barrier_before_unreachable();				\
> +	__builtin_unreachable();				\
>   								\
>   __label_warn_on:						\
>   	break;							\
Naveen N. Rao Sept. 5, 2022, 10:18 a.m. UTC | #2
Christophe Leroy wrote:
> 
> 
> Le 29/08/2022 à 07:52, Sathvika Vasireddy a écrit :
>> objtool is throwing *unannotated intra-function call* warnings in
>> .c files with a few instructions that are marked unreachable. The
>> problem comes from the annotate_unreachable() macro that is
>> called by unreachable(). This annotation is adding a call to a
>> function with size 0, and objtool does not add such symbols
>> to the rbtree. Due to this reason, find_call_destination() function
>> is not able to find the destination symbol for that call.
>> 
>> With the annotation (annotate_unreachable()), gcc seems to
>> generate a 'bl' to unreachable symbol with size 0. But with
>> the builtin variant of unreachable (__builtin_unreachable()),
>> gcc does not emit calls to such symbols and the warnings
>> go away. Given that the codegen remains same, and that
>> there are no 'bl' instructions to such symbols emitted, fix
>> these warnings by replacing unreachable() with it's builtin
>> variant in __WARN_FLAGS().
> 
> How can you say that the codegen remains the same if with the original 
> you get stale 'bl' instructions and with the alternative you don't ?

I guess the reference to codegen remaining the same is more to do with 
unreachable vs. __builtin_unreachable() in the absence of 
CONFIG_OBJTOOL. But yeah, the changelog needs to be reworked to clarify 
that.

> 
>> 
>> Also, add barrier_before_unreachable() before __builtin_unreachable()
>> to work around a gcc bug [1], for the problem reported at [2].
> 
> Here my comment was not related to the gcc bug [1] but to gcc bug 
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82365 , which was worked 
> around by commit 173a3efd3edb ("bug.h: work around GCC PR82365 in BUG()")
> 
> By chance it also solve the problem [1] as you mention.

That's a good commit to reference, but please also retain a link to the 
new PR.


- Naveen
diff mbox series

Patch

diff --git a/arch/powerpc/include/asm/bug.h b/arch/powerpc/include/asm/bug.h
index 61a4736355c2..ef42adb44aa3 100644
--- a/arch/powerpc/include/asm/bug.h
+++ b/arch/powerpc/include/asm/bug.h
@@ -99,7 +99,8 @@ 
 	__label__ __label_warn_on;				\
 								\
 	WARN_ENTRY("twi 31, 0, 0", BUGFLAG_WARNING | (flags), __label_warn_on); \
-	unreachable();						\
+	barrier_before_unreachable();				\
+	__builtin_unreachable();				\
 								\
 __label_warn_on:						\
 	break;							\