public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [GCC, ARM] armv8 linux toolchain asan testcase fail due to stl missing conditional code
@ 2015-06-03  5:27 Shiva Chen
  2015-06-03  8:31 ` Ramana Radhakrishnan
  2015-06-03  8:36 ` Kyrill Tkachov
  0 siblings, 2 replies; 21+ messages in thread
From: Shiva Chen @ 2015-06-03  5:27 UTC (permalink / raw)
  To: GCC Patches, nickc, richard.earnshaw, ramana.radhakrishnan

[-- Attachment #1: Type: text/plain, Size: 2010 bytes --]

Hi,

I noticed that armv8(32 bit target) linux toolchain

run asan testcase would get the following message:


FAIL: c-c++-common/asan/heap-overflow-1.c -O0 output pattern test, is
Executing on host:
/home/gccbuilder-x86/test/mgcc5.0/testsuite/../tools/x86_64/install/bin/qemu-arm
-E LD_LIBRARY_PATH=/home/gccbuilder-x86/test/mgcc5.0/Release/install/armv8-marvell-linux-gnueabihf-hard-5.1.1_x86_64/bin/../arm-linux-gnueabihf/libc/lib/arm-linux-gnueabihf:/home/gccbuilder-x86/test/mgcc5.0/Release/install/armv8-marvell-linux-gnueabihf-hard-5.1.1_x86_64/bin/../arm-linux-gnueabihf/libc/usr/lib/arm-linux-gnueabihf
-L /home/gccbuilder-x86/test/mgcc5.0/Release/install/armv8-marvell-linux-gnueabihf-hard-5.1.1_x86_64/bin/../arm-linux-gnueabihf/libc
./heap-overflow-1.exe
=================================================================
==2182==ERROR: AddressSanitizer: heap-buffer-overflow on address
0xf4a007fa at pc 0x000108a0 bp 0xf6ffc264 sp 0xf6ffc25c
READ of size 1 at 0xf4a007fa thread T0
ASAN:SIGSEGV


sanitizer library use the source in gcc-src/libbacktrace to allocate memory.

The error cause by null pointer reference in libbacktrace/mmap.c


void
backtrace_free (struct backtrace_state *state, void *addr, size_t size,
                backtrace_error_callback error_callback ATTRIBUTE_UNUSED,
                void *data ATTRIBUTE_UNUSED)
...
  if (locked)
    {
      backtrace_free_locked (state, addr, size);

      if (state->threaded) <= line 201
        __sync_lock_release (&state->lock_alloc); <= line 202
    }
}

.loc 1 201 0
cmp r3, #0 <= r3 contain the value of state->threaded
.loc 1 202 0
addne r3, r5, #32
movne r2, #0
stl r2, [r3] <= should be conditional execution

when r3 is 0, line 202 should not execute.

It seems that stl should generate as stlne.

Otherwise, slt will get null reference when r3 is 0.


To fix the issue, add %? when output stl assembly pattern in sync.md.

Is this patch ok for trunk?

Thanks,
Shiva

[-- Attachment #2: Fix_slt_lda_missing_conditional_code.diff --]
[-- Type: text/plain, Size: 877 bytes --]

diff --git a/gcc/config/arm/sync.md b/gcc/config/arm/sync.md
index 44cda61..79b039e 100644
--- a/gcc/config/arm/sync.md
+++ b/gcc/config/arm/sync.md
@@ -75,9 +75,9 @@
   {
     enum memmodel model = memmodel_from_int (INTVAL (operands[2]));
     if (is_mm_relaxed (model) || is_mm_consume (model) || is_mm_release (model))
-      return \"ldr<sync_sfx>\\t%0, %1\";
+      return \"ldr<sync_sfx>%?\\t%0, %1\";
     else
-      return \"lda<sync_sfx>\\t%0, %1\";
+      return \"lda<sync_sfx>%?\\t%0, %1\";
   }
 )
 
@@ -91,9 +91,9 @@
   {
     enum memmodel model = memmodel_from_int (INTVAL (operands[2]));
     if (is_mm_relaxed (model) || is_mm_consume (model) || is_mm_acquire (model))
-      return \"str<sync_sfx>\t%1, %0\";
+      return \"str<sync_sfx>%?\t%1, %0\";
     else
-      return \"stl<sync_sfx>\t%1, %0\";
+      return \"stl<sync_sfx>%?\t%1, %0\";
   }
 )
 

[-- Attachment #3: ChangeLog.fix_slt_lda_missing_conditional_code --]
[-- Type: application/octet-stream, Size: 247 bytes --]

2015-06-03  Shiva Chen  <shiva0217@gmail.com>

	Add conditional code for arm load acquire/store release instructions
	* sync.md (atomic_load<mode>): add conditional code for lda/ldr
        (atomic_store<mode>): add conditional code for stl/str



^ permalink raw reply	[flat|nested] 21+ messages in thread

end of thread, other threads:[~2015-10-02 12:57 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-03  5:27 [GCC, ARM] armv8 linux toolchain asan testcase fail due to stl missing conditional code Shiva Chen
2015-06-03  8:31 ` Ramana Radhakrishnan
2015-06-03  8:36 ` Kyrill Tkachov
     [not found]   ` <556EBBAC.2020504@arm.com>
2015-06-03  8:53     ` Kyrill Tkachov
2015-06-03  9:33       ` Shiva Chen
2015-06-04  4:51         ` Shiva Chen
2015-06-04  8:24           ` Kyrill Tkachov
2015-06-04  8:42             ` Richard Earnshaw
2015-06-04 10:01               ` Shiva Chen
2015-06-04 10:04                 ` Kyrill Tkachov
2015-06-05  8:34                   ` Shiva Chen
2015-06-05  8:35                     ` Kyrill Tkachov
2015-06-05 10:59                       ` Shiva Chen
2015-06-05 13:11                         ` Kyrill Tkachov
2015-06-05 13:14                           ` Richard Earnshaw
2015-06-05 14:02                             ` Kyrill Tkachov
2015-06-09  8:44                               ` Kyrill Tkachov
2015-09-30 17:10                                 ` Kyrill Tkachov
2015-10-01  9:10                                   ` Kyrill Tkachov
2015-10-01 20:21                                     ` Christophe Lyon
2015-10-02 12:57                                       ` Kyrill Tkachov

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 read-only IMAP folder(s) and NNTP newsgroup(s).