On 09.08.22 14:49, Ralf Ramsauer wrote:
> At the moment, Jailhouse is - by default - compiled with -Os.
> Nevertheless, at least we should also support other optimisation levels,
> such as -O2, without breaking anything.
>
> Turns out, if we compile Jailhouse with -O2, GCC creates endless loops
> inside memset. What it does - at least on my RISC-V port for example -
> is to emit the following code for memset:
>
>    ffffffdfff00a6be <memset>:
>    ffffffdfff00a6be:       1141                    addi    sp,sp,-16
>    ffffffdfff00a6c0:       e022                    sd      s0,0(sp)
>    ffffffdfff00a6c2:       e406                    sd      ra,8(sp)
>    ffffffdfff00a6c4:       842a                    mv      s0,a0
>    ffffffdfff00a6c6:       c609                    beqz a2,ffffffdfff00a6d0 
> <memset+0x12>
>    ffffffdfff00a6c8:       0ff5f593                zext.b  a1,a1
> -> ffffffdfff00a6cc:       ff3ff0ef                jal ra,ffffffdfff00a6be 
> <memset>
>    ffffffdfff00a6d0:       60a2                    ld      ra,8(sp)
>    ffffffdfff00a6d2:       8522                    mv      a0,s0
>    ffffffdfff00a6d4:       6402                    ld      s0,0(sp)
>    ffffffdfff00a6d6:       0141                    addi    sp,sp,16
>    ffffffdfff00a6d8:       8082                    ret
>
> In the marked line, we end up in an endless loop. The reason is that gcc
> recognises that we're about to implement a memset, and tries to take the
> shortcut by replacing our implementation by calling - guess what -
> memset. And here we are: endless loop.
>
> I don't know, but this could maybe also happen with -Os if they change
> optimisation strategies.
>
> To avoid issues like this in future, better add -ffreestanding to our
> compiler options. I wonder why we were missing that option in anyway.
>
> Signed-off-by: Ralf Ramsauer <[email protected]>
> ---
>  hypervisor/Makefile | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/hypervisor/Makefile b/hypervisor/Makefile
> index c475b8fd..b35809f5 100644
> --- a/hypervisor/Makefile
> +++ b/hypervisor/Makefile
> @@ -32,7 +32,7 @@ KBUILD_CFLAGS := -g -ggdb -gdwarf-3 -O0 -Wall -Wextra 
> -Wno-unused-parameter \
>                -Wnested-externs -Wshadow -Wredundant-decls \
>                -Wundef -Wdeprecated \
>                -fno-strict-aliasing -fno-pic -fno-common \
> -              -fno-stack-protector -fno-builtin-ffsl \
> +              -fno-stack-protector -fno-builtin-ffsl -ffreestanding \
>                -D__LINUX_COMPILER_TYPES_H
>
>  include $(src)/arch/$(SRCARCH)/Makefile

Thanks, applied.

Jan

-- 
You received this message because you are subscribed to the Google Groups 
"Jailhouse" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/jailhouse-dev/7cd2922f-5553-4dfa-3a79-edaa6c642bdb%40web.de.

Reply via email to