This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug rtl-optimization/83367] New: static global constructors stack memory clobbering
- From: "weilercdale at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 11 Dec 2017 13:14:10 +0000
- Subject: [Bug rtl-optimization/83367] New: static global constructors stack memory clobbering
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83367
Bug ID: 83367
Summary: static global constructors stack memory clobbering
Product: gcc
Version: 7.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: rtl-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: weilercdale at gmail dot com
Target Milestone: ---
Created attachment 42835
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=42835&action=edit
I've combined three files here because Bugzilla does not support adding
multiple attachment files?
I spent several hours trying to reduce this to the most minimal test case I
could but the compiler is very picky about the static global constructors being
in their own translation unit to trigger the problems.
Test.cpp contains the core code for a "test" framework that accepts registering
tests and subtests through maintaining a static linked list as static global
constructors are invoked.
Test.h contains the definitions needed to define tests in a seperate
translation unit Tests.cpp (again because putting it inline the Test.cpp file
does not exibit the problem.)
Test.cpp contains a test + subtest that triggers the bug, however the
conditionally excluded equivlant example (avoiding cTestRegister) does not
exibit the problem either.
When you compile with -fsanitize=address asan reports stack memory corruption,
as does valgrind if you run it a couple times.
It should print "b\n\a\n", as it does with clang/msvc (at all optimization
levels) and gcc at -O0, any optimization level will lead to clobbering, garbage
output and in most cases Illegal instruction exceptions.