gnustep / libobjc2

Objective-C runtime library intended for use with Clang.
http://www.gnustep.org/
MIT License
426 stars 116 forks source link

On Raspian 10 with libobjc2.1 all exceptions crash trying to determine objc exception personality #207

Closed mpw closed 3 years ago

mpw commented 3 years ago

This shows up in the GNUstep base test suite as well as in my own code.

Workaround is removing the code that does the detection, which apparently is only relevant for ObjC++.

(eh_personality.c lines 392ff)

//#ifndef NO_OBJCXX
#if 0
        if (cxx_exception_class == 0)
        {
                test_cxx_eh_implementation();
        }

        if (exceptionClass == cxx_exception_class)
        {
                int objcxx;
                id obj = objc_object_for_cxx_exception(exceptionObject, &objcxx);
                objcxxException = objcxx;
                if (objcxxException)
                {
                        object = obj;
                        DEBUG_LOG("ObjC++ object exception %p\n", object);
                        // This is a foreign exception, buy for the purposes of exception
                        // matching, we pretend that it isn't.
                        foreignException = NO;
                }
        }
#endif
mpw commented 3 years ago

Oh, the actual crash is in the test_eh_personality function in objcxx_eh.cc, message is "Unable to find refcount field".

Stack-trace:

#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0xb677f230 in __GI_abort () at abort.c:79
#2  0xb6994068 in test_eh_personality () from /usr/GNUstep/Local/Library/Libraries/libobjc.so.4.6
#3  0xb68cfcb0 in ?? () from /lib/arm-linux-gnueabihf/libgcc_s.so.1
#4  0xb68d091c in _Unwind_RaiseException () from /lib/arm-linux-gnueabihf/libgcc_s.so.1
#5  0xb4430984 in __cxa_throw () from /lib/arm-linux-gnueabihf/libstdc++.so.6
#6  0xb6993e9c in cxx_throw() () from /usr/GNUstep/Local/Library/Libraries/libobjc.so.4.6
#7  0xb6988510 in eh_trampoline() () from /usr/GNUstep/Local/Library/Libraries/libobjc.so.4.6
#8  0xb6994394 in test_cxx_eh_implementation () from /usr/GNUstep/Local/Library/Libraries/libobjc.so.4.6
#9  0xb69844d4 in internal_objc_personality () from /usr/GNUstep/Local/Library/Libraries/libobjc.so.4.6
#10 0xb6984b68 in __gnustep_objc_personality_v0 () from /usr/GNUstep/Local/Library/Libraries/libobjc.so.4.6
#11 0xb68cff4c in ?? () from /lib/arm-linux-gnueabihf/libgcc_s.so.1
#12 0xb68d09ac in _Unwind_Backtrace () from /lib/arm-linux-gnueabihf/libgcc_s.so.1
#13 0xb684e098 in __GI___backtrace (array=<optimized out>, size=<optimized out>) at ../sysdeps/arm/backtrace.c:105
#14 0xb6bd9244 in GSPrivateReturnAddresses (returns=0x1d74a4) at NSException.m:997
#15 0xb6bd9b20 in -[GSStackTrace trace] (self=0x1d7494, _cmd=0xb6fac618 <.objc_selector_trace_v80:4>) at NSException.m:1350
#16 0xb6bdad0c in -[NSException raise] (self=0x1d5ee4, _cmd=0xb6fa95c8 <.objc_selector_raise_v80:4>) at NSException.m:1604

I tried disabling the -[GStackTrace trace] method, but that puts the crash elsewhere:

#0  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1  0xb677f230 in __GI_abort () at abort.c:79
#2  0xb6994068 in test_eh_personality () from /usr/GNUstep/Local/Library/Libraries/libobjc.so.4.6
#3  0xb68cfcb0 in ?? () from /lib/arm-linux-gnueabihf/libgcc_s.so.1
#4  0xb68d091c in _Unwind_RaiseException () from /lib/arm-linux-gnueabihf/libgcc_s.so.1
#5  0xb4430984 in __cxa_throw () from /lib/arm-linux-gnueabihf/libstdc++.so.6
#6  0xb6993e9c in cxx_throw() () from /usr/GNUstep/Local/Library/Libraries/libobjc.so.4.6
#7  0xb6988510 in eh_trampoline() () from /usr/GNUstep/Local/Library/Libraries/libobjc.so.4.6
#8  0xb6994394 in test_cxx_eh_implementation () from /usr/GNUstep/Local/Library/Libraries/libobjc.so.4.6
#9  0xb69844d4 in internal_objc_personality () from /usr/GNUstep/Local/Library/Libraries/libobjc.so.4.6
#10 0xb6984b68 in __gnustep_objc_personality_v0 () from /usr/GNUstep/Local/Library/Libraries/libobjc.so.4.6
#11 0xb68cfcb0 in ?? () from /lib/arm-linux-gnueabihf/libgcc_s.so.1
#12 0xb68d091c in _Unwind_RaiseException () from /lib/arm-linux-gnueabihf/libgcc_s.so.1
#13 0xb6984150 in objc_exception_throw () from /usr/GNUstep/Local/Library/Libraries/libobjc.so.4.6
#14 0xb6bdabc4 in -[NSException raise] (self=0x1c373c, _cmd=0xb6fa95e0 <.objc_selector_raise_v80:4>) at NSException.m:1611
#15 0xb6bd9cb0 in +[NSException raise:format:arguments:] (self=0xb6f60d34 <._OBJC_CLASS_NSException>, 
    _cmd=0xb6faaa78 <.objc_selector_raise:format:arguments:_v200:4812{.va_list=^v}16>, 
    name=0xb6f97090 <.objc_str_NSMallocException>, format=0xb6fa2970 <.objc_str_Attempt_to_free_freed_memory>, argList=...)
    at NSException.m:1490
#16 0xb6bd9bf8 in +[NSException raise:format:] (self=0xb6f60d34 <._OBJC_CLASS_NSException>, 
    _cmd=0xb6fa9558 <.objc_selector_raise:format:_v160:4812>, name=0xb6f97090 <.objc_str_NSMallocException>, 
    format=0xb6fa2970 <.objc_str_Attempt_to_free_freed_memory>) at NSException.m:1475
#17 0xb6da67b8 in ffree (zone=0x1c37d8, ptr=0x1c38d8) at NSZone.m:714
#18 0xb6da7c18 in NSZoneFree (zone=0x1c37d8, ptr=0x1c38d8) at NSZone.m:1803
#19 0x000090d8 in main () at NSZone.m:40
mpw commented 3 years ago

Configuring libobjc2.1 without Objective-C++ support avoids the bug:

cmake ../ -DENABLE_OBJCXX=NO -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_ASM_COMPILER=clang -DTESTS=OFF

davidchisnall commented 3 years ago

Thanks for the report. This looks like a duplicate of #203, please can you confirm whether #205 fixes it for you?

mpw commented 3 years ago

It certainly should because the code that you removed is exactly the code I ifdefed away to make it work.

mpw commented 3 years ago

Can confirm fixed (pulled main with the changes you just merged)