Re: [PATCH, rs6000] Preserve link stack for 476 cpus
Peter Bergner berg...@vnet.ibm.com writes: Hmmm, more fallout from the libgcc move. I think I'm just going to use an older checkout to test with until the libgcc fallout gets fixed. ... xgcc: error: ecrti.S: No such file or directory xgcc: fatal error: no input files compilation terminated. make[5]: *** [ecrti.o] Error 1 make[5]: Leaving directory `/home/bergner/gcc/build/gcc-mainline-476-dje/powerpc64-linux/32/libgcc' ... I sent a patch for that one: http://gcc.gnu.org/ml/gcc-patches/2011-11/msg00300.html plus Paolo's typo fix: http://gcc.gnu.org/ml/gcc-patches/2011-11/msg00302.html Rainer -- - Rainer Orth, Center for Biotechnology, Bielefeld University
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Thu, 2011-11-03 at 14:48 +0100, Rainer Orth wrote: I sent a patch for that one: http://gcc.gnu.org/ml/gcc-patches/2011-11/msg00300.html plus Paolo's typo fix: http://gcc.gnu.org/ml/gcc-patches/2011-11/msg00302.html Thanks, I kicked off a bootstrap with those changes. I'll let you know how it goes. Peter
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
Peter Bergner berg...@vnet.ibm.com writes: On Thu, 2011-11-03 at 09:13 -0500, Peter Bergner wrote: On Thu, 2011-11-03 at 14:48 +0100, Rainer Orth wrote: I sent a patch for that one: http://gcc.gnu.org/ml/gcc-patches/2011-11/msg00300.html plus Paolo's typo fix: http://gcc.gnu.org/ml/gcc-patches/2011-11/msg00302.html Thanks, I kicked off a bootstrap with those changes. I'll let you know how it goes. My powerpc64-linux bootstrap completed with no errors with those patches. Thanks. Great, thanks for the confirmation. Rainer -- - Rainer Orth, Center for Biotechnology, Bielefeld University
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Thu, 2011-11-03 at 09:13 -0500, Peter Bergner wrote: On Thu, 2011-11-03 at 14:48 +0100, Rainer Orth wrote: I sent a patch for that one: http://gcc.gnu.org/ml/gcc-patches/2011-11/msg00300.html plus Paolo's typo fix: http://gcc.gnu.org/ml/gcc-patches/2011-11/msg00302.html Thanks, I kicked off a bootstrap with those changes. I'll let you know how it goes. My powerpc64-linux bootstrap completed with no errors with those patches. Thanks. Peter
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Tue, Nov 1, 2011 at 3:00 PM, Peter Bergner berg...@vnet.ibm.com wrote: +/* Fills in the label name that should be used for a 476 link stack thunk. */ + +void +get_ppc476_thunk_name (char name[32]) +{ + gcc_assert (TARGET_LINK_STACK); + + if (HAVE_GAS_HIDDEN) + sprintf (name, __ppc476.get_thunk); + else + ASM_GENERATE_INTERNAL_LABEL (name, LPPC476_, 0); +} + +/* This function emits the simple thunk routine that is used to preserve + the link stack on the 476 cpu. */ + +static void +rs6000_code_end (void) +{ + char name[32]; + tree decl; + + if (!TARGET_LINK_STACK) + return; + + get_ppc476_thunk_name (name); + + decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, get_identifier (name), + build_function_type_list (void_type_node, NULL_TREE)); + DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL, + NULL_TREE, void_type_node); + TREE_PUBLIC (decl) = 1; + TREE_STATIC (decl) = 1; + + if (HAVE_GAS_HIDDEN) + { + DECL_COMDAT_GROUP (decl) = DECL_ASSEMBLER_NAME (decl); + targetm.asm_out.unique_section (decl, 0); + switch_to_section (get_named_section (decl, NULL, 0)); + DECL_WEAK (decl) = 1; + ASM_WEAKEN_DECL (asm_out_file, decl, name, 0); + targetm.asm_out.globalize_label (asm_out_file, name); + targetm.asm_out.assemble_visibility (decl, VISIBILITY_HIDDEN); + ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl); + } + else + { + switch_to_section (text_section); + ASM_OUTPUT_LABEL (asm_out_file, name); + } + + DECL_INITIAL (decl) = make_node (BLOCK); + current_function_decl = decl; + init_function_start (decl); + first_function_block_is_cold = false; + /* Make sure unwind info is emitted for the thunk if needed. */ + final_start_function (emit_barrier (), asm_out_file, 1); + + fputs (\tblr\n, asm_out_file); + + final_end_function (); + init_insn_lengths (); + free_after_compilation (cfun); + set_cfun (NULL); + current_function_decl = NULL; The two new functions have mistakes because I did not realize the semantics of HAVE_GAS_HIDDEN. HAVE_GAS_HIDDEN is not a macro to be tested at runtime, but a macro tested at compile time. if (HAVE_GAS_HIDDEN) should be #ifdef HAVE_GAS_HIDDEN Please correct. Thanks, David
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On 2 Nov 2011, at 17:18, David Edelsohn wrote: On Tue, Nov 1, 2011 at 3:00 PM, Peter Bergner berg...@vnet.ibm.com wrote: +/* Fills in the label name that should be used for a 476 link stack thunk. */ + +void +get_ppc476_thunk_name (char name[32]) +{ + gcc_assert (TARGET_LINK_STACK); + + if (HAVE_GAS_HIDDEN) +sprintf (name, __ppc476.get_thunk); + else +ASM_GENERATE_INTERNAL_LABEL (name, LPPC476_, 0); +} + +/* This function emits the simple thunk routine that is used to preserve + the link stack on the 476 cpu. */ + +static void +rs6000_code_end (void) +{ + char name[32]; + tree decl; + + if (!TARGET_LINK_STACK) +return; + + get_ppc476_thunk_name (name); + + decl = build_decl (BUILTINS_LOCATION, FUNCTION_DECL, get_identifier (name), +build_function_type_list (void_type_node, NULL_TREE)); + DECL_RESULT (decl) = build_decl (BUILTINS_LOCATION, RESULT_DECL, + NULL_TREE, void_type_node); + TREE_PUBLIC (decl) = 1; + TREE_STATIC (decl) = 1; + + if (HAVE_GAS_HIDDEN) +{ + DECL_COMDAT_GROUP (decl) = DECL_ASSEMBLER_NAME (decl); + targetm.asm_out.unique_section (decl, 0); + switch_to_section (get_named_section (decl, NULL, 0)); + DECL_WEAK (decl) = 1; + ASM_WEAKEN_DECL (asm_out_file, decl, name, 0); + targetm.asm_out.globalize_label (asm_out_file, name); + targetm.asm_out.assemble_visibility (decl, VISIBILITY_HIDDEN); + ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl); +} + else +{ + switch_to_section (text_section); + ASM_OUTPUT_LABEL (asm_out_file, name); +} + + DECL_INITIAL (decl) = make_node (BLOCK); + current_function_decl = decl; + init_function_start (decl); + first_function_block_is_cold = false; + /* Make sure unwind info is emitted for the thunk if needed. */ + final_start_function (emit_barrier (), asm_out_file, 1); + + fputs (\tblr\n, asm_out_file); + + final_end_function (); + init_insn_lengths (); + free_after_compilation (cfun); + set_cfun (NULL); + current_function_decl = NULL; The two new functions have mistakes because I did not realize the semantics of HAVE_GAS_HIDDEN. HAVE_GAS_HIDDEN is not a macro to be tested at runtime, but a macro tested at compile time. if (HAVE_GAS_HIDDEN) should be #ifdef HAVE_GAS_HIDDEN also in macho_branch_islands () : if (TARGET_LINK_STACK) { char name[32]; get_ppc64_thunk_name (name); strcat (tmp_buf, :\n\tmflr r0\n\tbl ); strcat (tmp_buf, name); strcat (tmp_buf, \n); strcat (tmp_buf, label); strcat (tmp_buf, _pic:\n\tmflr r11\n); } else which breaks bootstrap for darwin - I'm not sure why you have an entry here (this is mach-o-specific code) - I doubt there will ever be a mach-o implementation with a PPC476 - but, in any case the call to get_ppc64_thunk_name needs wrapping somehow. cheers Iain
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Wed, 2011-11-02 at 18:17 +, Iain Sandoe wrote: also in macho_branch_islands () : if (TARGET_LINK_STACK) { char name[32]; get_ppc64_thunk_name (name); strcat (tmp_buf, :\n\tmflr r0\n\tbl ); strcat (tmp_buf, name); strcat (tmp_buf, \n); strcat (tmp_buf, label); strcat (tmp_buf, _pic:\n\tmflr r11\n); } else which breaks bootstrap for darwin - I'm not sure why you have an entry here (this is mach-o-specific code) - I doubt there will ever be a mach-o implementation with a PPC476 - but, in any case the call to get_ppc64_thunk_name needs wrapping somehow. How is it failing for you? And what are your configure options so I can try and recreate the error? If it's similar to what Alan saw but for get_ppc64_thunk_name, namely: rs6000.c:27968:1: error: 'void rs6000_code_end()' defined but not used [-Werror=unused-function] cc1plus: all warnings being treated as errors Does the following fix it for you? Index: config/rs6000/rs6000-protos.h === --- config/rs6000/rs6000-protos.h (revision 180786) +++ config/rs6000/rs6000-protos.h (working copy) @@ -173,7 +173,7 @@ extern void rs6000_emit_eh_reg_restore ( extern const char * output_isel (rtx *); extern void rs6000_call_indirect_aix (rtx, rtx, rtx); extern void rs6000_aix_asm_output_dwarf_table_ref (char *); -extern void get_ppc476_thunk_name (char name[32]); +extern void get_ppc476_thunk_name (char name[32]) ATTRIBUTE_UNUSED; /* Declare functions in rs6000-c.c */ Peter
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Wed, 2011-11-02 at 13:18 -0400, David Edelsohn wrote: The two new functions have mistakes because I did not realize the semantics of HAVE_GAS_HIDDEN. HAVE_GAS_HIDDEN is not a macro to be tested at runtime, but a macro tested at compile time. I'm sorry, I didn't realize that either. Does the following fix your problem? Peter * config/rs6000/rs6000.c (USE_HIDDEN_LINKONCE): New define. (get_ppc476_thunk_name): Use it. (rs6000_code_end): Likewise. Index: config/rs6000/rs6000.c === --- config/rs6000/rs6000.c (revision 180786) +++ config/rs6000/rs6000.c (working copy) @@ -27949,6 +27949,12 @@ rs6000_save_toc_in_prologue_p (void) return (cfun cfun-machine cfun-machine-save_toc_in_prologue); } +#ifdef HAVE_GAS_HIDDEN +# define USE_HIDDEN_LINKONCE 1 +#else +# define USE_HIDDEN_LINKONCE 0 +#endif + /* Fills in the label name that should be used for a 476 link stack thunk. */ void @@ -27956,7 +27962,7 @@ get_ppc476_thunk_name (char name[32]) { gcc_assert (TARGET_LINK_STACK); - if (HAVE_GAS_HIDDEN) + if (USE_HIDDEN_LINKONCE) sprintf (name, __ppc476.get_thunk); else ASM_GENERATE_INTERNAL_LABEL (name, LPPC476_, 0); @@ -27983,7 +27989,7 @@ rs6000_code_end (void) TREE_PUBLIC (decl) = 1; TREE_STATIC (decl) = 1; - if (HAVE_GAS_HIDDEN) + if (USE_HIDDEN_LINKONCE) { DECL_COMDAT_GROUP (decl) = DECL_ASSEMBLER_NAME (decl); targetm.asm_out.unique_section (decl, 0);
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On 2 Nov 2011, at 18:34, Peter Bergner wrote: On Wed, 2011-11-02 at 18:17 +, Iain Sandoe wrote: also in macho_branch_islands () : if (TARGET_LINK_STACK) { char name[32]; get_ppc64_thunk_name (name); strcat (tmp_buf, :\n\tmflr r0\n\tbl ); strcat (tmp_buf, name); strcat (tmp_buf, \n); strcat (tmp_buf, label); strcat (tmp_buf, _pic:\n\tmflr r11\n); } else which breaks bootstrap for darwin - I'm not sure why you have an entry here (this is mach-o-specific code) - I doubt there will ever be a mach-o implementation with a PPC476 - but, in any case the call to get_ppc64_thunk_name needs wrapping somehow. How is it failing for you? And what are your configure options so I can try and recreate the error? /GCC/gcc-live-trunk/gcc/config/rs6000/rs6000.c: In function ‘void macho_branch_islands()’: /GCC/gcc-live-trunk/gcc/config/rs6000/rs6000.c:25074:34: error: ‘get_ppc64_thunk_name’ was not declared in this scope make[3]: *** [rs6000.o] Error 1 make[3]: *** Waiting for unfinished jobs /GCC/gcc-live-trunk/configure --prefix=/GCC/gcc-4-7-tempi -- target=powerpc-apple-darwin9 --host=powerpc-apple-darwin9 -- build=powerpc-apple-darwin9 --enable-version-specific-runtime-libs -- enable-checking=yes --with-libiconv-prefix=/usr --with-system-zlib -- with-gmp=/GCC/multiprec-math/ppc --with-mpfr=/GCC/multiprec-math/ppc --with-mpc=/GCC/multiprec-math/ppc --enable-languages=c,c+ +,fortran,ada,objc,obj-c++,lto etc.. === Hmm .. I wonder if this is just a temporary glitch because of the move of files to libgcc. I'll investigate a bit further later... If it's similar to what Alan saw but for get_ppc64_thunk_name, namely: rs6000.c:27968:1: error: 'void rs6000_code_end()' defined but not used [-Werror=unused-function] cc1plus: all warnings being treated as errors Does the following fix it for you? Index: config/rs6000/rs6000-protos.h === --- config/rs6000/rs6000-protos.h (revision 180786) +++ config/rs6000/rs6000-protos.h (working copy) @@ -173,7 +173,7 @@ extern void rs6000_emit_eh_reg_restore ( extern const char * output_isel (rtx *); extern void rs6000_call_indirect_aix (rtx, rtx, rtx); extern void rs6000_aix_asm_output_dwarf_table_ref (char *); -extern void get_ppc476_thunk_name (char name[32]); +extern void get_ppc476_thunk_name (char name[32]) ATTRIBUTE_UNUSED; /* Declare functions in rs6000-c.c */ We do include this in tm_p.h $ more ../gcc-4-7-trunk-build/gcc/tm_p.h #ifndef GCC_TM_P_H #define GCC_TM_P_H #ifdef IN_GCC # include config/rs6000/rs6000-protos.h # include config/darwin-protos.h # include tm-preds.h #endif #endif /* GCC_TM_P_H */ .. but not in tm.h Iain
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Wed, 2011-11-02 at 18:52 +, Iain Sandoe wrote: Hmm .. I wonder if this is just a temporary glitch because of the move of files to libgcc. Note that I just hit a problem with the libgcc move. We need: Index: libgcc/config/rs6000/t-ppccomm === --- libgcc/config/rs6000/t-ppccomm (revision 180786) +++ libgcc/config/rs6000/t-ppccomm (working copy) @@ -7,7 +7,7 @@ LIB2ADD_ST += \ $(srcdir)/config/rs6000/crtresfpr.S \ $(srcdir)/config/rs6000/crtsavgpr.S \ $(srcdir)/config/rs6000/crtresgpr.S \ - $(srcdir)/config/rs6000/crtresxfpr.S + $(srcdir)/config/rs6000/crtresxfpr.S \ $(srcdir)/config/rs6000/crtresxgpr.S \ $(srcdir)/config/rs6000/e500crtres32gpr.S \ $(srcdir)/config/rs6000/e500crtres64gpr.S \ @@ -21,7 +21,7 @@ LIB2ADD_ST += \ $(srcdir)/config/rs6000/e500crtsav64gprctr.S \ $(srcdir)/config/rs6000/e500crtsavg32gpr.S \ $(srcdir)/config/rs6000/e500crtsavg64gpr.S \ - $(srcdir)/config/rs6000/e500crtsavg64gprctr.S + $(srcdir)/config/rs6000/e500crtsavg64gprctr.S \ $(srcdir)/config/rs6000/eabi.S I'm continuing my build to see if there's anything more that falls out from that...or my patch :(. I'll investigate a bit further later... So you didn't start your build from scratch? I'll keep my fingers crossed that a fresh build fixing things for you. Otherwise, let me know what you find. Peter
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Wed, 2011-11-02 at 19:33 +, Iain Sandoe wrote: I'm going to try this $ svn diff -x -p gcc/config/rs6000/rs6000.c Index: gcc/config/rs6000/rs6000.c === --- gcc/config/rs6000/rs6000.c (revision 180788) +++ gcc/config/rs6000/rs6000.c (working copy) @@ -25071,7 +25071,7 @@ macho_branch_islands (void) if (TARGET_LINK_STACK) { char name[32]; - get_ppc64_thunk_name (name); + get_ppc476_thunk_name (name); strcat (tmp_buf, :\n\tmflr r0\n\tbl ); strcat (tmp_buf, name); strcat (tmp_buf, \n); Oh my, I'm not sure how that got through. :( Oh, as you said, that is TARGET_MACHO which I can't really test. Sorry about that. @@ -27956,10 +27956,11 @@ get_ppc476_thunk_name (char name[32]) { gcc_assert (TARGET_LINK_STACK); - if (HAVE_GAS_HIDDEN) +#if defined(HAVE_GAS_HIDDEN) sprintf (name, __ppc476.get_thunk); - else +#else ASM_GENERATE_INTERNAL_LABEL (name, LPPC476_, 0); +#endif } ... Instead of that, see my patch to fix David's AIX problem: http://gcc.gnu.org/ml/gcc-patches/2011-11/msg00198.html Peter
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Wed, 2011-11-02 at 14:05 -0500, Peter Bergner wrote: On Wed, 2011-11-02 at 18:52 +, Iain Sandoe wrote: Hmm .. I wonder if this is just a temporary glitch because of the move of files to libgcc. Note that I just hit a problem with the libgcc move. We need: Index: libgcc/config/rs6000/t-ppccomm === --- libgcc/config/rs6000/t-ppccomm(revision 180786) +++ libgcc/config/rs6000/t-ppccomm(working copy) @@ -7,7 +7,7 @@ LIB2ADD_ST += \ $(srcdir)/config/rs6000/crtresfpr.S \ $(srcdir)/config/rs6000/crtsavgpr.S \ $(srcdir)/config/rs6000/crtresgpr.S \ -$(srcdir)/config/rs6000/crtresxfpr.S +$(srcdir)/config/rs6000/crtresxfpr.S \ $(srcdir)/config/rs6000/crtresxgpr.S \ $(srcdir)/config/rs6000/e500crtres32gpr.S \ $(srcdir)/config/rs6000/e500crtres64gpr.S \ @@ -21,7 +21,7 @@ LIB2ADD_ST += \ $(srcdir)/config/rs6000/e500crtsav64gprctr.S \ $(srcdir)/config/rs6000/e500crtsavg32gpr.S \ $(srcdir)/config/rs6000/e500crtsavg64gpr.S \ -$(srcdir)/config/rs6000/e500crtsavg64gprctr.S +$(srcdir)/config/rs6000/e500crtsavg64gprctr.S \ $(srcdir)/config/rs6000/eabi.S I'm continuing my build to see if there's anything more that falls out from that...or my patch :(. Hmmm, more fallout from the libgcc move. I think I'm just going to use an older checkout to test with until the libgcc fallout gets fixed. ... xgcc: error: ecrti.S: No such file or directory xgcc: fatal error: no input files compilation terminated. make[5]: *** [ecrti.o] Error 1 make[5]: Leaving directory `/home/bergner/gcc/build/gcc-mainline-476-dje/powerpc64-linux/32/libgcc' ... Peter
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On 2 Nov 2011, at 19:39, Peter Bergner wrote: On Wed, 2011-11-02 at 19:33 +, Iain Sandoe wrote: I'm going to try this char name[32]; - get_ppc64_thunk_name (name); + get_ppc476_thunk_name (name); This (together with the changes for HAVE_GAS_HIDDEN) fixes my bootstrap problem. Oh my, I'm not sure how that got through. :( Well, I guess I should have looked at your patch before it hit trunk (I was mistakenly thinking it didn't touch Darwin). Oh, as you said, that is TARGET_MACHO which I can't really test. Sorry about that. FWIW, it's not really any worse building a cross from linux - darwin9*** than a cross to any other foreign OS from linux (there are a couple of differences - because of the non-binutils tool-chain). I did it recently. ** Rainer, AFAICT, all is OK with your (much appreciated) rationalization of libgcc on *-Darwin9 x86-64-Darwin10 (although testing is incomplete). cheers Iain *** x86-64-darwin10 and Darwin11 are more problematic, since the cross toolchains are not yet in place/mature (at least as of a few weeks ago).
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Wed, 2011-11-02 at 22:02 +, Iain Sandoe wrote: On 2 Nov 2011, at 19:39, Peter Bergner wrote: On Wed, 2011-11-02 at 19:33 +, Iain Sandoe wrote: I'm going to try this char name[32]; - get_ppc64_thunk_name (name); + get_ppc476_thunk_name (name); This (together with the changes for HAVE_GAS_HIDDEN) fixes my bootstrap problem. Ok, I committed the following as obvious. Sorry to you and David for the breakage. Peter 2011-11-02 Peter Bergner berg...@vnet.ibm.com Iain Sandoe ia...@gcc.gnu.org * config/rs6000/rs6000.c (USE_HIDDEN_LINKONCE): New define. (get_ppc476_thunk_name): Use it. (rs6000_code_end): Likewise. (macho_branch_islands): Fix typo. Index: gcc/config/rs6000/rs6000.c === --- gcc/config/rs6000/rs6000.c (revision 180813) +++ gcc/config/rs6000/rs6000.c (working copy) @@ -25071,7 +25071,7 @@ macho_branch_islands (void) if (TARGET_LINK_STACK) { char name[32]; - get_ppc64_thunk_name (name); + get_ppc476_thunk_name (name); strcat (tmp_buf, :\n\tmflr r0\n\tbl ); strcat (tmp_buf, name); strcat (tmp_buf, \n); @@ -27949,6 +27949,12 @@ rs6000_save_toc_in_prologue_p (void) return (cfun cfun-machine cfun-machine-save_toc_in_prologue); } +#ifdef HAVE_GAS_HIDDEN +# define USE_HIDDEN_LINKONCE 1 +#else +# define USE_HIDDEN_LINKONCE 0 +#endif + /* Fills in the label name that should be used for a 476 link stack thunk. */ void @@ -27956,7 +27962,7 @@ get_ppc476_thunk_name (char name[32]) { gcc_assert (TARGET_LINK_STACK); - if (HAVE_GAS_HIDDEN) + if (USE_HIDDEN_LINKONCE) sprintf (name, __ppc476.get_thunk); else ASM_GENERATE_INTERNAL_LABEL (name, LPPC476_, 0); @@ -27983,7 +27989,7 @@ rs6000_code_end (void) TREE_PUBLIC (decl) = 1; TREE_STATIC (decl) = 1; - if (HAVE_GAS_HIDDEN) + if (USE_HIDDEN_LINKONCE) { DECL_COMDAT_GROUP (decl) = DECL_ASSEMBLER_NAME (decl); targetm.asm_out.unique_section (decl, 0);
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Mon, 2011-10-31 at 19:05 -0400, David Edelsohn wrote: Okay, go ahead with PPC64 support as well. Hopefully no one ever will have to use it. That implies the option should not explicitly reference ppc476. Ok, for completeness, I attached what I committed below, which includes the support for 64-bit because it makes the code cleaner and changes the option name back to -mpreserve-link-stack. Thanks. Peter * config.gcc (powerpc*-*-linux*): Add powerpc*-*-linux*ppc476* variant. * config/rs6000/476.h: New file. * config/rs6000/476.opt: Likewise. * config/rs6000/rs6000.h (TARGET_LINK_STACK): New define. (SET_TARGET_LINK_STACK): Likewise. (TARGET_ASM_CODE_END): Define. * config/rs6000/rs6000.c (rs6000_option_override_internal): Enable TARGET_LINK_STACK for -mtune=476 and -mtune=476fp. (rs6000_legitimize_tls_address): Emit the link stack preserving GOT code if TARGET_LINK_STACK. (rs6000_emit_load_toc_table): Likewise. (output_function_profiler): Likewise (macho_branch_islands): Likewise (machopic_output_stub): Likewise (get_ppc476_thunk_name): New function. (rs6000_code_end): Likewise. * config/rs6000/rs6000.md (load_toc_v4_PIC_1, load_toc_v4_PIC_1b): Convert to a define_expand. (load_toc_v4_PIC_1_normal): New define_insn. (load_toc_v4_PIC_1_476): Likewise. (load_toc_v4_PIC_1b_normal): Likewise. (load_toc_v4_PIC_1b_476): Likewise. Index: gcc/config.gcc === --- gcc/config.gcc (revision 180740) +++ gcc/config.gcc (revision 180741) @@ -2145,6 +2145,9 @@ powerpc-*-linux* | powerpc64-*-linux*) esac tmake_file=${tmake_file} t-slibgcc-libgcc case ${target} in + powerpc*-*-linux*ppc476*) + tm_file=${tm_file} rs6000/476.h + extra_options=${extra_options} rs6000/476.opt ;; powerpc*-*-linux*altivec*) tm_file=${tm_file} rs6000/linuxaltivec.h ;; powerpc*-*-linux*spe*) Index: gcc/config/rs6000/476.h === --- gcc/config/rs6000/476.h (revision 0) +++ gcc/config/rs6000/476.h (revision 180741) @@ -0,0 +1,32 @@ +/* Enable IBM PowerPC 476 support. + Copyright (C) 2011 Free Software Foundation, Inc. + Contributed by Peter Bergner (berg...@vnet.ibm.com) + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GCC is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + http://www.gnu.org/licenses/. */ + +#undef TARGET_LINK_STACK +#define TARGET_LINK_STACK (rs6000_link_stack) + +#undef SET_TARGET_LINK_STACK +#define SET_TARGET_LINK_STACK(X) do { TARGET_LINK_STACK = (X); } while (0) + +#undef TARGET_ASM_CODE_END +#define TARGET_ASM_CODE_END rs6000_code_end Index: gcc/config/rs6000/rs6000-protos.h === --- gcc/config/rs6000/rs6000-protos.h (revision 180740) +++ gcc/config/rs6000/rs6000-protos.h (revision 180741) @@ -173,6 +173,7 @@ extern void rs6000_emit_eh_reg_restore ( extern const char * output_isel (rtx *); extern void rs6000_call_indirect_aix (rtx, rtx, rtx); extern void rs6000_aix_asm_output_dwarf_table_ref (char *); +extern void get_ppc476_thunk_name (char name[32]); /* Declare functions in rs6000-c.c */ Index: gcc/config/rs6000/476.opt === --- gcc/config/rs6000/476.opt (revision 0) +++ gcc/config/rs6000/476.opt (revision 180741) @@ -0,0 +1,24 @@ +; IBM PowerPC 476 options. +; +; Copyright (C) 2011 Free Software Foundation, Inc. +; Contributed by Peter Bergner (berg...@vnet.ibm.com) +; +; This file is part of GCC. +; +; GCC is free software; you can redistribute it and/or modify it under +; the terms of the GNU General Public License as published by the Free +; Software Foundation; either version 3, or (at your option) any later +; version. +; +; GCC is distributed in the hope that it will be useful, but WITHOUT ANY +; WARRANTY; without even the implied warranty
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Tue, Nov 01, 2011 at 02:00:25PM -0500, Peter Bergner wrote: (get_ppc476_thunk_name): New function. (rs6000_code_end): Likewise. rs6000.c:27968:1: error: 'void rs6000_code_end()' defined but not used [-Werror=unused-function] cc1plus: all warnings being treated as errors Bootstrapped and committed as obvious, revision 180761. * config/rs6000/rs6000.c (rs6000_code_end): Declare ATTRIBUTE_UNUSED. Index: gcc/config/rs6000/rs6000.c === --- gcc/config/rs6000/rs6000.c (revision 180754) +++ gcc/config/rs6000/rs6000.c (working copy) @@ -1176,6 +1176,7 @@ static void rs6000_trampoline_init (rtx, static bool rs6000_cannot_force_const_mem (enum machine_mode, rtx); static bool rs6000_legitimate_constant_p (enum machine_mode, rtx); static bool rs6000_save_toc_in_prologue_p (void); +static void rs6000_code_end (void) ATTRIBUTE_UNUSED; /* Hash table stuff for keeping track of TOC entries. */ -- Alan Modra Australia Development Lab, IBM
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Fri, 2011-10-28 at 15:37 -0400, David Edelsohn wrote: On Fri, Oct 28, 2011 at 12:36 PM, Peter Bergner berg...@vnet.ibm.com wrote: So David, do we even want to bother trying to support this on -m64 given the only cpu that needs this is a 32-bit only cpu? If so, I can try and work with Alan to figure out how we can merge the function descriptors for the thunk routines when using -m64. I barely want to bother with this ;-). So, no, I don't want to bother with -m64 support. Ok, attached below is the updated patch that passes bootstrap and regtesting that only enables the new link stack code for 32-bit compiles. However, talking with Alan, he mentioned we just have to mark the opd entry weak and that will fix my link problem (confirmed it does). It seems we might want to allow this on 64-bit too, since it actually makes the code cleaner wrt where we set TARGET_LINK_STACK. To get 64-bit working, we only need the following patch on top of the 32-bit only patch below: --- gcc/config/rs6000/rs6000.c.old 2011-10-31 16:16:04.0 -0500 +++ gcc/config/rs6000/rs6000.c 2011-10-31 16:16:37.0 -0500 @@ -3245,13 +3245,7 @@ /* If not explicitly specified via option, decide whether to generate the extra blr's required to preserve the link stack on some cpus (eg, 476). */ - if (TARGET_POWERPC64) -{ - if (TARGET_LINK_STACK 0) - warning (0, -m64 disables -mpreserve-ppc476-link-stack); - SET_TARGET_LINK_STACK (0); -} - else if (TARGET_LINK_STACK == -1) + if (TARGET_LINK_STACK == -1) SET_TARGET_LINK_STACK (rs6000_cpu == PROCESSOR_PPC476 flag_pic); return ret; @@ -27960,6 +27954,8 @@ DECL_COMDAT_GROUP (decl) = DECL_ASSEMBLER_NAME (decl); targetm.asm_out.unique_section (decl, 0); switch_to_section (get_named_section (decl, NULL, 0)); + DECL_WEAK (decl) = 1; + ASM_WEAKEN_DECL (asm_out_file, decl, name, 0); targetm.asm_out.globalize_label (asm_out_file, name); targetm.asm_out.assemble_visibility (decl, VISIBILITY_HIDDEN); ASM_DECLARE_FUNCTION_NAME (asm_out_file, name, decl); It's up to you David whether we should stick with the 32-bit only patch or go ahead and allow 64-bit too. What do you think? Peter * config.gcc (powerpc*-*-linux*): Add powerpc*-*-linux*ppc476* variant. * config/rs6000/476.h: New file. * config/rs6000/476.opt: Likewise. * config/rs6000/rs6000.h (TARGET_LINK_STACK): New define. (SET_TARGET_LINK_STACK): Likewise. (TARGET_ASM_CODE_END): Define. * config/rs6000/rs6000.c (rs6000_option_override_internal): Enable TARGET_LINK_STACK for -mtune=476 and -mtune=476fp. (rs6000_legitimize_tls_address): Emit the link stack preserving GOT code if TARGET_LINK_STACK. (rs6000_emit_load_toc_table): Likewise. (output_function_profiler): Likewise (macho_branch_islands): Likewise (machopic_output_stub): Likewise (get_ppc476_thunk_name): New function. (rs6000_code_end): Likewise. * config/rs6000/rs6000.md (load_toc_v4_PIC_1, load_toc_v4_PIC_1b): Convert to a define_expand. (load_toc_v4_PIC_1_normal): New define_insn. (load_toc_v4_PIC_1_476): Likewise. (load_toc_v4_PIC_1b_normal): Likewise. (load_toc_v4_PIC_1b_476): Likewise. Index: gcc/config.gcc === --- gcc/config.gcc (revision 179091) +++ gcc/config.gcc (working copy) @@ -2133,6 +2133,9 @@ powerpc-*-linux* | powerpc64-*-linux*) esac tmake_file=${tmake_file} t-slibgcc-libgcc case ${target} in + powerpc*-*-linux*ppc476*) + tm_file=${tm_file} rs6000/476.h + extra_options=${extra_options} rs6000/476.opt ;; powerpc*-*-linux*altivec*) tm_file=${tm_file} rs6000/linuxaltivec.h ;; powerpc*-*-linux*spe*) Index: gcc/config/rs6000/476.h === --- gcc/config/rs6000/476.h (revision 0) +++ gcc/config/rs6000/476.h (revision 0) @@ -0,0 +1,32 @@ +/* Enable IBM PowerPC 476 support. + Copyright (C) 2011 Free Software Foundation, Inc. + Contributed by Peter Bergner (berg...@vnet.ibm.com) + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GCC is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Mon, Oct 31, 2011 at 5:32 PM, Peter Bergner berg...@vnet.ibm.com wrote: Ok, attached below is the updated patch that passes bootstrap and regtesting that only enables the new link stack code for 32-bit compiles. However, talking with Alan, he mentioned we just have to mark the opd entry weak and that will fix my link problem (confirmed it does). It seems we might want to allow this on 64-bit too, since it actually makes the code cleaner wrt where we set TARGET_LINK_STACK. To get 64-bit working, we only need the following patch on top of the 32-bit only patch below: Okay, go ahead with PPC64 support as well. Hopefully no one ever will have to use it. That implies the option should not explicitly reference ppc476. - David
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On 10/27/2011 06:43 PM, Peter Bergner wrote: Ok, here's a patch to implement that, and it passes bootstrap and regtesting. Richard, is this what you had in mind? I'll note that I disabled rs6000_code_end for TARGET_POWERPC64, since I was running into linker errors when building libgcc. The merging of the thunk routines with comdat worked fine, but the thunk function also has a function descriptor and I couldn't figure out a way to get those merged properly (if it's even possible), so they led to multiply defined symbol linker errors. That's something you might have to discuss with David and Alan. You might wind up bypassing some of the normal boilerplate that gets added by final_start_function etc. It does look like you're missing the stub for ppc64, and yet you invoke it? At least, I don't see anything earlier that tests ppc64, only in rs6000_code_end. r~
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Fri, 2011-10-28 at 08:20 -0700, Richard Henderson wrote: On 10/27/2011 06:43 PM, Peter Bergner wrote: Ok, here's a patch to implement that, and it passes bootstrap and regtesting. Richard, is this what you had in mind? I'll note that I disabled rs6000_code_end for TARGET_POWERPC64, since I was running into linker errors when building libgcc. The merging of the thunk routines with comdat worked fine, but the thunk function also has a function descriptor and I couldn't figure out a way to get those merged properly (if it's even possible), so they led to multiply defined symbol linker errors. That's something you might have to discuss with David and Alan. So David, do we even want to bother trying to support this on -m64 given the only cpu that needs this is a 32-bit only cpu? If so, I can try and work with Alan to figure out how we can merge the function descriptors for the thunk routines when using -m64. It does look like you're missing the stub for ppc64, and yet you invoke it? At least, I don't see anything earlier that tests ppc64, only in rs6000_code_end. Oops, you're write. Had I compiled with -m64 -mcpu=power7 -mtune=476fp, I would have caught that. I guess (supposing we don't want to support 64-bit) I should have the following hunks instead, correct? + /* If not explicitly specified via option, decide whether to generate the + extra blr's required to preserve the link stack on some cpus (eg, 476). */ + if (TARGET_LINK_STACK == -1) +SET_TARGET_LINK_STACK (rs6000_cpu == PROCESSOR_PPC476 + flag_pic + !TARGET_POWERPC64); + +static void +rs6000_code_end (void) +{ + char name[32]; + tree decl; + + if (!TARGET_LINK_STACK) +return; ... Peter ~
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On 10/28/2011 09:36 AM, Peter Bergner wrote: Oops, you're write. Had I compiled with -m64 -mcpu=power7 -mtune=476fp, I would have caught that. I guess (supposing we don't want to support 64-bit) I should have the following hunks instead, correct? + /* If not explicitly specified via option, decide whether to generate the + extra blr's required to preserve the link stack on some cpus (eg, 476). */ + if (TARGET_LINK_STACK == -1) +SET_TARGET_LINK_STACK (rs6000_cpu == PROCESSOR_PPC476 + flag_pic + !TARGET_POWERPC64); Not quite. You can't allow the user to set TARGET_LINK_STACK either, for 64-bit. Because it won't work without further fixups. More like if (TARGET_POWERPC64) SET_TARGET_LINK_STACK (0); if (TARGET_LINK_STACK == -1) SET_TARGET_LINK_STACK (rs6000_cpu == PROCESSOR_PPC476 flag_pic); That first test could possibly be more refined, like testing AIX calling conventions or DOT_SYMBOLS. But it hardly seems worthwhile. r~
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Fri, 2011-10-28 at 09:44 -0700, Richard Henderson wrote: Not quite. You can't allow the user to set TARGET_LINK_STACK either, for 64-bit. Because it won't work without further fixups. More like if (TARGET_POWERPC64) SET_TARGET_LINK_STACK (0); if (TARGET_LINK_STACK == -1) SET_TARGET_LINK_STACK (rs6000_cpu == PROCESSOR_PPC476 flag_pic); Ah, I forgot about if the user explicitly uses -mpreserve-ppc476-link-stack. Ok, so how about if we also spit out a warning that we're implicitly disabling the link stack code rather than doing it silently? Like so: if (TARGET_POWERPC64) { if (TARGET_LINK_STACK 0) warning (0, -m64 disables -mpreserve-ppc476-link-stack); SET_TARGET_LINK_STACK (0); } else if (TARGET_LINK_STACK == -1) SET_TARGET_LINK_STACK (rs6000_cpu == PROCESSOR_PPC476 flag_pic); Peter
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On 10/28/2011 11:35 AM, Peter Bergner wrote: On Fri, 2011-10-28 at 09:44 -0700, Richard Henderson wrote: Not quite. You can't allow the user to set TARGET_LINK_STACK either, for 64-bit. Because it won't work without further fixups. More like if (TARGET_POWERPC64) SET_TARGET_LINK_STACK (0); if (TARGET_LINK_STACK == -1) SET_TARGET_LINK_STACK (rs6000_cpu == PROCESSOR_PPC476 flag_pic); Ah, I forgot about if the user explicitly uses -mpreserve-ppc476-link-stack. Ok, so how about if we also spit out a warning that we're implicitly disabling the link stack code rather than doing it silently? Like so: if (TARGET_POWERPC64) { if (TARGET_LINK_STACK 0) warning (0, -m64 disables -mpreserve-ppc476-link-stack); SET_TARGET_LINK_STACK (0); } else if (TARGET_LINK_STACK == -1) SET_TARGET_LINK_STACK (rs6000_cpu == PROCESSOR_PPC476 flag_pic); Fine by me. Final rs6000 approval is dje's bivouac. r~
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Fri, Oct 28, 2011 at 12:36 PM, Peter Bergner berg...@vnet.ibm.com wrote: So David, do we even want to bother trying to support this on -m64 given the only cpu that needs this is a 32-bit only cpu? If so, I can try and work with Alan to figure out how we can merge the function descriptors for the thunk routines when using -m64. I barely want to bother with this ;-). So, no, I don't want to bother with -m64 support. - David
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Thu, 2011-10-13 at 10:03 -0700, Richard Henderson wrote: On 10/13/2011 08:49 AM, Peter Bergner wrote: + if (TARGET_LINK_STACK) + asm_fprintf (file, \tbl 1f\n\tb 2f\n1:\n\tblr\n2:\n); + else + asm_fprintf (file, \tbcl 20,31,1f\n1:\n); Wouldn't it be better to set up an out-of-line blr insn that could be shared by all instances? That would solve a lot of this sort of this sort of branch-to-branch-to-branch ugliness. See the i386 port for an example of this, if you need it. ...after returning from a short vacation... Ok, here's a patch to implement that, and it passes bootstrap and regtesting. Richard, is this what you had in mind? I'll note that I disabled rs6000_code_end for TARGET_POWERPC64, since I was running into linker errors when building libgcc. The merging of the thunk routines with comdat worked fine, but the thunk function also has a function descriptor and I couldn't figure out a way to get those merged properly (if it's even possible), so they led to multiply defined symbol linker errors. Peter * config.gcc (powerpc*-*-linux*): Add powerpc*-*-linux*ppc476* variant. * config/rs6000/476.h: New file. * config/rs6000/476.opt: Likewise. * config/rs6000/rs6000.h (TARGET_LINK_STACK): New define. (SET_TARGET_LINK_STACK): Likewise. (TARGET_ASM_CODE_END): Define. * config/rs6000/rs6000.c (rs6000_option_override_internal): Enable TARGET_LINK_STACK for -mtune=476 and -mtune=476fp. (rs6000_legitimize_tls_address): Emit the link stack preserving GOT code if TARGET_LINK_STACK. (rs6000_emit_load_toc_table): Likewise. (output_function_profiler): Likewise (macho_branch_islands): Likewise (machopic_output_stub): Likewise (get_ppc476_thunk_name): New function. (rs6000_code_end): Likewise. * config/rs6000/rs6000.md (load_toc_v4_PIC_1, load_toc_v4_PIC_1b): Convert to a define_expand. (load_toc_v4_PIC_1_normal): New define_insn. (load_toc_v4_PIC_1_476): Likewise. (load_toc_v4_PIC_1b_normal): Likewise. (load_toc_v4_PIC_1b_476): Likewise. Index: gcc/config.gcc === --- gcc/config.gcc (revision 179091) +++ gcc/config.gcc (working copy) @@ -2133,6 +2133,9 @@ powerpc-*-linux* | powerpc64-*-linux*) esac tmake_file=${tmake_file} t-slibgcc-libgcc case ${target} in + powerpc*-*-linux*ppc476*) + tm_file=${tm_file} rs6000/476.h + extra_options=${extra_options} rs6000/476.opt ;; powerpc*-*-linux*altivec*) tm_file=${tm_file} rs6000/linuxaltivec.h ;; powerpc*-*-linux*spe*) Index: gcc/config/rs6000/476.h === --- gcc/config/rs6000/476.h (revision 0) +++ gcc/config/rs6000/476.h (revision 0) @@ -0,0 +1,32 @@ +/* Enable IBM PowerPC 476 support. + Copyright (C) 2011 Free Software Foundation, Inc. + Contributed by Peter Bergner (berg...@vnet.ibm.com) + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GCC is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + http://www.gnu.org/licenses/. */ + +#undef TARGET_LINK_STACK +#define TARGET_LINK_STACK (rs6000_link_stack) + +#undef SET_TARGET_LINK_STACK +#define SET_TARGET_LINK_STACK(X) do { TARGET_LINK_STACK = (X); } while (0) + +#undef TARGET_ASM_CODE_END +#define TARGET_ASM_CODE_END rs6000_code_end Index: gcc/config/rs6000/rs6000-protos.h === --- gcc/config/rs6000/rs6000-protos.h (revision 179091) +++ gcc/config/rs6000/rs6000-protos.h (working copy) @@ -173,6 +173,7 @@ extern void rs6000_emit_eh_reg_restore ( extern const char * output_isel (rtx *); extern void rs6000_call_indirect_aix (rtx, rtx, rtx); extern void rs6000_aix_asm_output_dwarf_table_ref (char *); +extern void get_ppc476_thunk_name (char name[32]); /* Declare functions in rs6000-c.c */ Index: gcc/config/rs6000/476.opt
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Thu, 2011-10-27 at 20:43 -0500, Peter Bergner wrote: Index: gcc/config/rs6000/476.opt [snip] +Target Var(rs6000_link_stack) Init(1) Save Oops, this should actually be Init(-1). The hunk above was just my way of testing the modified code more by enabling it by default. Sorry about that. Peter
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Mon, 2011-09-12 at 15:29 -0400, David Edelsohn wrote: First, please choose a more informative option name. -mpreserve-link-stack seems like something generally useful for all processors and someone may randomly add the option. It always is useful to preserve the link stack -- that's why you're jumping through hoops to fix this bug. Maybe -mpreserve-ppc476-link-stack . Done. I would prefer that this patch were maintained by the chip vendors distributing SDKs for PPC476 instead of complicating the FSF codebase. Talking with the chip folks, they said there were a number of companies already downloading the FSF gcc sources and building it unpatched and that they expected more to do so in the future, so I'm not sure how many (if any) are actually even relying on a SDK. So... Otherwise, please implement this like Xilinx FPU in rs6000.opt, rs6000.h, ppc476.h and config.gcc where TARGET_LINK_STACK is defined as 0 unless GCC explicitly is configured for powerpc476. Here's a patch to do that, by adding a variant to the powerpc*-*-linux* target for the 476. I bootstrapped and regtested this as before, meaning I also tested this with the -mpreserve-ppc476-link-stack on by default, as well as configuring without 476 support and verified that the TARGET_LINK_STACK tests are not only optimized away, but so is the -mpreserve-ppc476-link-stack option itself. Is this ok for mainline now? Peter * config.gcc (powerpc*-*-linux*): Add powerpc*-*-linux*ppc476* variant. * config/rs6000/476.h: New file. * config/rs6000/476.opt: Likewise. * config/rs6000/rs6000.h (TARGET_LINK_STACK): New define. (SET_TARGET_LINK_STACK): Likewise. * config/rs6000/rs6000.c (rs6000_option_override_internal): Enable TARGET_LINK_STACK for -mtune=476 and -mtune=476fp. (rs6000_legitimize_tls_address): Emit the link stack preserving GOT code if TARGET_LINK_STACK. (rs6000_emit_load_toc_table): Likewise. (output_function_profiler): Likewise (macho_branch_islands): Likewise (machopic_output_stub): Likewise * config/rs6000/rs6000.md (load_toc_v4_PIC_1, load_toc_v4_PIC_1b): Convert to a define_expand. (load_toc_v4_PIC_1_normal): New define_insn. (load_toc_v4_PIC_1_476): Likewise. (load_toc_v4_PIC_1b_normal): Likewise. (load_toc_v4_PIC_1b_476): Likewise. Index: gcc/config.gcc === --- gcc/config.gcc (revision 179091) +++ gcc/config.gcc (working copy) @@ -2133,6 +2133,9 @@ powerpc-*-linux* | powerpc64-*-linux*) esac tmake_file=${tmake_file} t-slibgcc-libgcc case ${target} in + powerpc*-*-linux*ppc476*) + tm_file=${tm_file} rs6000/476.h + extra_options=${extra_options} rs6000/476.opt ;; powerpc*-*-linux*altivec*) tm_file=${tm_file} rs6000/linuxaltivec.h ;; powerpc*-*-linux*spe*) Index: gcc/config/rs6000/476.h === --- gcc/config/rs6000/476.h (revision 0) +++ gcc/config/rs6000/476.h (revision 0) @@ -0,0 +1,29 @@ +/* Enable IBM PowerPC 476 support. + Copyright (C) 2011 Free Software Foundation, Inc. + Contributed by Peter Bergner (berg...@vnet.ibm.com) + This file is part of GCC. + + GCC is free software; you can redistribute it and/or modify it + under the terms of the GNU General Public License as published + by the Free Software Foundation; either version 3, or (at your + option) any later version. + + GCC is distributed in the hope that it will be useful, but WITHOUT + ANY WARRANTY; without even the implied warranty of MERCHANTABILITY + or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public + License for more details. + + Under Section 7 of GPL version 3, you are granted additional + permissions described in the GCC Runtime Library Exception, version + 3.1, as published by the Free Software Foundation. + + You should have received a copy of the GNU General Public License and + a copy of the GCC Runtime Library Exception along with this program; + see the files COPYING3 and COPYING.RUNTIME respectively. If not, see + http://www.gnu.org/licenses/. */ + +#undef TARGET_LINK_STACK +#define TARGET_LINK_STACK (rs6000_link_stack) + +#undef SET_TARGET_LINK_STACK +#define SET_TARGET_LINK_STACK(X) do { TARGET_LINK_STACK = (X); } while (0) Index: gcc/config/rs6000/476.opt === --- gcc/config/rs6000/476.opt (revision 0) +++ gcc/config/rs6000/476.opt (revision 0) @@ -0,0 +1,24 @@ +; IBM PowerPC 476 options. +; +; Copyright (C) 2011 Free Software Foundation, Inc. +; Contributed by Peter Bergner (berg...@vnet.ibm.com) +; +; This file is part of GCC. +; +; GCC is free software; you can redistribute it and/or modify it under +; the terms of the
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On 10/13/2011 08:49 AM, Peter Bergner wrote: + if (TARGET_LINK_STACK) + asm_fprintf (file, \tbl 1f\n\tb 2f\n1:\n\tblr\n2:\n); + else + asm_fprintf (file, \tbcl 20,31,1f\n1:\n); Wouldn't it be better to set up an out-of-line blr insn that could be shared by all instances? That would solve a lot of this sort of this sort of branch-to-branch-to-branch ugliness. See the i386 port for an example of this, if you need it. r~
Re: [PATCH, rs6000] Preserve link stack for 476 cpus
On Mon, Sep 12, 2011 at 12:07 PM, Peter Bergner berg...@vnet.ibm.com wrote: The Power ISA declares the bcl 20,31,... instruction as the preferred idiom for obtaining the next instruction address (NIA), which we use for computing the address of the GOT. This special branch and link is *not* a subroutine call, meaning it won't be paired with a blr (subroutine return). Processors therefore are not supposed to update their internal link stack when executing one of this instructions, otherwise we'll mispredict the following blrs. The 476 processor has an bug where it doesn't ignore these bcl 20,31,... instructions, so we end up getting lots of mispredicts for -fPIC code. The following patch adds a -mpreserve-link-stack option that is enabled automatically for -mtune={476,476fp}, that changes the two types of GOT access code GCC produces. The new code replaces the bcl 20,31,... with a bl..., b..., blr triplet. I've included some old versus new code snipits for both types of GOT access code to illustrate how the code has changed. 1) Normal Code: New 476 Code: == bcl 20,31,$+4 bl $+8 .L3: .L3: b $+8 blr mflr 9 mflr 9 addis 9,9,.LCTOC1-.L3@ha addis 9,9,.LCTOC1-.L3@ha addi 9,9,.LCTOC1-.L3@l addi 9,9,.LCTOC1-.L3@l 2) Normal Code: New 476 Code: == bcl 20,31,$+8 bl $+12 .long _GLOBAL_OFFSET_TABLE_-$ b $+12 .long _GLOBAL_OFFSET_TABLE_-$ blr mflr 9 mflr 9 addi 9,9,4 lwz 3,0(9) lwz 3,0(9) I have bootstrapped and regtested the following patch with no regressiosn. To test the code even more, I modified the patch so that we default to always using -mpreserve-link-stack and that bootstrapped and regtested with no regressions too. Ok for mainline? Peter * config/rs6000/rs6000.opt (mpreserve-link-stack): New option. * config/rs6000/rs6000.c (rs6000_option_override_internal): Enable TARGET_LINK_STACK for -mtune=476 and -mtune=476fp. (rs6000_legitimize_tls_address): Emit the link stack preserving GOT code if TARGET_LINK_STACK. (rs6000_emit_load_toc_table): Likewise. (output_function_profiler): Likewise (macho_branch_islands): Likewise (machopic_output_stub): Likewise * config/rs6000/rs6000.md (load_toc_v4_PIC_1, load_toc_v4_PIC_1b): Convert to a define_expand. (load_toc_v4_PIC_1_normal): New define_insn. (load_toc_v4_PIC_1_476): Likewise. (load_toc_v4_PIC_1b_normal): Likewise. (load_toc_v4_PIC_1b_476): Likewise. First, please choose a more informative option name. -mpreserve-link-stack seems like something generally useful for all processors and someone may randomly add the option. It always is useful to preserve the link stack -- that's why you're jumping through hoops to fix this bug. Maybe -mpreserve-ppc476-link-stack . I would prefer that this patch were maintained by the chip vendors distributing SDKs for PPC476 instead of complicating the FSF codebase. Otherwise, please implement this like Xilinx FPU in rs6000.opt, rs6000.h, ppc476.h and config.gcc where TARGET_LINK_STACK is defined as 0 unless GCC explicitly is configured for powerpc476. Thanks, David