public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/40918] New: uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before
@ 2009-07-30 20:18 andriys at gmail dot com
2009-07-30 20:22 ` [Bug c++/40918] " andriys at gmail dot com
` (8 more replies)
0 siblings, 9 replies; 11+ messages in thread
From: andriys at gmail dot com @ 2009-07-30 20:18 UTC (permalink / raw)
To: gcc-bugs
I was not able to reproduce the bug on Linux, so I assume this is a
Windows-specific.
If an exception is generated inside shared library (DLL), then crosses the
DLL-boundary and gets caught in some other module, the std::uncaught_exception
will always return wrong (inverted) value from now on. Here's a small test
case.
The DLL (throw.dll) contains just a single function that throws an exception:
throw.cpp
~~~~~~~~~
void do_throw(void)
{
throw("");
}
The test program (test.exe) is linked against throw.dll:
test.cpp
~~~~~~~~
#include <exception>
#include <iostream>
bool b;
void do_throw(void);
struct UE
{
~UE()
{
b = std::uncaught_exception();
}
};
int main(void)
{
try
{
do_throw();
}
catch (...)
{
}
try
{
UE ue;
throw "";
}
catch (...)
{
}
std::cout << "Expecting 'true', got " << (b ? "'true'" : "'false'") <<
std::endl;
{
UE ue;
}
std::cout << "Expecting 'false', got " << (b ? "'true'" : "'false'") <<
std::endl;
return 0;
}
test.exe produces the following output:
C:\TEMP\bug>test.exe
Expecting 'true', got 'false'
Expecting 'false', got 'true'
If we comment out the call to do_throw(), std::uncaught_exception will work as
expected. If we put do_throw() in a statically linked module,
std::uncaught_exception will work as expected as well.
--
Summary: uncaught_exception() returns wrong (inverted) value if
some exception have crossed a DLL boundary before
Product: gcc
Version: 4.4.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: andriys at gmail dot com
GCC host triplet: mingw32
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40918
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/40918] uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before
2009-07-30 20:18 [Bug c++/40918] New: uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before andriys at gmail dot com
@ 2009-07-30 20:22 ` andriys at gmail dot com
2009-07-31 4:18 ` dannysmith at users dot sourceforge dot net
` (7 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: andriys at gmail dot com @ 2009-07-30 20:22 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from andriys at gmail dot com 2009-07-30 20:22 -------
Created an attachment (id=18275)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18275&action=view)
Test case
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40918
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/40918] uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before
2009-07-30 20:18 [Bug c++/40918] New: uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before andriys at gmail dot com
2009-07-30 20:22 ` [Bug c++/40918] " andriys at gmail dot com
@ 2009-07-31 4:18 ` dannysmith at users dot sourceforge dot net
2009-07-31 6:56 ` andriys at gmail dot com
` (6 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: dannysmith at users dot sourceforge dot net @ 2009-07-31 4:18 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from dannysmith at users dot sourceforge dot net 2009-07-31 04:18 -------
(In reply to comment #0)
> I was not able to reproduce the bug on Linux, so I assume this is a
> Windows-specific.
>
> If an exception is generated inside shared library (DLL), then crosses the
> DLL-boundary and gets caught in some other module, the std::uncaught_exception
> will always return wrong (inverted) value from now on. Here's a small test
> case.
>
You need to link against a shared libgcc and a shared libstdc++ for this to
work. Shared libgcc is part of standard build now for mingw Shared libstdc++
is close.
http://gcc.gnu.org/ml/gcc-patches/2009-07/msg01042.html
Danny
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40918
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/40918] uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before
2009-07-30 20:18 [Bug c++/40918] New: uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before andriys at gmail dot com
2009-07-30 20:22 ` [Bug c++/40918] " andriys at gmail dot com
2009-07-31 4:18 ` dannysmith at users dot sourceforge dot net
@ 2009-07-31 6:56 ` andriys at gmail dot com
2009-07-31 6:58 ` andriys at gmail dot com
` (5 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: andriys at gmail dot com @ 2009-07-31 6:56 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from andriys at gmail dot com 2009-07-31 06:56 -------
I'm linking using g++ driver, so shared libgcc is enabled by default in 4.4.0.
I've just tried to enabled shared libstdc++ as described in the Release Notes
to the MinGW GCC 4.4.0 release, which made no difference.
More over, I modified the test case the following way: I got rid of std::cout
in favor of printf(), added -nodefaultlibs option to the linker and specified
all the required libraries manually. Now libstdc++ is not linked at all
(neither static nor dynamic), the bug is still here.
I'll attach the modified test case shortly.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40918
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/40918] uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before
2009-07-30 20:18 [Bug c++/40918] New: uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before andriys at gmail dot com
` (2 preceding siblings ...)
2009-07-31 6:56 ` andriys at gmail dot com
@ 2009-07-31 6:58 ` andriys at gmail dot com
2009-08-02 8:57 ` dannysmith at users dot sourceforge dot net
` (4 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: andriys at gmail dot com @ 2009-07-31 6:58 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from andriys at gmail dot com 2009-07-31 06:58 -------
Created an attachment (id=18277)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18277&action=view)
Modified test case (not dependent on libstdc++ at all)
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40918
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/40918] uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before
2009-07-30 20:18 [Bug c++/40918] New: uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before andriys at gmail dot com
` (3 preceding siblings ...)
2009-07-31 6:58 ` andriys at gmail dot com
@ 2009-08-02 8:57 ` dannysmith at users dot sourceforge dot net
2009-08-04 13:41 ` andriys at gmail dot com
` (3 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: dannysmith at users dot sourceforge dot net @ 2009-08-02 8:57 UTC (permalink / raw)
To: gcc-bugs
------- Comment #5 from dannysmith at users dot sourceforge dot net 2009-08-02 08:57 -------
(In reply to comment #3)
> I'm linking using g++ driver, so shared libgcc is enabled by default in 4.4.0.
> I've just tried to enabled shared libstdc++ as described in the Release Notes
> to the MinGW GCC 4.4.0 release, which made no difference.
>
> More over, I modified the test case the following way: I got rid of std::cout
> in favor of printf(), added -nodefaultlibs option to the linker and specified
> all the required libraries manually. Now libstdc++ is not linked at all
> (neither static nor dynamic), the bug is still here.
>
I cannot comment on the build of libsdc++.dll in the mingw 4.4.0 release since
I have not looked at that source.
However, your revised testcase -- linking against a static libsupc++ -- would
be expected to fail. We can have only one instance of the eh_globals structure
defined in libsupc++/eh_globals.cc. This is accomplished by linking both the
.exe and the .dll against a shared libstdc++.
Applying Dave Korn's patch mentioned in Comment #2, and linking against
libstdc++.dll, I get this with your original testcaase:
Expecting 'true', got 'true'
Expecting 'false', got 'false'
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40918
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/40918] uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before
2009-07-30 20:18 [Bug c++/40918] New: uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before andriys at gmail dot com
` (4 preceding siblings ...)
2009-08-02 8:57 ` dannysmith at users dot sourceforge dot net
@ 2009-08-04 13:41 ` andriys at gmail dot com
2009-08-04 13:53 ` andriys at gmail dot com
` (2 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: andriys at gmail dot com @ 2009-08-04 13:41 UTC (permalink / raw)
To: gcc-bugs
------- Comment #6 from andriys at gmail dot com 2009-08-04 13:41 -------
(In reply to comment #5)
> I cannot comment on the build of libsdc++.dll in the mingw 4.4.0 release since
> I have not looked at that source.
There is a patch file that is shipped along with the mingw 4.4.0 build
instructions/script. The patch adds most of the essential things that the Dave
Korn's patch does (i.e. __attribute__((dllimport)) decorations and
-no-undefined linker option.) I believe the official MinGW binaries were built
with that patch applied. Well, there are your E-mail at the top of that patch
file...
> Applying Dave Korn's patch mentioned in Comment #2, and linking against
> libstdc++.dll, I get this with your original testcaase:
>
> Expecting 'true', got 'true'
> Expecting 'false', got 'false'
>
Where this patch is supposed to be applied to? trunk?
I have looked through the patches you are referring to and through the source
in repository. As far as I can see, libsupc++ is still static only, and
eh_globals.cc is a part of libsupc++, not libstdc++. The fact that test-case
works correctly for you could be just a coincidence. The more reliable way to
check for the problem would be to compare the value returned by the
__cxa_get_globals() when being from the main executable and from the dll
respectively. I'll prepare the new test case.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40918
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/40918] uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before
2009-07-30 20:18 [Bug c++/40918] New: uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before andriys at gmail dot com
` (5 preceding siblings ...)
2009-08-04 13:41 ` andriys at gmail dot com
@ 2009-08-04 13:53 ` andriys at gmail dot com
2009-08-05 4:55 ` dannysmith at users dot sourceforge dot net
2010-01-26 12:16 ` [Bug target/40918] " andriys at gmail dot com
8 siblings, 0 replies; 11+ messages in thread
From: andriys at gmail dot com @ 2009-08-04 13:53 UTC (permalink / raw)
To: gcc-bugs
------- Comment #7 from andriys at gmail dot com 2009-08-04 13:53 -------
Created an attachment (id=18296)
--> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=18296&action=view)
Yet another test case
This test checks whether main executable and dll share common
abi::__cxa_eh_globals structure.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40918
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c++/40918] uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before
2009-07-30 20:18 [Bug c++/40918] New: uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before andriys at gmail dot com
` (6 preceding siblings ...)
2009-08-04 13:53 ` andriys at gmail dot com
@ 2009-08-05 4:55 ` dannysmith at users dot sourceforge dot net
2010-01-26 12:16 ` [Bug target/40918] " andriys at gmail dot com
8 siblings, 0 replies; 11+ messages in thread
From: dannysmith at users dot sourceforge dot net @ 2009-08-05 4:55 UTC (permalink / raw)
To: gcc-bugs
------- Comment #8 from dannysmith at users dot sourceforge dot net 2009-08-05 04:55 -------
(In reply to comment #6)
> (In reply to comment #5)
>
> > Applying Dave Korn's patch mentioned in Comment #2, and linking against
> > libstdc++.dll, I get this with your original testcaase:
> >
> > Expecting 'true', got 'true'
> > Expecting 'false', got 'false'
> >
> Where this patch is supposed to be applied to? trunk?
Yes, it against trunk.
> I have looked through the patches you are referring to and through the source
> in repository. As far as I can see, libsupc++ is still static only, and
> eh_globals.cc is a part of libsupc++, not libstdc++.
libsupc++ is a convenience lib that is included in libstdc++
The fact that test-case
> works correctly for you could be just a coincidence. The more reliable way to
> check for the problem would be to compare the value returned by the
> __cxa_get_globals() when being from the main executable and from the dll
> respectively. I'll prepare the new test case.
The new test case succeeds when I link against a shared libstdc++.
Danny
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40918
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/40918] uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before
2009-07-30 20:18 [Bug c++/40918] New: uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before andriys at gmail dot com
` (7 preceding siblings ...)
2009-08-05 4:55 ` dannysmith at users dot sourceforge dot net
@ 2010-01-26 12:16 ` andriys at gmail dot com
8 siblings, 0 replies; 11+ messages in thread
From: andriys at gmail dot com @ 2010-01-26 12:16 UTC (permalink / raw)
To: gcc-bugs
------- Comment #9 from andriys at gmail dot com 2010-01-26 12:16 -------
Well, I have finally managed to build the trunk on Windows (mingw32). Now all
test cases work fine for me without any patches (as of revision 156168 at
least). Thanks.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40918
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug target/40918] uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before
[not found] <bug-40918-4@http.gcc.gnu.org/bugzilla/>
@ 2012-01-16 9:57 ` ktietz at gcc dot gnu.org
0 siblings, 0 replies; 11+ messages in thread
From: ktietz at gcc dot gnu.org @ 2012-01-16 9:57 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40918
Kai Tietz <ktietz at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
CC| |ktietz at gcc dot gnu.org
Resolution| |FIXED
Known to fail| |
--- Comment #10 from Kai Tietz <ktietz at gcc dot gnu.org> 2012-01-16 09:40:58 UTC ---
Well, as user problem is solved and new gcc-version providing by default shared
version for libstdc++/libgcc, I close this issue.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2012-01-16 9:41 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-07-30 20:18 [Bug c++/40918] New: uncaught_exception() returns wrong (inverted) value if some exception have crossed a DLL boundary before andriys at gmail dot com
2009-07-30 20:22 ` [Bug c++/40918] " andriys at gmail dot com
2009-07-31 4:18 ` dannysmith at users dot sourceforge dot net
2009-07-31 6:56 ` andriys at gmail dot com
2009-07-31 6:58 ` andriys at gmail dot com
2009-08-02 8:57 ` dannysmith at users dot sourceforge dot net
2009-08-04 13:41 ` andriys at gmail dot com
2009-08-04 13:53 ` andriys at gmail dot com
2009-08-05 4:55 ` dannysmith at users dot sourceforge dot net
2010-01-26 12:16 ` [Bug target/40918] " andriys at gmail dot com
[not found] <bug-40918-4@http.gcc.gnu.org/bugzilla/>
2012-01-16 9:57 ` ktietz at gcc dot gnu.org
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).