Bug 96307 - [10 Regression] ICE in sanopt on riscv64 since r11-2283-g2ca1b6d009b194286c3ec91f9c51cc6b0a475458
Summary: [10 Regression] ICE in sanopt on riscv64 since r11-2283-g2ca1b6d009b194286c3e...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: sanitizer (show other bugs)
Version: 11.0
: P4 normal
Target Milestone: 10.2
Assignee: Kito Cheng
URL:
Keywords: ice-on-valid-code
Depends on:
Blocks:
 
Reported: 2020-07-24 09:44 UTC by Martin Liška
Modified: 2023-07-07 08:58 UTC (History)
7 users (show)

See Also:
Host:
Target: riscv
Build:
Known to work: 10.2.0
Known to fail: 10.2.1
Last reconfirmed: 2020-07-24 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liška 2020-07-24 09:44:47 UTC
I see the following ICE with a cross compiler:

$ riscv64-linux-gnu-gcc /home/marxin/Programming/gcc/gcc/testsuite/gcc.dg/lto/c-compatible-types-1_1.c -fsanitize=kernel-address --param=asan-instrumentation-with-call-threshold=8
during GIMPLE pass: sanopt
/home/marxin/Programming/gcc/gcc/testsuite/gcc.dg/lto/c-compatible-types-1_1.c: In function ‘t’:
/home/marxin/Programming/gcc/gcc/testsuite/gcc.dg/lto/c-compatible-types-1_1.c:9:1: internal compiler error: Segmentation fault
    9 | t()
      | ^
0xae236f crash_signal
	/home/marxin/BIG/buildbot/buildworker/marxinbox-gcc-trunk-riscv64/build/gcc/toplev.c:328
0x7ffff78d752f ???
	/usr/src/debug/glibc-2.31-6.1.x86_64/signal/../sysdeps/unix/sysv/linux/x86_64/sigaction.c:0
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Comment 1 Kito Cheng 2020-07-24 09:57:31 UTC
Confirmed, thanks for report that :)
Comment 2 Jim Wilson 2020-08-05 03:52:46 UTC
It is calling targetm.asan_shadow_offset which is a null function pointer currently for RISC-V.  This is related to Kito's recent patch to re-enable ksan support when asan_shadow_offset isn't defined.  But it looks like there are multiple params that can cause asan_shadow_offset to be called for ksan when it normally isn't.  So this change may need to be removed.

Good news is that we have a patch to add asan support for RISC-V which would make Kito's toplev.c patch unnecessary for us.
Comment 3 Martin Liška 2020-09-21 10:38:25 UTC
May I ask about progress of the RISC-V sanitization enablement?
Comment 4 Kito Cheng 2020-09-21 15:33:24 UTC
ASAN related patches are seems need take more time than expect, I plan to fix that this week, and I think ASAN is a new feature so that it won't back port to GCC 10.
Comment 5 Kito Cheng 2020-10-16 06:13:29 UTC
Patch posted, waiting for review: 
https://gcc.gnu.org/pipermail/gcc-patches/2020-October/555482.html
Comment 6 GCC Commits 2020-11-06 03:23:15 UTC
The master branch has been updated by Kito Cheng <kito@gcc.gnu.org>:

https://gcc.gnu.org/g:65e82636bcdb72a878c2e53943e71b15dd9fb22d

commit r11-4762-g65e82636bcdb72a878c2e53943e71b15dd9fb22d
Author: Kito Cheng <kito.cheng@sifive.com>
Date:   Mon Oct 5 14:01:04 2020 +0800

    PR target/96307: Fix KASAN option checking.
    
     - Disable kasan if target is unsupported and -fasan-shadow-offset= is not
       given, no matter `--param asan-stack=1` is given or not.
    
     - Moving KASAN option checking testcase to gcc.dg, those testcase could be
       useful for all other target which not support asan.
    
     - Verifed on riscv and x86.
    
    gcc/ChangeLog:
    
            PR target/96307
            * toplev.c (process_options): Remove param_asan_stack checking for kasan
            option checking.
    
    gcc/testsuite/ChangeLog:
    
            PR target/96307
            * gcc.dg/pr96307.c: New.
            * gcc.target/riscv/pr96260.c: Move this test case from here to ...
            * gcc.dg/pr96260.c: ... here.
            * gcc.target/riscv/pr91441.c: Move this test case from here to ...
            * gcc.dg/pr91441.c: ... here.
            * lib/target-supports.exp (check_effective_target_no_fsanitize_address):
            New proc.
