Bug 47490 - __Unwind_SjLj_Unregister clobbers return value with i586-mingw32msvc-g++ 4.4.4 and -fstack-protector
Summary: __Unwind_SjLj_Unregister clobbers return value with i586-mingw32msvc-g++ 4.4....
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.4.4
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
: 30047 48519 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-01-27 14:29 UTC by Cyp
Modified: 2011-04-12 19:46 UTC (History)
4 users (show)

See Also:
Host: Ubuntu, 64-bit
Target: i586-mingw32msvc
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Cyp 2011-01-27 14:29:29 UTC
Wrong code:
i586-mingw32msvc-g++ (GCC) 4.4.4 (on Ubuntu)
Correct code:
i586-mingw32msvc-g++ (Gentoo 4.5.2 p1.0, pie-0.4.5) 4.5.2

Build with:
i586-mingw32msvc-g++ -O0 -fstack-protector -o wtf.exe wtf.cpp

Apparent problem:
The function theCompilerWorks() returns false due to the return value true in the al register being clobbered by __Unwind_SjLj_Unregister.

The problem only occurs at -O0 in this test case, but the original program fails at -O2.

May be related to:
Bug 30047 mentions a return value being clobbered by __Unwind_SjLj_Unregister.

Testcase:
-----
extern "C" void abort(void);

void a() {}

void (*volatile doNothing)() = a;

struct TheCompilerWorks
{
	TheCompilerWorks() {}
	~TheCompilerWorks() {}
	char unusedArray[340];
};

bool theCompilerWorks()
{
	TheCompilerWorks harmlessObject;
	doNothing();
	return true;
}

int main()
{
	if (!theCompilerWorks())
		abort();
}
-----
Comment 1 Mikael Pettersson 2011-01-28 23:01:37 UTC
I can reproduce the failure on i686-linux when gcc-4.4.5 is configured with
--enable-languages=c,c++ --disable-dwarf2 --enable-sjlj-exceptions, mimicking mingw/mingw-w64.  gcc-4.5.2 appears to work though.
Comment 2 Mikael Pettersson 2011-01-30 01:23:33 UTC
Fixed on trunk for 4.5 by r146570:

Author: uweigand
Date: Wed Apr 22 11:31:56 2009
New Revision: 146570

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=146570
Log:
	* function.c (expand_function_end): Do not emit a jump to the "naked"
	return label for fall-through returns.
	* except.c (sjlj_emit_function_exit): Always place the call to the
	unregister function at the location installed by expand_function_end.

This seems to have been intended to fix SJLJ miscompilation on SPU, see the thread starting <http://gcc.gnu.org/ml/gcc-patches/2009-04/msg01265.html>.

Backporting this change to 4.4.5 solves the test case failure there too.
Comment 3 Kai Tietz 2011-04-12 19:44:10 UTC
*** Bug 30047 has been marked as a duplicate of this bug. ***
Comment 4 Kai Tietz 2011-04-12 19:45:09 UTC
*** Bug 48519 has been marked as a duplicate of this bug. ***
Comment 5 Kai Tietz 2011-04-12 19:46:06 UTC
Confirmed bug is fixed beginning with 4.4.5