Bug 77957 - [5/6 Regression] Undefined .LCTOC0 with -fstack-protector-strong -mminimal-toc -O0 on ppc64
Summary: [5/6 Regression] Undefined .LCTOC0 with -fstack-protector-strong -mminimal-to...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 6.0
: P2 normal
Target Milestone: 6.3
Assignee: Not yet assigned to anyone
URL:
Keywords: link-failure
Depends on:
Blocks:
 
Reported: 2016-10-12 16:19 UTC by Jakub Jelinek
Modified: 2016-12-07 23:13 UTC (History)
4 users (show)

See Also:
Host:
Target: powerpc64*-*-*
Build:
Known to work: 7.0
Known to fail: 5.0, 6.0
Last reconfirmed: 2016-10-12 00:00:00


Attachments
gcc7-pr77957.patch (2.51 KB, patch)
2016-10-12 16:33 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Jakub Jelinek 2016-10-12 16:19:47 UTC
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.
Comment 1 Jakub Jelinek 2016-10-12 16:33:48 UTC
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.
Comment 2 Jakub Jelinek 2016-10-13 08:29:35 UTC
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
Comment 3 Jakub Jelinek 2016-11-05 16:19:46 UTC
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?
Comment 4 Segher Boessenkool 2016-11-05 20:34:27 UTC
It is on my "stage3" list.
Comment 5 Segher Boessenkool 2016-11-12 15:13:46 UTC
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
Comment 6 Segher Boessenkool 2016-11-12 15:34:06 UTC
Fixed on trunk, 5 and 6 branches pending.
Comment 7 Segher Boessenkool 2016-12-07 23:08:30 UTC
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
Comment 8 Segher Boessenkool 2016-12-07 23:11:54 UTC
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
Comment 9 Segher Boessenkool 2016-12-07 23:12:41 UTC
Fixed on all open branches.
Comment 10 Segher Boessenkool 2016-12-07 23:13:19 UTC
.