This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] -fsanitize=address,undefined support on s390x


On Mon, Jan 23, 2017 at 04:10:01PM +0100, Ulrich Weigand wrote:
> Bill Schmidt wrote:
> > On Jan 23, 2017, at 8:32 AM, Jakub Jelinek <jakub@redhat.com> wrote:
> > >
> > > Another question is, it seems upstream has s390{,x}-*-linux* support for
> > > asan/ubsan, does that work?  In that case we should add it to configure.tgt
> > > too (similarly to the sparc*-*-linux* entry).
> > 
> > CCing Uli for the s390 question.
> 
> Asan support was added just recently to LLVM for s390x-linux.  However,
> I'm not sure it will work out-of-the-box on GCC, since we haven't done any
> back-end work to enable it.  Also, LLVM is 64-bit only, so there probably
> would have to be extra work in the libraries to enable 31-bit mode.

So, I've bootstrapped/regtested s390x-linux (64-bit only, don't have 32-bit
userland around anymore to test 31-bit) with the attached patch (and on top
of the PR79168 patch I'll post soon) and the
only regressions I got are:
FAIL: c-c++-common/asan/null-deref-1.c   {-O2,-O2 -flto -fno-use-linker-plugin -flto-partition=none,-O2 -flto -fuse-linker-plugin -fno-fat-lto-objects,-O3 -g,-Os}  output pattern test
FAIL: g++.dg/asan/deep-stack-uaf-1.C   {-O0,-O1,-O2,-O3 -g,-Os}  output pattern test
FAIL: c-c++-common/ubsan/overflow-vec-1.c   {-O0,-O1,-O2,-O2 -flto -fno-use-linker-plugin -flto-partition=none,-O2 -flto -fuse-linker-plugin -fno-fat-lto-objects,-O3 -g,-Os}  execution test
FAIL: c-c++-common/ubsan/overflow-vec-2.c   {-O0,-O1,-O2,-O2 -flto -fno-use-linker-plugin -flto-partition=none,-O2 -flto -fuse-linker-plugin -fno-fat-lto-objects,-O3 -g,-Os}  execution test
All but deep-stack-uaf-1.C in both check-gcc and check-g++.

In null-deref-1.c it seems the problem is in the line for the deref,
the testcase is expecting runtime error on line 10, while
    #0 0x80000a6d in NullDeref c-c++-common/asan/null-deref-1.c:11                                                                                 
    #1 0x800008f1 in main c-c++-common/asan/null-deref-1.c:15                                                                                      
    #2 0x3ff93022c5f in __libc_start_main (/lib64/libc.so.6+0x22c5f)                                                                               
    #3 0x8000096d  (gcc-7.0.1-20170120/obj-s390x-redhat-linux/gcc/testsuite/g++/null-deref-1.exe+0x8000096d)                                       
is reported.
The second test fails
ERROR: AddressSanitizer: heap-use-after-free on address 0x615000000205 at pc 0x000080000b12 bp 0x03fff8378928 sp 0x03fff8378918           
READ of size 1 at 0x615000000205 thread T0                                                                                                         
    #0 0x80000b11 in main g++.dg/asan/deep-stack-uaf-1.C:33                                                                                        
    #1 0x3ffabe22c5f in __libc_start_main (/lib64/libc.so.6+0x22c5f)                                                                               
    #2 0x800009cd  (gcc-7.0.1-20170120/obj-s390x-redhat-linux/gcc/testsuite/g++/deep-stack-uaf-1.exe+0x800009cd)
will need to debug if we don't need to add further options on s390x to
make sure it has all the frames it is expecting.
The last 2 tests aren't really asan related, will debug.

Note apparently asan_test.C isn't enabled on non-i?86/x86_64, which
is a big mistake, will try to change it separately.

2017-01-23  Jakub Jelinek  <jakub@redhat.com>

gcc/
	* config/s390/s390.c (s390_asan_shadow_offset): New function.
	(TARGET_ASAN_SHADOW_OFFSET): Redefine.
libsanitizer/
	* configure.tgt: Enable asan and ubsan on 64-bit s390*-*-linux*.

--- gcc/config/s390/s390.c.jj	2017-01-19 16:58:25.000000000 +0100
+++ gcc/config/s390/s390.c	2017-01-23 16:32:28.220398187 +0100
@@ -15435,6 +15435,14 @@ s390_excess_precision (enum excess_preci
   return FLT_EVAL_METHOD_UNPREDICTABLE;
 }
 
+/* Implement the TARGET_ASAN_SHADOW_OFFSET hook.  */
+
+static unsigned HOST_WIDE_INT
+s390_asan_shadow_offset (void)
+{
+  return TARGET_64BIT ? HOST_WIDE_INT_1U << 52 : HOST_WIDE_INT_UC (0x20000000);
+}
+
 /* Initialize GCC target structure.  */
 
 #undef  TARGET_ASM_ALIGNED_HI_OP
@@ -15536,6 +15544,8 @@ s390_excess_precision (enum excess_preci
 #define TARGET_BUILD_BUILTIN_VA_LIST s390_build_builtin_va_list
 #undef TARGET_EXPAND_BUILTIN_VA_START
 #define TARGET_EXPAND_BUILTIN_VA_START s390_va_start
+#undef TARGET_ASAN_SHADOW_OFFSET
+#define TARGET_ASAN_SHADOW_OFFSET s390_asan_shadow_offset
 #undef TARGET_GIMPLIFY_VA_ARG_EXPR
 #define TARGET_GIMPLIFY_VA_ARG_EXPR s390_gimplify_va_arg
 
--- libsanitizer/configure.tgt.jj	2017-01-23 15:25:21.000000000 +0100
+++ libsanitizer/configure.tgt	2017-01-23 15:36:40.787456320 +0100
@@ -39,6 +39,11 @@ case "${target}" in
 	;;
   sparc*-*-linux*)
 	;;
+  s390*-*-linux*)
+	if test x$ac_cv_sizeof_void_p = x4; then
+		UNSUPPORTED=1
+	fi
+	;;
   arm*-*-linux*)
 	;;
   aarch64*-*-linux*)


	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]