Bug 52999 - [4.7/4.8 Regression] ICE, segmentation fault in c_tree_printer
[4.7/4.8 Regression] ICE, segmentation fault in c_tree_printer
Status: RESOLVED FIXED
Product: gcc
Classification: Unclassified
Component: target
4.8.0
: P3 normal
: 4.7.1
Assigned To: Not yet assigned to anyone
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-04-15 22:15 UTC by John David Anglin
Modified: 2012-06-03 12:41 UTC (History)
2 users (show)

See Also:
Host: hppa-unknown-linux-gnu
Target: hppa-unknown-linux-gnu
Build: hppa-unknown-linux-gnu
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Compressed rtld.i file (53.42 KB, application/x-bzip2)
2012-04-15 22:15 UTC, John David Anglin
Details
gcc48-pr52999.patch (1.08 KB, patch)
2012-04-23 09:58 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John David Anglin 2012-04-15 22:15:04 UTC
Created attachment 27162 [details]
Compressed rtld.i file

(gdb) r
Starting program: /home/dave/gnu/gcc/objdir/gcc/cc1 -fpreprocessed rtld.i -quiet -dumpbase rtld.i -auxbase rtld -O2 -Wall -Winline -Wwrite-strings -Wstrict-prototypes -std=gnu99 -version -fgnu89-inline -fmerge-all-constants -fno-stack-protector -fPIC -o xx.s
GNU C (GCC) version 4.8.0 20120412 (experimental) [trunk revision 186378] (hppa-linux-gnu)
	compiled by GNU C version 4.8.0 20120412 (experimental) [trunk revision 186378], GMP version 5.0.4, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
GNU C (GCC) version 4.8.0 20120412 (experimental) [trunk revision 186378] (hppa-linux-gnu)
	compiled by GNU C version 4.8.0 20120412 (experimental) [trunk revision 186378], GMP version 5.0.4, MPFR version 3.1.0-p3, MPC version 0.9
GGC heuristics: --param ggc-min-expand=30 --param ggc-min-heapsize=4096
Compiler executable checksum: d431a91d532955514383649751f02954
rtld.c: In function ‘dl_main’:
rtld.c:937:3: warning: implicit declaration of function ‘__canonicalize_funcptr_for_compare’ [-Wimplicit-function-declaration]

Program received signal SIGSEGV, Segmentation fault.
c_tree_printer (hash=false, set_locus=false, spec=0xa919b0 "D", 
    text=0xfdf02608, pp=0xab7228, precision=<optimized out>, 
    wide=<optimized out>) at ../../gcc/gcc/c-objc-common.c:116
116	      if (DECL_DEBUG_EXPR_IS_FROM (t) && DECL_DEBUG_EXPR (t))
(gdb) bt
#0  c_tree_printer (hash=false, set_locus=false, spec=0xa919b0 "D", 
    text=0xfdf02608, pp=0xab7228, precision=<optimized out>, 
    wide=<optimized out>) at ../../gcc/gcc/c-objc-common.c:116
#1  c_tree_printer (pp=0xab7228, text=0xfdf02608, spec=0xa919b0 "D", 
    precision=0, wide=false, set_locus=false, hash=false)
    at ../../gcc/gcc/c-objc-common.c:89
#2  0x0089b42c in pp_base_format (pp=0xab7228, text=0xfdf02608)
    at ../../gcc/gcc/pretty-print.c:509
#3  0x00899730 in diagnostic_report_diagnostic (context=0xa917b4, 
    diagnostic=0xfdf02708) at ../../gcc/gcc/diagnostic.c:644
#4  0x00899ba0 in error (gmsgid=<optimized out>)
    at ../../gcc/gcc/diagnostic.c:857
#5  0x0075b994 in get_section (name=0xa919b0 "D", flags=<optimized out>, 
    decl=<optimized out>) at ../../gcc/gcc/varasm.c:318
#6  0x0076fbf4 in varpool_assemble_pending_decls ()
    at ../../gcc/gcc/varpool.c:653
#7  varpool_assemble_pending_decls () at ../../gcc/gcc/varpool.c:638
#8  0x001e6464 in cgraph_optimize () at ../../gcc/gcc/cgraphunit.c:2637
#9  0x001e6b20 in cgraph_finalize_compilation_unit ()
    at ../../gcc/gcc/cgraphunit.c:2720
#10 0x000be150 in c_write_global_declarations ()
    at ../../gcc/gcc/c-decl.c:10053
