Bug 82788 - wrong code with -fstack-clash-protection --param=stack-clash-protection-probe-interval=10 on simple code
Summary: wrong code with -fstack-clash-protection --param=stack-clash-protection-probe...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 8.0
: P3 normal
Target Milestone: ---
Assignee: Jeffrey A. Law
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2017-10-31 19:00 UTC by Zdenek Sojka
Modified: 2017-11-06 22:45 UTC (History)
2 users (show)

See Also:
Host:
Target: x86_64-*-*, i?86-*-*
Build:
Known to work:
Known to fail: 8.0
Last reconfirmed: 2017-11-03 00:00:00


Attachments
reduced testcase (34 bytes, text/plain)
2017-10-31 19:00 UTC, Zdenek Sojka
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Zdenek Sojka 2017-10-31 19:00:23 UTC
Created attachment 42507 [details]
reduced testcase

$ cat testcase.c 
int main() { int a[1442]; }
$ x86_64-pc-linux-gnu-gcc -fstack-clash-protection --param=stack-clash-protection-probe-interval=10 testcase.c
$ ./a.out 
Segmentation fault

In the assembly, there is a loop that never finishes (until it segfaults):
...
	lea	r11, [rsp-5120]
.LPSRL0:
	sub	rsp, 4096
	or	DWORD PTR [rsp], 0
	cmp	rsp, r11
	jne	.LPSRL0
...


$ x86_64-pc-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/repo/gcc-trunk/binary-latest-amd64/bin/x86_64-pc-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/repo/gcc-trunk/binary-trunk-254242-checking-yes-rtl-df-extra-nographite-amd64/bin/../libexec/gcc/x86_64-pc-linux-gnu/8.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /repo/gcc-trunk//configure --enable-languages=c,c++ --enable-valgrind-annotations --disable-nls --enable-checking=yes,rtl,df,extra --without-cloog --without-ppl --without-isl --build=x86_64-pc-linux-gnu --host=x86_64-pc-linux-gnu --target=x86_64-pc-linux-gnu --with-ld=/usr/bin/x86_64-pc-linux-gnu-ld --with-as=/usr/bin/x86_64-pc-linux-gnu-as --disable-libstdcxx-pch --prefix=/repo/gcc-trunk//binary-trunk-254242-checking-yes-rtl-df-extra-nographite-amd64
Thread model: posix
gcc version 8.0.0 20171030 (experimental) (GCC)
Comment 1 Jeffrey A. Law 2017-11-02 16:51:50 UTC
Sigh.  Yet more evidence that user-configurable probing intervals is probably a bad idea...
Comment 2 Jeffrey A. Law 2017-11-06 15:51:48 UTC
Author: law
Date: Mon Nov  6 15:51:16 2017
New Revision: 254456

URL: https://gcc.gnu.org/viewcvs?rev=254456&root=gcc&view=rev
Log:
	PR target/82788
	* config/i386/i386.c (PROBE_INTERVAL): Remove.
	(get_probe_interval): New functions.
	(ix86_adjust_stack_and_probe_stack_clash): Use get_probe_interval.
	(ix86_adjust_stack_and_probe): Likewise.
	(output_adjust_stack_and_probe): Likewise.
	(ix86_emit_probe_stack_range): Likewise.
	(ix86_expand_prologue): Likewise.

	PR target/82788
	* gcc.dg/pr82788.c: New test.

Added:
    trunk/gcc/testsuite/gcc.dg/pr82788.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/i386/i386.c
    trunk/gcc/testsuite/ChangeLog
Comment 3 Jeffrey A. Law 2017-11-06 22:45:51 UTC
Fixed on the trunk this morning.