Exception catching problem since 10.4.3 using gcc 3.3 - IOKit
site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Anand Context : -------- This problems occurs when : -> Compiling a C++ program with gcc3.3 -> Linking using flat namespace -> Linking this program againt IOKit Description : -------- Diagnosis : ------- Sample program : ------- ------ file throw.cpp (dynamic lib throwing an exception): -- #include <iostream.h> class Exc1 { public: Exc1 () {} ~Exc1 () {} }; void dothrow () { std::cout << "before throw" << std::endl; throw Exc1 (); } -- file main.cpp : -- #include <stdio.h> #include <iostream.h> void dothrow (); class Exc1 { public: Exc1 (); ~Exc1 (); }; _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... We have found a problem in Mac OS X 10.4.3, which was not present in 10.4.2, concerning exception catching (see details below). This problem's cause is IOKit, which is dynamically linked to libgcc_s.1.dylib since 10.4.3, certainly by mistake. The problem is summed up below, with a small example program which demonstrate the problem . A bug report has already been sent by us to Apple a few day ago (Problem ID: 4393607). Does anybody already has come accross this problem, and know how to work around it ? Thank you for your answers, Wishing a happy new year to darwin-dev list readers. The problem occurs for programs made up of : a main binary, and at least a dynamic library compiled using flat namespace. The problem only occurs for programs which are linked against IOKit. Exceptions which are thrown from a dynamic library function cannot be catched in the main program. An abort is generated instead. This problem has apparead in Mac OS X 10.4.3, and was not present in 10.4.2. With command otool -L, We have noticed that IOKit is now dynamically linked against libgcc_s.1.dylib. This was not the case in Mac OS X 10.4.2 and former versions. Interestingly, libggcc_s.1.dylib is a component of gcc 4 runtime, and we are using gcc 3.3. When using gcc 3.3 on Mac OS X, the runtime used is a static version, and not the dylib version. Therefore, the problem could come from this mix of gcc 3.3 / gcc 4 runtimes. There may be some interference between the two, preventing exceptions to be correctly handled in some cases. Output of otool command on MacOS X 10.4.3 : command : otool -L /System/Library/Frameworks/IOKit.framework/ Versions/Current/IOKit result : /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0) /System/Library/Frameworks/SystemConfiguration.framework/Versions/A/ SystemConfiguration (compatibility version 1.0.0, current version 1.0.0) /System/Library/Frameworks/CoreFoundation.framework/Versions/A/ CoreFoundation (compatibility version 150.0.0, current version 368.18.0) /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3) /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0) /usr/lib/libmx.A.dylib (compatibility version 1.0.0, current version 93.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.1.2) The example contains three files which are reproduced below. - throw.cpp : a dynamic library with only one function : dothrow - main.cpp : main program, which calls dothrow and tries to catch the exception - Makefile : the Makefile To compile the example type the : make The program test is generated Launch the program : ./test If the problem is present (with Mac OX 10.4.3), the output is the following : -- trying lib->main exception before throw zsh: abort ./test -- If the problem is not present : with Mac OS 10.4.2, or removing - flat_namespace options from the Makefile, the output is the following : -- trying lib->main exception before throw ok catched in main -- We would like to know : - if other people have come accross the same problem- - if there is a workaround knowing that we have to use flat_namespace option, due to other constraints in our project. - if this problem in IOKit is planned to be fixed in next Mac OS version : 10.4.4 int main (void) { try { std::cout << "trying lib->main exception" << std::endl; dothrow (); } catch (...) { std::cout << "ok catched in main" << std::endl; } } -- Makefile : -- test:libThrow.dylib main.o g++ -o test main.o -lthrow -L./ throw.o:throw.cpp g++ -c -o throw.o throw.cpp main.o:main.cpp g++ -c -o main.o main.cpp libThrow.dylib:throw.o g++ -dynamiclib -flat_namespace -o libThrow.dylib throw.o - lIOKit -- This email sent to site_archiver@lists.apple.com
participants (1)
-
Ananda Tallur