#11 0x0050fdec in compile_file () at ../../gcc/gcc/toplev.c:572
(gdb) p t
$1 = (tree) 0x0

4.6 successfully generates section conflict error message.
Comment 1 Jakub Jelinek 2012-04-23 09:58:38 UTC
Created attachment 27219 [details]
gcc48-pr52999.patch

This patch avoids the ICE when diagnosing the section conflict, but not sure what to do to actually compile the testcase without errors.  What ld.so does is not exactly kosher from GCC POV (it wants to put non-constant, writable variables into a section that GCC assumes is for constant variables that need relocations).
Comment 2 dave.anglin 2012-04-23 13:47:31 UTC
On 4/23/2012 5:58 AM, jakub at gcc dot gnu.org wrote:
> http://gcc.gnu.org/bugzilla/show_bug.cgi?id=52999
>
> --- Comment #1 from Jakub Jelinek<jakub at gcc dot gnu.org>  2012-04-23 09:58:38 UTC ---
> Created attachment 27219 [details]
>    -->  http://gcc.gnu.org/bugzilla/attachment.cgi?id=27219
> gcc48-pr52999.patch
>
> This patch avoids the ICE when diagnosing the section conflict, but not sure
> what to do to actually compile the testcase without errors.  What ld.so does is
> not exactly kosher from GCC POV (it wants to put non-constant, writable
> variables into a section that GCC assumes is for constant variables that need
> relocations).
I asked a glibc maintainer whether it would be possible to work around 
the issue.

I know from debugging  that there is at least one varable in the code 
that's placed in .data.rel.ro
and assigned to.  So, the const qualifier can't be used for it.  As 
things stand, glibc doesn't build
with GCC 4.6 and later.

One fix might be to provide an option to set the SECTION_OVERRIDE flag.  
Another might
be to issue a warning rather than an error on section conflicts.

Dave
Comment 3 Jakub Jelinek 2012-04-23 13:56:44 UTC
Or for PA define __attribute_relro__ to nothing, or assume that users putting decls into .data.rel.ro or .data.rel.ro.local sections know what they are doing and just force SECTION_WRITE | SECTION_RELRO always for those.
Comment 4 dave.anglin 2012-04-23 14:50:18 UTC
On 4/23/2012 9:56 AM, jakub at gcc dot gnu.org wrote:
> Or for PA define __attribute_relro__ to nothing, or assume that users putting
> decls into .data.rel.ro or .data.rel.ro.local sections know what they are doing
> and just force SECTION_WRITE | SECTION_RELRO always for those.
hppa-linux uses the default section flags.  Is there a reason why this 
is PA specific?  I sense
there must be as this would have come up before.  It's -fPIC that 
triggers the error.
Comment 5 Jakub Jelinek 2012-04-23 16:16:54 UTC
The PA specific thing there is that PA puts rtx constant pool into .data.rel.ro section, something that doesn't happen on i?86/x86_64/ppc/ppc64 etc. to my knowledge.  Which is why there is no section->named.decl (thus the diagnostics ICE), as well as that in the absence of user variables without section attribute that should go into .data.rel.ro (like const int *foo = &bar; where bar isn't hidden) the compiler puts anything into .data.rel.ro section.  rtld.c carefully doesn't have such variables, and uses .data.rel.ro section attribute on variables that are writable and written before relocation processing, but never after.
Comment 6 dave.anglin 2012-04-23 17:04:13 UTC
On 4/23/2012 12:16 PM, jakub at gcc dot gnu.org wrote:
> The PA specific thing there is that PA puts rtx constant pool into .data.rel.ro
> section, something that doesn't happen on i?86/x86_64/ppc/ppc64 etc. to my
> knowledge.
This occurs in default_elf_select_section.  For example,

      case SECCAT_DATA_REL:
       sname = ".data.rel";
       break;
     case SECCAT_DATA_REL_LOCAL:
       sname = ".data.rel.local";
       break;
     case SECCAT_DATA_REL_RO:
       sname = ".data.rel.ro";

The category comes from here:

       else if (! TREE_READONLY (decl)
                || TREE_SIDE_EFFECTS (decl)
                || ! TREE_CONSTANT (DECL_INITIAL (decl)))
         {
           /* Here the reloc_rw_mask is not testing whether the section 
should
              be read-only or not, but whether the dynamic link will have to
              do something.  If so, we wish to segregate the data in 
order to
              minimize cache misses inside the dynamic linker.  */
           if (reloc & targetm.asm_out.reloc_rw_mask ())
             ret = reloc == 1 ? SECCAT_DATA_REL_LOCAL : SECCAT_DATA_REL;
           else
             ret = SECCAT_DATA;
         }

