Message ID | 7D5A46F8-D89F-493E-A729-6CEC651367CF@sandoe-acoustics.co.uk |
---|---|
State | New |
Headers | show |
On Wed, 9 Nov 2011, Iain Sandoe wrote: > I am probably missing something > - but there doesn't seem to be a ready way to set the Init() value of a flag > depending on the target The way that is done is to use an expression inside Init() that uses a target macro (it needs to be a macro, not a hook, at present). So change NEXT_OBJC_RUNTIME to be a macro defined to either 1 or 0, instead of defined or undefined, and use that in Init().
On Nov 9, 2011, at 10:12 AM, Iain Sandoe wrote: > This puts "flag_next_runtime" into the global options structure > I needed to deal with '-fobjc-sjlj-exceptions' and elected to remove it - > - this is because there is only one valid exception model for each permutation of runtime and ABI - thus the User flag is just clutter. > > It is now ignored as a User flag - and the relevant selection actions are all local to Objective C. > > (yay! got rid of one exceptions-related flag :-)) .... Yeah, that sounds like a good idea. > +ObjC ObjC++ Ignore Warn(switch %qs has been removed and is set automaticaly where required) Spelling, automatically. > + targetting Darwin. However, the flag overrides have not be called yet. */ Spelling, targeting. > + if (flag_objc_exceptions) > + /* ??? Should we warn that this is incompatible, if the user has set it. > + For now, just force it it off. */ > + flag_exceptions = 0; Where was this in the previous code? In ObjC++, exceptions can be on for C++ and should not be turned off. Does this code ever turn off C++ exceptions? As a stylistic note, I'd rather have a literal translation into the new mechanism, no changes to behavior, and then a separate patch that then changes things you think are wrong or could be done better. The first is large and mechanical and it important to get right. The follow-on patches, when done one at a time, if any one proved wrong, it alone could then be reverted. If the flag_exceptions = 0 bit and Joseph's comments are fixed, I think we're done.
On Wed, 9 Nov 2011, Mike Stump wrote: > On Nov 9, 2011, at 10:12 AM, Iain Sandoe wrote: > > This puts "flag_next_runtime" into the global options structure > > > I needed to deal with '-fobjc-sjlj-exceptions' and elected to remove it - > > - this is because there is only one valid exception model for each permutation of runtime and ABI - thus the User flag is just clutter. > > > > It is now ignored as a User flag - and the relevant selection actions are all local to Objective C. > > > > (yay! got rid of one exceptions-related flag :-)) .... > > Yeah, that sounds like a good idea. > > > +ObjC ObjC++ Ignore Warn(switch %qs has been removed and is set automaticaly where required) > > Spelling, automatically. > > > + targetting Darwin. However, the flag overrides have not be called yet. */ > > Spelling, targeting. > > > + if (flag_objc_exceptions) > > + /* ??? Should we warn that this is incompatible, if the user has set it. > > + For now, just force it it off. */ > > + flag_exceptions = 0; > > Where was this in the previous code? In ObjC++, exceptions can be on for C++ and should not be turned off. Does this code ever turn off C++ exceptions? flag_exceptions also triggers middle-end behavior - without it no statement can possibly throw. Thus, resetting it can't be ok. Richard.
On Nov 10, 2011, at 1:35 AM, Richard Guenther <rguenther@suse.de> wrote: > flag_exceptions also triggers middle-end behavior - without it no > statement can possibly throw Actually, one version of exception handling for objective c++ doesn't require flag_exceptions... One can indeed @throw without it, they just can't throw without it.
Hi Mike, just want to state my understanding to allow you to comment if I'm off.... On 10 Nov 2011, at 16:12, Mike Stump wrote: > On Nov 10, 2011, at 1:35 AM, Richard Guenther <rguenther@suse.de> > wrote: >> flag_exceptions also triggers middle-end behavior - without it no >> statement can possibly throw > > Actually, one version of exception handling for objective c++ > doesn't require flag_exceptions... One can indeed @throw without > it, they just can't throw without it. Thanks for catching that --- brainstorm on my part ... the code under discussion should have been #ifndef OBCPLUS Unfortunately, that particular blunder wasn't caught by the test-suite (which passes with the code I posted). -=- Specifically: NeXT m32 (ABI=0 or 1) uses SjLj exceptions for @throw etc. (and the @throw is done from a library routine). Moreover, there is no personality routine in m32 NeXT libobjc, so if one tries to engage the zero-cost exceptions, one gets a link error (and generates a load of unused eh data). I can work around that if there is still reason to have "-fexceptions" on. When c++ exceptions are operated in parallel with the ObjC ones - the personality routine is pointed at the libstc++ one. === m64 NeXT is a different beast altogether and the @throw and throw exceptions work together using the same unwinder. === With Joseph's suggestion I don't have a problem with the early use of flag_next_runtime - which means I can split the patch up - as I know Mike would prefer. ... will try an post a new version later. Iain
On Nov 10, 2011, at 9:40 AM, Iain Sandoe wrote: > Thanks for catching that --- brainstorm on my part ... the code under discussion should have been #ifndef OBCPLUS There is no prohibition against C having exceptions, so, doesn't matter if you turn C++ off, you can still throw through C code, so turning on exceptions is reasonable. > Moreover, there is no personality routine in m32 NeXT libobjc, so if one tries to engage the zero-cost exceptions, one gets a link error (and generates a load of unused eh data). I can work around that if there is still reason to have "-fexceptions" on. No, this must be wrong: $ cat t.c void bar() { } void foo() { bar(); } int main() { return 0; } $ gcc -fexceptions t.c $ gcc -m32 -fexceptions t.c $ Like I said, it does work, one can count on it working and it is useful, you can't break it. And next week, they'll add catching and throwing to C, and when they do, it still has to just work. :-)
On 11 Nov 2011, at 00:30, Mike Stump wrote: > On Nov 10, 2011, at 9:40 AM, Iain Sandoe wrote: >> Thanks for catching that --- brainstorm on my part ... the code >> under discussion should have been #ifndef OBCPLUS > > There is no prohibition against C having exceptions, so, doesn't > matter if you turn C++ off, you can still throw through C code, so > turning on exceptions is reasonable. > >> Moreover, there is no personality routine in m32 NeXT libobjc, so >> if one tries to engage the zero-cost exceptions, one gets a link >> error (and generates a load of unused eh data). I can work around >> that if there is still reason to have "-fexceptions" on. > > No, this must be wrong: > > $ cat t.c > void bar() { > } > > void foo() { > bar(); > } > > > int main() { > return 0; > } > $ gcc -fexceptions t.c > $ gcc -m32 -fexceptions t.c > $ > > Like I said, it does work, one can count on it working and it is > useful, you can't break it. And next week, they'll add catching and > throwing to C, and when they do, it still has to just work. :-) FWIW your example doesn't reproduce the problem because it contains no objective c exceptions code. However, OK - I see your point (I also see where the problem came from). in the code before the split there is this path (note gcc-4.2.1 system versionl): $ gcc-4.2 ../gcc-live-trunk/gcc/testsuite/objc.dg/exceptions-2.m - lobjc -fobjc-exceptions -fno-objc-sjlj-exceptions -o t Undefined symbols: "___gnu_objc_personality_v0", referenced from: ___gnu_objc_personality_v0$non_lazy_ptr in ccOk5CMv.o ld: symbol(s) not found collect2: ld returned 1 exit status I have incorrectly made that path apply to ABI=0,1 NeXT regardless of the setting of fobjc-sjlj-exceptions. This doesn't affect GNU runtime or NeXT m64. Patch under test to fix this (will post later). Iain
On Nov 11, 2011, at 12:25 AM, Iain Sandoe wrote: > FWIW your example doesn't reproduce the problem because it contains no objective c exceptions code. Ah, but it can be seen to contradict what you said. It also found a bug. > However, OK - I see your point (I also see where the problem came from). :-) Which is why it is occasionally important to restate the obvious, to ensure we're all on the same page. > Patch under test to fix this (will post later). Thanks.
Index: gcc/flags.h =================================================================== --- gcc/flags.h (revision 181206) +++ gcc/flags.h (working copy) @@ -56,10 +56,6 @@ extern bool final_insns_dump_p; /* Nonzero means make permerror produce warnings instead of errors. */ extern int flag_permissive; - -/* Generate code for GNU or NeXT Objective-C runtime environment. */ - -extern int flag_next_runtime; /* Other basic status info about current function. */ Index: gcc/c-family/c.opt =================================================================== --- gcc/c-family/c.opt (revision 181206) +++ gcc/c-family/c.opt (working copy) @@ -810,7 +810,7 @@ C++ ObjC++ Var(flag_no_gnu_keywords, 0) Recognize GNU-defined keywords fgnu-runtime -ObjC ObjC++ +ObjC ObjC++ Report RejectNegative Var(flag_next_runtime,0) Generate code for GNU runtime environment fgnu89-inline @@ -872,7 +872,7 @@ fnew-abi C++ ObjC++ Ignore Warn(switch %qs is no longer supported) fnext-runtime -ObjC ObjC++ +ObjC ObjC++ Report RejectNegative Var(flag_next_runtime) Generate code for NeXT (Apple Mac OS X) runtime environment fnil-receivers @@ -919,8 +919,8 @@ Enable inline checks for nil receivers with the Ne ; Nonzero means that we generate NeXT setjmp based exceptions. fobjc-sjlj-exceptions -ObjC ObjC++ Var(flag_objc_sjlj_exceptions) Init(-1) -Enable Objective-C setjmp exception handling runtime +ObjC ObjC++ Ignore Warn(switch %qs has been removed and is set automaticaly where required) +Option removed fobjc-std=objc1 ObjC ObjC++ Var(flag_objc1_only) Index: gcc/c-family/c-opts.c =================================================================== --- gcc/c-family/c-opts.c (revision 181206) +++ gcc/c-family/c-opts.c (working copy) @@ -604,14 +604,6 @@ c_common_handle_option (size_t scode, const char * cpp_opts->extended_identifiers = value; break; - case OPT_fgnu_runtime: - flag_next_runtime = !value; - break; - - case OPT_fnext_runtime: - flag_next_runtime = value; - break; - case OPT_foperator_names: cpp_opts->operator_names = value; break; @@ -902,12 +894,6 @@ c_common_post_options (const char **pfilename) else if (!flag_gnu89_inline && !flag_isoc99) error ("-fno-gnu89-inline is only supported in GNU99 or C99 mode"); - /* Default to ObjC sjlj exception handling if NeXT runtime. */ - if (flag_objc_sjlj_exceptions < 0) - flag_objc_sjlj_exceptions = flag_next_runtime; - if (flag_objc_exceptions && !flag_objc_sjlj_exceptions) - flag_exceptions = 1; - /* -Wextra implies the following flags unless explicitly overridden. */ if (warn_type_limits == -1) Index: gcc/objc/objc-next-runtime-abi-01.c =================================================================== --- gcc/objc/objc-next-runtime-abi-01.c (revision 181206) +++ gcc/objc/objc-next-runtime-abi-01.c (working copy) @@ -145,14 +145,19 @@ static tree finish_try_stmt (struct objc_try_conte bool objc_next_runtime_abi_01_init (objc_runtime_hooks *rthooks) { - if (flag_objc_exceptions - && !flag_objc_sjlj_exceptions) - { - warning_at (UNKNOWN_LOCATION, OPT_Wall, - "%<-fobjc-sjlj-exceptions%> is the only supported exceptions " - "system for %<-fnext-runtime%> with %<-fobjc-abi-version%> < 2"); - } + /* flag_objc_sjlj_exceptions has been removed as a User option. For now, + we'll simply force this on - since, for the foreseeable future the only + supported exceptions scheme for NeXT V0/1 is SjLj. It's always on, for + NeXT ABI 0 and 1. */ + + flag_objc_sjlj_exceptions = true; + + if (flag_objc_exceptions) + /* ??? Should we warn that this is incompatible, if the user has set it. + For now, just force it it off. */ + flag_exceptions = 0; + rthooks->initialize = next_runtime_01_initialize; rthooks->default_constant_string_class_name = DEF_CONSTANT_STRING_CLASS_NAME; rthooks->tag_getclass = TAG_GETCLASS; Index: gcc/objc/objc-act.c =================================================================== --- gcc/objc/objc-act.c (revision 181206) +++ gcc/objc/objc-act.c (working copy) @@ -267,6 +267,11 @@ FILE *gen_declaration_file; /* Hooks for stuff that differs between runtimes. */ objc_runtime_hooks runtime; +/* We've removed the SjLj switch, but there is still one case where the + code generated here needs to account for it. */ + +bool flag_objc_sjlj_exceptions = false; + /* Create a temporary variable of type 'type'. If 'name' is set, uses the specified name, else use no name. Returns the declaration of the type. The 'name' is mostly useful for debugging. Index: gcc/objc/objc-next-runtime-abi-02.c =================================================================== --- gcc/objc/objc-next-runtime-abi-02.c (revision 181206) +++ gcc/objc/objc-next-runtime-abi-02.c (working copy) @@ -239,11 +239,17 @@ objc_next_runtime_abi_02_init (objc_runtime_hooks { extern_names = ggc_alloc_cleared_vec_hash (SIZEHASHTABLE); - if (flag_objc_exceptions && flag_objc_sjlj_exceptions) + if (flag_objc_exceptions) { - inform (UNKNOWN_LOCATION, "%<-fobjc-sjlj-exceptions%> is ignored for " - "%<-fnext-runtime%> when %<-fobjc-abi-version%> >= 2"); - flag_objc_sjlj_exceptions = 0; + /* If the User has not specified fexceptions, set it silently. */ + if (!global_options_set.x_flag_exceptions) + flag_exceptions = 1; + else if (!flag_exceptions) + /* If the User has explicitly specified -fno-exceptions together + with -fobjc-exceptions, this is an error. */ + error_at (UNKNOWN_LOCATION, "%<-fobjc-exceptions%> requires" + "%<-fexceptions%> for the 64 bit NeXT" + " runtime"); } rthooks->initialize = next_runtime_02_initialize; Index: gcc/objc/objc-act.h =================================================================== --- gcc/objc/objc-act.h (revision 181206) +++ gcc/objc/objc-act.h (working copy) @@ -689,6 +689,11 @@ struct objc_try_context tree rethrow_decl; }; +/* We've removed the SjLj switch, but there is still one case where the + code generated in objc-act.c needs to account for it. */ + +extern bool flag_objc_sjlj_exceptions; + /* A small number of routines used by the FE parser and the runtime code generators. Put here as inlines for efficiency in non-lto builds rather than making them externs. */ Index: gcc/objc/objc-gnu-runtime-abi-01.c =================================================================== --- gcc/objc/objc-gnu-runtime-abi-01.c (revision 181206) +++ gcc/objc/objc-gnu-runtime-abi-01.c (working copy) @@ -132,12 +132,17 @@ objc_gnu_runtime_abi_01_init (objc_runtime_hooks * flag_objc_gc = 0; } - /* Although I guess we could, we don't currently support SJLJ exceptions for the - GNU runtime. */ - if (flag_objc_sjlj_exceptions) + /* Objective C exceptions implies -fexceptions for the GNU Runtime. */ + if (flag_objc_exceptions) { - inform (UNKNOWN_LOCATION, "%<-fobjc-sjlj-exceptions%> is ignored for %<-fgnu-runtime%>"); - flag_objc_sjlj_exceptions = 0; + /* If the User has not specified fexceptions, set it silently. */ + if (!global_options_set.x_flag_exceptions) + flag_exceptions = 1; + else if (!flag_exceptions) + /* If the User has explicitly specified -fno-exceptions together + with -fobjc-exceptions, this is an error. */ + error_at (UNKNOWN_LOCATION, "%<-fobjc-exceptions%> requires" + "%<-fexceptions%> for the GNU runtime"); } /* TODO: Complain if -fobjc-abi-version=N was used. */ Index: gcc/toplev.c =================================================================== --- gcc/toplev.c (revision 181206) +++ gcc/toplev.c (working copy) @@ -146,14 +146,6 @@ HOST_WIDE_INT random_seed; /* -f flags. */ -/* Generate code for GNU or NeXT Objective-C runtime environment. */ - -#ifdef NEXT_OBJC_RUNTIME -int flag_next_runtime = 1; -#else -int flag_next_runtime = 0; -#endif - /* Nonzero means make permerror produce warnings instead of errors. */ int flag_permissive = 0; Index: gcc/config/darwin-c.c =================================================================== --- gcc/config/darwin-c.c (revision 181206) +++ gcc/config/darwin-c.c (working copy) @@ -478,9 +478,12 @@ darwin_register_objc_includes (const char *sysroot fname = GCC_INCLUDE_DIR "-gnu-runtime"; /* Register the GNU OBJC runtime include path if we are compiling OBJC - with GNU-runtime. */ + with GNU-runtime. We 'know' that the default is NeXT, since we're + targetting Darwin. However, the flag overrides have not be called yet. */ - if (c_dialect_objc () && !flag_next_runtime) + if (c_dialect_objc () + && global_options_set.x_flag_next_runtime + && !flag_next_runtime) { char *str; /* See if our directory starts with the standard prefix. Index: gcc/config/darwin.c =================================================================== --- gcc/config/darwin.c (revision 181206) +++ gcc/config/darwin.c (working copy) @@ -2934,6 +2937,36 @@ darwin_override_options (void) /* Earlier versions are not specifically accounted, until required. */ } + /* In principle, this should be c-family only. However, we really need to + set sensible defaults for LTO as well, since the section selection stuff + should check for correctness re. the ABI. TODO: check and provide the + flags (runtime & ABI) from the lto wrapper). */ + + if (!global_options_set.x_flag_next_runtime) + flag_next_runtime = 1; + + /* Unless set, force ABI=2 for NeXT and m64, 0 otherwise. */ + if (!global_options_set.x_flag_objc_abi) + global_options.x_flag_objc_abi + = (!flag_next_runtime) + ? 0 + : (TARGET_64BIT ? 2 + : (generating_for_darwin_version >= 9) ? 1 + : 0); + + /* Objective-C family ABI 2 is only valid for next/m64 at present. */ + if (global_options_set.x_flag_objc_abi && flag_next_runtime) + { + if (TARGET_64BIT && global_options.x_flag_objc_abi < 2) + error_at (UNKNOWN_LOCATION, "%<-fobjc-abi-version%> >= 2 must be" + " used for %<-m64%> targets with" + " %<-fnext-runtime%>"); + if (!TARGET_64BIT && global_options.x_flag_objc_abi >= 2) + error_at (UNKNOWN_LOCATION, "%<-fobjc-abi-version%> >= 2 is not" + " supported on %<-m32%> targets with" + " %<-fnext-runtime%>"); + } + /* Don't emit DWARF3/4 unless specifically selected. This is a workaround for tool bugs. */ if (!global_options_set.x_dwarf_strict) Index: gcc/config/darwin.h =================================================================== --- gcc/config/darwin.h (revision 181206) +++ gcc/config/darwin.h (working copy) @@ -140,21 +140,6 @@ extern GTY(()) int darwin_ms_struct; } while (0) #define SUBTARGET_C_COMMON_OVERRIDE_OPTIONS do { \ - /* Unless set, force ABI=2 for NeXT and m64, 0 otherwise. */ \ - if (!global_options_set.x_flag_objc_abi) \ - global_options.x_flag_objc_abi \ - = (flag_next_runtime && TARGET_64BIT) ? 2 : 0; \ - /* Objective-C family ABI 2 is only valid for next/m64 at present. */ \ - if (global_options_set.x_flag_objc_abi && flag_next_runtime) \ - if (TARGET_64BIT && global_options.x_flag_objc_abi < 2) \ - error_at (UNKNOWN_LOCATION, "%<-fobjc-abi-version%> >= 2 is only" \ - " supported on %<-m64%> targets for" \ - " %<-fnext-runtime%>"); \ - /* Sort out ObjC exceptions: If the runtime is NeXT we default to \ - sjlj for m32 only. */ \ - if (!global_options_set.x_flag_objc_sjlj_exceptions) \ - global_options.x_flag_objc_sjlj_exceptions = \ - flag_next_runtime && !TARGET_64BIT; \ if (flag_mkernel || flag_apple_kext) \ { \ if (flag_use_cxa_atexit == 2) \