Comment 7 Kito Cheng 2020-11-06 03:35:48 UTC
Committed fix into trunk, wait one week to commit to gcc 10 branh.
Comment 8 GCC Commits 2021-02-01 09:43:41 UTC
The releases/gcc-10 branch has been updated by Kito Cheng <kito@gcc.gnu.org>:

https://gcc.gnu.org/g:037a02be13d24f3be65480b50c58c7f6cf654f9a

commit r10-9329-g037a02be13d24f3be65480b50c58c7f6cf654f9a
Author: Kito Cheng <kito.cheng@sifive.com>
Date:   Mon Oct 5 14:01:04 2020 +0800

    PR target/96307: Fix KASAN option checking.
    
     - Disable kasan if target is unsupported and -fasan-shadow-offset= is not
       given, no matter `--param asan-stack=1` is given or not.
    
     - Moving KASAN option checking testcase to gcc.dg, those testcase could be
       useful for all other target which not support asan.
    
     - Verifed on riscv and x86.
    
    gcc/ChangeLog:
    
            PR target/96307
            * toplev.c (process_options): Remove param_asan_stack checking for kasan
            option checking.
    
    gcc/testsuite/ChangeLog:
    
            PR target/96307
            * gcc.dg/pr96307.c: New.
            * gcc.target/riscv/pr96260.c: Move this test case from here to ...
            * gcc.dg/pr96260.c: ... here.
            * gcc.target/riscv/pr91441.c: Move this test case from here to ...
            * gcc.dg/pr91441.c: ... here.
            * lib/target-supports.exp (check_effective_target_no_fsanitize_address):
            New proc.
    
    (cherry picked from commit 65e82636bcdb72a878c2e53943e71b15dd9fb22d)
Comment 9 Kito Cheng 2021-02-02 08:58:43 UTC
Fixed on 10 and trunk.
Comment 10 Andreas Schwab 2021-03-12 14:05:23 UTC
This disables the CC_HAS_KASAN_GENERIC config of the kernel, making KASAN unavailable.
Comment 11 Andreas Schwab 2021-03-12 17:26:12 UTC
Also, the warning text doesn't make sense:

$ gcc -fsanitize=kernel-address -S -xc /dev/null -o /dev/null
cc1: warning: ‘-fsanitize=kernel-address’ with stack protection is not supported without ‘-fasan-shadow-offset=’ for this target
Comment 12 Kito Cheng 2021-03-16 10:37:37 UTC
> This disables the CC_HAS_KASAN_GENERIC config of the kernel, making KASAN unavailable.

Hmmmm, I checked with kernel source code, it only feed -fsanitize=kernel-address during checking, but in fact it must work with -fasan-shadow-offset=, and it does actually, what do you think about fix that on kernel side?

diff --git a/lib/Kconfig.kasan b/lib/Kconfig.kasan
index fba9909e31b7..9a2484132b2d 100644
--- a/lib/Kconfig.kasan
+++ b/lib/Kconfig.kasan
@@ -13,7 +13,7 @@ config HAVE_ARCH_KASAN_VMALLOC
        bool
 
 config CC_HAS_KASAN_GENERIC
-       def_bool $(cc-option, -fsanitize=kernel-address)
+       def_bool $(cc-option, -fsanitize=kernel-address -fasan-shadow-offset=0x1)
 
 config CC_HAS_KASAN_SW_TAGS
        def_bool $(cc-option, -fsanitize=kernel-hwaddress)


> Also, the warning text doesn't make sense:
>
> $ gcc -fsanitize=kernel-address -S -xc /dev/null -o /dev/null
> cc1: warning: ‘-fsanitize=kernel-address’ with stack protection is not supported without ‘-fasan-shadow-offset=’ for this target

That's my fault I didn't update the error message there, that error message was introduced when fixing PR96260, but during fix this PR.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96260
Comment 13 Richard Biener 2021-04-08 12:02:08 UTC
GCC 10.3 is being released, retargeting bugs to GCC 10.4.
Comment 14 Jakub Jelinek 2022-06-28 10:41:23 UTC
GCC 10.4 is being released, retargeting bugs to GCC 10.5.
Comment 15 Richard Biener 2023-07-07 08:58:31 UTC
Fixed in GCC 10.2