With PIC code, we get SECCAT_DATA_REL for the variable that caused
the diagnostic ICE.  It lacked a "const" qualifier.
Comment 7 Jakub Jelinek 2012-04-24 06:03:47 UTC
Author: jakub
Date: Tue Apr 24 06:03:43 2012
New Revision: 186741

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186741
Log:
	PR middle-end/52999
	* varasm.c (get_section): Don't ICE for section conflicts with
	built-in section kinds.

Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/varasm.c
Comment 8 Jakub Jelinek 2012-04-24 06:09:00 UTC
Author: jakub
Date: Tue Apr 24 06:08:55 2012
New Revision: 186743

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186743
Log:
	PR middle-end/52999
	* varasm.c (get_section): Don't ICE for section conflicts with
	built-in section kinds.

Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/varasm.c
Comment 9 Jakub Jelinek 2012-04-24 09:35:53 UTC
(In reply to comment #6)
> This occurs in default_elf_select_section.  For example,
You are looking at wrong spot.

What happens on this testcase is 
default_elf_select_rtx_section and the PA specific part of that is just that PA needs any constants that need relocations pushed into the constant pool, other targets don't.
Comment 10 dave.anglin 2012-04-24 18:18:07 UTC
On 4/24/2012 5:35 AM, jakub at gcc dot gnu.org wrote:
> What happens on this testcase is
> default_elf_select_rtx_section and the PA specific part of that is just that PA
> needs any constants that need relocations pushed into the constant pool, other
> targets don't.
So, it's probably the procedure labels which cause the problem.
Comment 11 John David Anglin 2012-04-27 20:41:22 UTC
Author: danglin
Date: Fri Apr 27 20:41:16 2012
New Revision: 186919

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186919
Log:
	PR target/52999
	* config/pa/pa.c (pa_legitimate_constant_p): Don't put function labels
	in constant pool.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/pa/pa.c
Comment 12 John David Anglin 2012-05-06 20:50:13 UTC
Author: danglin
Date: Sun May  6 20:50:06 2012
New Revision: 187216

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187216
Log:
	Backport from mainline:
	2012-04-27  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>

	PR target/52999
	* config/pa/pa.c (pa_legitimate_constant_p): Don't put function labels
	in constant pool.


Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/config/pa/pa.c
Comment 13 John David Anglin 2012-05-06 20:59:14 UTC
Author: danglin
Date: Sun May  6 20:59:10 2012
New Revision: 187217

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=187217
Log:
	PR target/52999
	* config/pa/pa.h (LEGITIMATE_CONSTANT_P): Don't put function labels
	in constant pool.


Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/config/pa/pa.h
Comment 14 John David Anglin 2012-05-06 21:00:41 UTC
Fixed.
Comment 15 John David Anglin 2012-05-30 22:54:24 UTC
Author: danglin
Date: Wed May 30 22:54:20 2012
New Revision: 188031

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=188031
Log:
2012-05-30  John David Anglin  <dave.anglin@nrc-cnrc.gc.ca>

	PR target/52999
	* config/pa/pa.c (TARGET_SECTION_TYPE_FLAGS): Define.
	(pa_section_type_flags): New.
	(pa_legitimate_constant_p): Revert previous change.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/pa/pa.c
Comment 16 John David Anglin 2012-05-30 23:04:04 UTC
Author: danglin
Date: Wed May 30 23:03:59 2012
New Revision: 188032

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=188032
Log:
	PR target/52999
	* config/pa/pa.c (TARGET_SECTION_TYPE_FLAGS): Define.
	(pa_section_type_flags): New.
	(pa_legitimate_constant_p): Revert previous change.


Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/config/pa/pa.c
Comment 17 John David Anglin 2012-06-03 12:41:07 UTC
Author: danglin
Date: Sun Jun  3 12:41:02 2012
New Revision: 188150

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=188150
Log:
	PR target/52999
	* config/pa/pa.c (TARGET_SECTION_TYPE_FLAGS): Define.
	(pa_section_type_flags): New.
	* config/pa/pa.h (LEGITIMATE_CONSTANT_P): Revert previous change.


Modified:
    branches/gcc-4_6-branch/gcc/ChangeLog
    branches/gcc-4_6-branch/gcc/config/pa/pa.c
    branches/gcc-4_6-branch/gcc/config/pa/pa.h