void foo (void) { unsigned long x = 0; asm volatile ("" : : "r" (&x) : "memory"); } int main () { foo (); return 0; } fails to link on powerpc64le-linux with -fstack-protector-strong -mminimal-toc -O0: gcc -fstack-protector-strong -mminimal-toc -O0 -o /tmp/test{,.c} /tmp/ccldrAkU.o: In function `foo': test.c:(.text+0x20): undefined reference to `.LCTOC0' collect2: error: ld returned 1 exit status I can reproduce also with a cross-compiler, the important trigger is that TARGET_LIBC_PROVIDES_SSP must be defined to 1. This compiled fine with 4.8, fails with 6.2 and current trunk.
Created attachment 39798 [details] gcc7-pr77957.patch One of the problems is that for TARGET_THREAD_SSP_OFFSET targets we completely wastefully create a MEM we don't really need and then ignore it. This untested patch attempts to avoid that. The more important bug is somewhere in the rs6000 backend, that the useless MEMs at -O0 confuse the backend enough that it contains (useless) .LCTOC0 reference/load without corresponding definition of .LCTOC0. I'll leave this part to the rs6000 maintainers.
Author: jakub Date: Thu Oct 13 08:29:03 2016 New Revision: 241087 URL: https://gcc.gnu.org/viewcvs?rev=241087&root=gcc&view=rev Log: PR target/77957 * hooks.h (hook_tree_void_null): Declare. * hooks.c (hook_tree_void_null): New function. * langhooks.c (lhd_return_null_tree_v): Remove. * langhooks-def.h (lhd_return_null_tree_v): Remove. * cfgexpand.c (stack_protect_prologue): If guard_decl is NULL, set y to const0_rtx. * function.c (stack_protect_epilogue): Likewise. * config/tilepro/tilepro.c (TARGET_STACK_PROTECT_GUARD): Redefine if TARGET_THREAD_SSP_OFFSET is defined. * config/s390/s390.c (TARGET_STACK_PROTECT_GUARD): Likewise. * config/sparc/sparc.c (TARGET_STACK_PROTECT_GUARD): Likewise. * config/tilegx/tilegx.c (TARGET_STACK_PROTECT_GUARD): Likewise. * config/rs6000/rs6000.c (TARGET_STACK_PROTECT_GUARD): Likewise. * config/i386/i386.c (TARGET_STACK_PROTECT_GUARD): Likewise. (ix86_stack_protect_guard): New function. c/ * c-objc-common.h (LANG_HOOKS_GETDECLS): Use hook_tree_void_null instead of lhd_return_null_tree_v. ada/ * gcc-interface/misc.c (LANG_HOOKS_GETDECLS): Use hook_tree_void_null instead of lhd_return_null_tree_v. Modified: trunk/gcc/ChangeLog trunk/gcc/ada/ChangeLog trunk/gcc/ada/gcc-interface/misc.c trunk/gcc/c/ChangeLog trunk/gcc/c/c-objc-common.h trunk/gcc/cfgexpand.c trunk/gcc/config/i386/i386.c trunk/gcc/config/rs6000/rs6000.c trunk/gcc/config/s390/s390.c trunk/gcc/config/sparc/sparc.c trunk/gcc/config/tilegx/tilegx.c trunk/gcc/config/tilepro/tilepro.c trunk/gcc/function.c trunk/gcc/hooks.c trunk/gcc/hooks.h trunk/gcc/langhooks-def.h trunk/gcc/langhooks.c
This has been worked around on the trunk, but I haven't tracked status of the actual bugfix (making sure that if we don't optimize away the .LCTOC0 reference, we emit that symbol). Segher, do you remember if anything has been checked in or not?
It is on my "stage3" list.
Author: segher Date: Sat Nov 12 15:13:14 2016 New Revision: 242336 URL: https://gcc.gnu.org/viewcvs?rev=242336&root=gcc&view=rev Log: rs6000: Don't forget to initialize the TOC (PR77957) The code generating traceback tables mistakenly does an early return if !optional_tbtab, which causes it to miss the code generating the TOC section. This only matters if the TOC will be empty since otherwise the section is created elsewhere. This patch fixes it. PR target/77957 * config/rs6000/rs6000.c (rs6000_output_function_epilogue): Don't return early if !optional_tbtab. Modified: trunk/gcc/ChangeLog trunk/gcc/config/rs6000/rs6000.c
Fixed on trunk, 5 and 6 branches pending.
Author: segher Date: Wed Dec 7 23:07:58 2016 New Revision: 243415 URL: https://gcc.gnu.org/viewcvs?rev=243415&root=gcc&view=rev Log: rs6000: Don't forget to initialize the TOC (PR77957) The code generating traceback tables mistakenly does an early return if !optional_tbtab, which causes it to miss the code generating the TOC section. This only matters if the TOC will be empty since otherwise the section is created elsewhere. This patch fixes it. PR target/77957 * config/rs6000/rs6000.c (rs6000_output_function_epilogue): Don't return early if !optional_tbtab. Modified: branches/gcc-6-branch/gcc/ChangeLog branches/gcc-6-branch/gcc/config/rs6000/rs6000.c
Author: segher Date: Wed Dec 7 23:11:23 2016 New Revision: 243416 URL: https://gcc.gnu.org/viewcvs?rev=243416&root=gcc&view=rev Log: rs6000: Don't forget to initialize the TOC (PR77957) The code generating traceback tables mistakenly does an early return if !optional_tbtab, which causes it to miss the code generating the TOC section. This only matters if the TOC will be empty since otherwise the section is created elsewhere. This patch fixes it. PR target/77957 * config/rs6000/rs6000.c (rs6000_output_function_epilogue): Don't return early if !optional_tbtab. Modified: branches/gcc-5-branch/gcc/ChangeLog branches/gcc-5-branch/gcc/config/rs6000/rs6000.c
Fixed on all open branches.
.