Message ID | 20141216223558.6CADB2C2446@topped-with-meat.com |
---|---|
State | New |
Headers | show |
On Tue, 16 Dec 2014, Roland McGrath wrote: > Verified on x86_64-linux-gnu that no generated code (including unwind info) > changes. Also tested arm-linux-gnueabihf that no generated code changes; > there was one difference in the EABI unwind info for __unwind_freeres, > which I don't understand but also deem wholly unimportant. I don't think this is safe. The optimize pragma is documented as being for optimization options only; using it with other options such as -fexceptions is not a documented or supported GCC feature (actually, even using it for some optimization options can be very fragile; it's best to use it only for purely non-semantic options rather than those such as -ffast-math that affect semantics). -fexceptions affects global state in GCC, including global choices made when the parser is initialized [*]; enabling it at any later point risks subtle problems from inconsistencies in GCC's internal datastructures; that it works with a particular version of GCC at a particular time means very little. Enabling it after headers (probably including inline functions) have been parsed seems even riskier than enabling it at the start of a source file before any headers have been parsed (but I still don't think that would be safe). [*] using_eh_for_cleanups - on that basis, it seems quite plausible that cleanup attributes (as used in various ways in glibc) will not reliably interact properly with exceptions if exceptions weren't enabled from the command line.
OK. I've reverted it (including the ChangeLog and all, since there were no later commits anyway). I was eager to do this because I thought it was going to simplify some other changes I'm working on. But I changed tack on that work anyway so I think this is now wholly orthogonal. Thanks, Roland
--- a/nptl/Makefile +++ b/nptl/Makefile @@ -146,9 +146,6 @@ libpthread-static-only-routines = pthread_atfork # nptl-init.c contains sigcancel_handler(). CFLAGS-nptl-init.c = -fexceptions -fasynchronous-unwind-tables -# The unwind code itself, -CFLAGS-unwind.c = -fexceptions -CFLAGS-unwind-forcedunwind.c = -fexceptions -fasynchronous-unwind-tables # The following three functions must be async-cancel safe. CFLAGS-pthread_cancel.c = -fexceptions -fasynchronous-unwind-tables --- a/nptl/unwind.c +++ b/nptl/unwind.c @@ -25,6 +25,8 @@ #include "pthreadP.h" #include <jmpbuf-unwind.h> +#pragma GCC optimize "-fexceptions" + #ifdef HAVE_FORCED_UNWIND #ifdef _STACK_GROWS_DOWN --- a/sysdeps/gnu/Makefile +++ b/sysdeps/gnu/Makefile @@ -79,11 +79,9 @@ endif ifeq ($(subdir),csu) routines += unwind-resume shared-only-routines += unwind-resume -CFLAGS-unwind-resume.c += -fexceptions -fasynchronous-unwind-tables endif ifeq ($(subdir),rt) librt-sysdep_routines += rt-unwind-resume librt-shared-only-routines += rt-unwind-resume -CFLAGS-rt-unwind-resume.c += -fexceptions -fasynchronous-unwind-tables endif --- a/sysdeps/gnu/unwind-resume.c +++ b/sysdeps/gnu/unwind-resume.c @@ -21,6 +21,8 @@ #include <unwind.h> #include <gnu/lib-names.h> +#pragma GCC optimize ("-fexceptions", "-fasynchronous-unwind-tables") + static void (*libgcc_s_resume) (struct _Unwind_Exception *exc) __attribute__ ((noreturn)); static _Unwind_Reason_Code (*libgcc_s_personality) --- a/sysdeps/nptl/unwind-forcedunwind.c +++ b/sysdeps/nptl/unwind-forcedunwind.c @@ -23,6 +23,8 @@ #include <sysdep.h> #include <gnu/lib-names.h> +#pragma GCC optimize ("-fexceptions", "-fasynchronous-unwind-tables") + static void *libgcc_s_handle; static void (*libgcc_s_resume) (struct _Unwind_Exception *exc); static _Unwind_Reason_Code (*libgcc_s_personality) --- a/sysdeps/unix/sysv/linux/arm/unwind-forcedunwind.c +++ b/sysdeps/unix/sysv/linux/arm/unwind-forcedunwind.c @@ -21,6 +21,8 @@ #include <unwind.h> #include <pthreadP.h> +#pragma GCC optimize ("-fexceptions", "-fasynchronous-unwind-tables") + static void *libgcc_s_handle; static void (*libgcc_s_resume) (struct _Unwind_Exception *exc) __attribute_used__;