* [Bug c++/54267] std::exception not catched when -O3 (-Os is fine, link static, FreeBSD 9.0-RELEASE-p3)
2012-08-15 2:01 [Bug c++/54267] New: std::exception not catched when -O3 (-Os is fine, link static, FreeBSD 9.0-RELEASE-p3) david.keller at litchis dot fr
@ 2012-08-15 2:10 ` david.keller at litchis dot fr
2012-08-15 2:58 ` david.keller at litchis dot fr
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: david.keller at litchis dot fr @ 2012-08-15 2:10 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54267
--- Comment #1 from David Keller <david.keller at litchis dot fr> 2012-08-15 02:09:47 UTC ---
Err:
Pasted command line show use of -Os which does *NOT* reproduce the behavior.
Please use -O3.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug c++/54267] std::exception not catched when -O3 (-Os is fine, link static, FreeBSD 9.0-RELEASE-p3)
2012-08-15 2:01 [Bug c++/54267] New: std::exception not catched when -O3 (-Os is fine, link static, FreeBSD 9.0-RELEASE-p3) david.keller at litchis dot fr
2012-08-15 2:10 ` [Bug c++/54267] " david.keller at litchis dot fr
@ 2012-08-15 2:58 ` david.keller at litchis dot fr
2012-08-15 3:01 ` [Bug target/54267] " pinskia at gcc dot gnu.org
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: david.keller at litchis dot fr @ 2012-08-15 2:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54267
--- Comment #2 from David Keller <david.keller at litchis dot fr> 2012-08-15 02:58:33 UTC ---
1 #include <iostream>
2 #include <boost/system/error_code.hpp>
3 #include <boost/system/system_error.hpp>
4
5
6 namespace detail {
7
8 inline void throw_error(const boost::system::error_code& err)
9 {
10 /**
11 * If this condition is removed, (i.e. always throw)
12 * Then the exception will be caught!!
13 */
14 if ( err )
15 {
16 boost::system::system_error e(err);
17 throw e;
18 }
19 }
20
21 } // namespace detail
22
23 /**
24 * This exception is not catchable !
25 */
26 void
27 do_throw_bad
28 ( void )
29 {
30 // Simulate a boost::asio::error
31 detail::throw_error( boost::system::errc::make_error_code(
boost::system::errc::address_in_use ));
32 }
33
34 /**
35 * Now the exceptions thrown becomes catchable.
36 * When the function lives in an anonymous namespace.
37 */
38 namespace {
39
40 void
41 do_throw_ok
42 ( void )
43 {
44 // Simulate a boost::asio::error
45 detail::throw_error( boost::system::errc::make_error_code(
boost::system::errc::address_in_use ));
46 }
47
48 } // anonymous namespace
49 [...]
When the if condition is removed from the throw_error function, the exception
is caught!
I'll continue to simplify the case.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/54267] std::exception not catched when -O3 (-Os is fine, link static, FreeBSD 9.0-RELEASE-p3)
2012-08-15 2:01 [Bug c++/54267] New: std::exception not catched when -O3 (-Os is fine, link static, FreeBSD 9.0-RELEASE-p3) david.keller at litchis dot fr
2012-08-15 2:10 ` [Bug c++/54267] " david.keller at litchis dot fr
2012-08-15 2:58 ` david.keller at litchis dot fr
@ 2012-08-15 3:01 ` pinskia at gcc dot gnu.org
2012-08-15 3:05 ` david.keller at litchis dot fr
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-08-15 3:01 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54267
Andrew Pinski <pinskia at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Target|x64 |x68_64-freebsd*
Component|c++ |target
Host|FreeBSD |
Build|With -O3 |
--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-08-15 03:01:03 UTC ---
Can you remove the boost dependency? Also does this work with the shared
libgcc?
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/54267] std::exception not catched when -O3 (-Os is fine, link static, FreeBSD 9.0-RELEASE-p3)
2012-08-15 2:01 [Bug c++/54267] New: std::exception not catched when -O3 (-Os is fine, link static, FreeBSD 9.0-RELEASE-p3) david.keller at litchis dot fr
` (2 preceding siblings ...)
2012-08-15 3:01 ` [Bug target/54267] " pinskia at gcc dot gnu.org
@ 2012-08-15 3:05 ` david.keller at litchis dot fr
2012-08-15 3:16 ` david.keller at litchis dot fr
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: david.keller at litchis dot fr @ 2012-08-15 3:05 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54267
--- Comment #4 from David Keller <david.keller at litchis dot fr> 2012-08-15 03:05:29 UTC ---
I'am trying.
It's not reproducible with <system_error> classes.
Static build seems to use shared libgcc_s:
$ldd bin/gcc-4.7/release/link-static/threading-multi/main
bin/gcc-4.7/release/link-static/threading-multi/main:
libstdc++.so.6 => /usr/local/lib/gcc47/libstdc++.so.6 (0x80084d000)
libm.so.5 => /lib/libm.so.5 (0x800b55000)
libgcc_s.so.1 => /usr/local/lib/gcc47/libgcc_s.so.1 (0x800d76000)
libthr.so.3 => /lib/libthr.so.3 (0x800f8b000)
libc.so.7 => /lib/libc.so.7 (0x8011ae000)
Shared build reproduces.
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/54267] std::exception not catched when -O3 (-Os is fine, link static, FreeBSD 9.0-RELEASE-p3)
2012-08-15 2:01 [Bug c++/54267] New: std::exception not catched when -O3 (-Os is fine, link static, FreeBSD 9.0-RELEASE-p3) david.keller at litchis dot fr
` (3 preceding siblings ...)
2012-08-15 3:05 ` david.keller at litchis dot fr
@ 2012-08-15 3:16 ` david.keller at litchis dot fr
2012-08-15 3:34 ` david.keller at litchis dot fr
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: david.keller at litchis dot fr @ 2012-08-15 3:16 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54267
--- Comment #5 from David Keller <david.keller at litchis dot fr> 2012-08-15 03:16:30 UTC ---
1 #include <iostream>
2 #include <stdexcept>
3
4 namespace detail {
5
6 inline void throw_error(bool t)
7 {
8 /**
9 * If this condition is removed, (i.e. always throw)
10 * Then the exception will be catched !!
11 */
12 if ( t )
13 {
14 std::runtime_error e("failed");
15 throw e;
16 }
17 }
18
19 inline void this_function_is_required ( void )
20 {
21 std::cout << "do not remove on optimization" << std::endl;
22 }
23
24 } // namespace detail
25
26 /**
27 * This exception is not catchable !
28 */
29 void
30 do_throw_bad
31 ( bool b )
32 {
33 // Simulate a boost::asio::error
34 //boost::system::errc::make_error_code(
boost::system::errc::address_in_use );
35 detail::this_function_is_required();
36 detail::throw_error( b );
37 }
38
39 /**
40 * Expect:
41 * #############
42 * catched bad
43 * ############
44 *
45 * But see:
46 * #############
47 * terminate called after throwing an instance of
'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::system::system_error>
>'
48 * what(): asio: End of file
49 * Abort trap (core dumped)
50 * #############
51 */
52 int
53 main
54 ( int argc
55 , char* argv[] )
56 {
57 try
58 {
59 do_throw_bad( argc == 1 );
60 }
61 catch ( std::exception const& )
62 {
63 std::cout << "catched" << std::endl;
64 }
65
66 return 0;
67 }
68
Et voilà
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/54267] std::exception not catched when -O3 (-Os is fine, link static, FreeBSD 9.0-RELEASE-p3)
2012-08-15 2:01 [Bug c++/54267] New: std::exception not catched when -O3 (-Os is fine, link static, FreeBSD 9.0-RELEASE-p3) david.keller at litchis dot fr
` (4 preceding siblings ...)
2012-08-15 3:16 ` david.keller at litchis dot fr
@ 2012-08-15 3:34 ` david.keller at litchis dot fr
2012-08-15 3:40 ` david.keller at litchis dot fr
2012-08-15 15:55 ` david.keller at litchis dot fr
7 siblings, 0 replies; 9+ messages in thread
From: david.keller at litchis dot fr @ 2012-08-15 3:34 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54267
--- Comment #6 from David Keller <david.keller at litchis dot fr> 2012-08-15 03:34:07 UTC ---
Created attachment 28018
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28018
Here is the faulty code.
# Hum, without this variable, the program runs fine.
# Is it finding the wrong version of stdlib ?
setenv LD_LIBRARY_PATH
/lib:/usr/local/bin:/usr/local/lib:/usr/local/lib32:/usr/local/lib64
g++47 -O3 -Wl,-rpath,/usr/local/lib/gcc47 main.cpp && ./a.out
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/54267] std::exception not catched when -O3 (-Os is fine, link static, FreeBSD 9.0-RELEASE-p3)
2012-08-15 2:01 [Bug c++/54267] New: std::exception not catched when -O3 (-Os is fine, link static, FreeBSD 9.0-RELEASE-p3) david.keller at litchis dot fr
` (5 preceding siblings ...)
2012-08-15 3:34 ` david.keller at litchis dot fr
@ 2012-08-15 3:40 ` david.keller at litchis dot fr
2012-08-15 15:55 ` david.keller at litchis dot fr
7 siblings, 0 replies; 9+ messages in thread
From: david.keller at litchis dot fr @ 2012-08-15 3:40 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54267
--- Comment #7 from David Keller <david.keller at litchis dot fr> 2012-08-15 03:39:56 UTC ---
It might be related to a wrong stdlib selection on my side:
1) Without setenv LD_LIBRARY_PATH
/lib:/usr/local/bin:/usr/local/lib:/usr/local/lib32:/usr/local/lib64, the
program runs fine.
2) It is linked with -rpath,/usr/local/lib/gcc48 (and rpath should have
priority over LD_LIBRARy_PATH)
*) Why optimization level has an influence on all this ?
^ permalink raw reply [flat|nested] 9+ messages in thread
* [Bug target/54267] std::exception not catched when -O3 (-Os is fine, link static, FreeBSD 9.0-RELEASE-p3)
2012-08-15 2:01 [Bug c++/54267] New: std::exception not catched when -O3 (-Os is fine, link static, FreeBSD 9.0-RELEASE-p3) david.keller at litchis dot fr
` (6 preceding siblings ...)
2012-08-15 3:40 ` david.keller at litchis dot fr
@ 2012-08-15 15:55 ` david.keller at litchis dot fr
7 siblings, 0 replies; 9+ messages in thread
From: david.keller at litchis dot fr @ 2012-08-15 15:55 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=54267
--- Comment #8 from David Keller <david.keller at litchis dot fr> 2012-08-15 15:55:16 UTC ---
According to http://www.freebsd.org/cgi/query-pr.cgi?pr=28191, the man is
wrong, FreeBSD look at LD_LIBRARY_PATH before rpath.
So, when LD_LIBRARY_PATH contains /lib:, it crashes as seen in this thread.
The test program picks the wrong lib libgcc_s !
Not a GCC bug then :-)
Do you agree ?
(I don't get why O3 makes program requiring the last libgcc_s, I'll expect it
to be required regardless of optimization level)
^ permalink raw reply [flat|nested] 9+ messages in thread