Bug 81186 - SIGSEGV when using Address Sanitizer with nested functions
Summary: SIGSEGV when using Address Sanitizer with nested functions
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: sanitizer (show other bugs)
Version: 7.1.0
: P3 normal
Target Milestone: ---
Assignee: Martin Liška
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-06-23 01:57 UTC by Evgeny Kapun
Modified: 2017-07-27 07:37 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 7.1.0, 8.0
Known to fail:
Last reconfirmed: 2017-06-23 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Evgeny Kapun 2017-06-23 01:57:22 UTC
gcc version 7.1.0 (Debian 7.1.0-7)
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 7.1.0-7' --with-bugurl=file:///usr/share/doc/gcc-7/README.Bugs --enable-languages=c,ada,c++,go,brig,d,fortran,objc,obj-c++ --prefix=/usr --with-gcc-major-version-only --program-suffix=-7 --program-prefix=x86_64-linux-gnu- --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --with-default-libstdcxx-abi=new --enable-gnu-unique-object --disable-vtable-verify --enable-libmpx --enable-plugin --enable-default-pie --with-system-zlib --with-target-system-zlib --enable-objc-gc=auto --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --enable-multilib --with-tune=generic --enable-offload-targets=nvptx-none --without-cuda-driver --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu

Program:

    int main() {
        __label__ l;
        void f() {
            goto l;
        }
    l:
        return 0;
    }

Commands:

    $ gcc -fsanitize=address -o test test.c
    $ ./test
    ASAN:DEADLYSIGNAL
    =================================================================
    ==4734==ERROR: AddressSanitizer: SEGV on unknown address 0x564cfe0a887a (pc 0x564cfe0a88d2 bp 0x7ffc4f3a68b0 sp 0x7ffc4f3a6800 T0)
    ==4734==The signal is caused by a WRITE memory access.
        #0 0x564cfe0a88d1 in main (/path/to/test+0x8d1)
        #1 0x7faed07412b0 in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x202b0)
        #2 0x564cfe0a87d9 in _start (/path/to/test+0x7d9)

    AddressSanitizer can not provide additional info.
    SUMMARY: AddressSanitizer: SEGV (/path/to/test+0x8d1) in main
    ==4734==ABORTING

With GCC 6, this code works fine.
Comment 1 Martin Liška 2017-06-23 07:55:19 UTC
Mine, w/ -fno-sanitize-address-use-after-scope works fine.
Comment 2 Martin Liška 2017-07-26 08:53:09 UTC
Author: marxin
Date: Wed Jul 26 08:52:37 2017
New Revision: 250561

URL: https://gcc.gnu.org/viewcvs?rev=250561&root=gcc&view=rev
Log:
Move non-local goto expansion after parm_birth_insn (PR sanitize/81186).

2017-07-26  Martin Liska  <mliska@suse.cz>

	PR sanitize/81186
	* function.c (expand_function_start): Make expansion of
	nonlocal_goto_save_area after parm_birth_insn.
2017-07-26  Martin Liska  <mliska@suse.cz>

	PR sanitize/81186
	* gcc.dg/asan/pr81186.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/asan/pr81186.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/function.c
    trunk/gcc/testsuite/ChangeLog
Comment 3 Martin Liška 2017-07-26 08:53:38 UTC
Fixed on trunk so far.
Comment 4 Martin Liška 2017-07-27 07:33:26 UTC
Author: marxin
Date: Thu Jul 27 07:32:53 2017
New Revision: 250605

URL: https://gcc.gnu.org/viewcvs?rev=250605&root=gcc&view=rev
Log:
Backport r250561

2017-07-27  Martin Liska  <mliska@suse.cz>

	Backport from mainline
	2017-07-26  Martin Liska  <mliska@suse.cz>

	PR sanitize/81186
	* function.c (expand_function_start): Make expansion of
	nonlocal_goto_save_area after parm_birth_insn.
2017-07-27  Martin Liska  <mliska@suse.cz>

	Backport from mainline
	2017-07-26  Martin Liska  <mliska@suse.cz>

	PR sanitize/81186
	* gcc.dg/asan/pr81186.c: New test.

Added:
    branches/gcc-7-branch/gcc/testsuite/gcc.dg/asan/pr81186.c
Modified:
    branches/gcc-7-branch/gcc/ChangeLog
    branches/gcc-7-branch/gcc/function.c
    branches/gcc-7-branch/gcc/testsuite/ChangeLog
Comment 5 Martin Liška 2017-07-27 07:37:56 UTC
Fixed.