public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Re: i370 port - music/sp - possible generic gcc problem
@ 2009-11-29 14:31 Paul Edwards
  0 siblings, 0 replies; 7+ messages in thread
From: Paul Edwards @ 2009-11-29 14:31 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc

Latest information - 

> Ok, based on this, I traced it back further:
> 
> rtx
> gen_rtx_fmt_e0 (code, mode, arg0)
>     RTX_CODE code;
>     enum machine_mode mode;
>     rtx arg0;
> {
>  rtx rt;
>  rt = ggc_alloc_rtx (2);
>  memset (rt, 0, sizeof (struct rtx_def) - sizeof (rtunion));

The request for 2 (I guess, rtx's) results in a malloc for 65536
bytes, so presumably each rtx is 32k.  It appears that only the 
single byte at offset 47072 needs to be initialized to some
appropriate value (I found that x'08' and x'81' also work, and
I am still experimenting on that) in order to circumvent the 
problem of garbage code generation.

> rtx
> gen_rtx_MEM (mode, addr)
>     enum machine_mode mode;
>     rtx addr;
> {
>  rtx rt = gen_rtx_raw_MEM (mode, addr);
> 
>  /* This field is not cleared by the mere allocation of the rtx, so
>     we clear it here.  */
>  MEM_ATTRS (rt) = 0;
> 
>  return rt;
> }

I wonder if another field like the above also needs to be
initialized?  Or maybe the same field, but it needs to be
for the second rtx?

I will try to see if I can map that offset onto a meaningful variable.

BFN.  Paul.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: i370 port - music/sp - possible generic gcc problem
@ 2009-11-29  7:57 Paul Edwards
  0 siblings, 0 replies; 7+ messages in thread
From: Paul Edwards @ 2009-11-29  7:57 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc

> <stdin>: In function `acos':
> <stdin>:137: Internal compiler error in ?, at <stdin>:724
> Please submit a full bug report,
> with preprocessed source if appropriate.
> See <URL:http://gcc.gnu.org/bugs.html> for instructions.
> 
> I might be able to trace it from a different approach, getting more
> information about that internal error, now that I know where some
> of the involved memory is.  I'll get that <stdin> converted into a
> PC filename first.

6 hours of compilation later, I was unsuccessful in getting the proper
filename displayed.  As far as I can tell, it's aborting but not displaying
any output.  ie randomly displaying the above message.

However, not to worry, since there's only one line 724 with an
abort() in it, and it's this bit of code:

static int
insert_save (chain, before_p, regno, to_save, save_mode)
     struct insn_chain *chain;
     int before_p;
     int regno;
     HARD_REG_SET *to_save;
     enum machine_mode *save_mode;
{
  int i;
  unsigned int k;
  rtx pat = NULL_RTX;
  int code;
  unsigned int numregs = 0;
  struct insn_chain *new;
  rtx mem;

  /* A common failure mode if register status is not correct in the RTL
     is for this routine to be called with a REGNO we didn't expect to
     save.  That will cause us to write an insn with a (nil) SET_DEST
     or SET_SRC.  Instead of doing so and causing a crash later, check
     for this common case and abort here instead.  This will remove one
     step in debugging such problems.  */

  if (regno_save_mem[regno][1] == 0)
    abort ();


which is in the same file as the init_caller_save() function that
allocated the memory in the first place.

One fortunate thing is that this source file is under 1000 lines
long so hopefully amenable to debugging.

BFN.  Paul.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: i370 port - music/sp - possible generic gcc problem
  2009-11-28 17:03       ` Richard Guenther
@ 2009-11-28 23:44         ` Paul Edwards
  0 siblings, 0 replies; 7+ messages in thread
From: Paul Edwards @ 2009-11-28 23:44 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc

>> If GC does that, then how come there is all this effort to do
>> mmap testing to see if it has the facility to zero memory, and

> I can't see what you are refering to.

I obviously misinterpreted that then.

>> why is the surrounding code (in GCC 4.4's alloc_page())
>> calling XCNEWVEC instead of XNEWVEC?

> That's the page table entries, not the data itself.

> There wouldn't be the need for ggc_alloc_cleared if ggc_alloc
> would already zero pages.

Ok, based on this, I traced it back further:

rtx
gen_rtx_fmt_e0 (code, mode, arg0)
     RTX_CODE code;
     enum machine_mode mode;
     rtx arg0;
{
  rtx rt;
  rt = ggc_alloc_rtx (2);
  memset (rt, 0, sizeof (struct rtx_def) - sizeof (rtunion));



rtx
gen_rtx_MEM (mode, addr)
     enum machine_mode mode;
     rtx addr;
{
  rtx rt = gen_rtx_raw_MEM (mode, addr);

  /* This field is not cleared by the mere allocation of the rtx, so
     we clear it here.  */
  MEM_ATTRS (rt) = 0;

  return rt;
}



void
init_caller_save ()
{
...
  for (i = 0; i < FIRST_PSEUDO_REGISTER; i++)
    for (mode = 0 ; mode < MAX_MACHINE_MODE; mode++)
      if (HARD_REGNO_MODE_OK (i, mode))
        {
      rtx mem = gen_rtx_MEM (mode, address);


And indeed, this code - caller_save, shows up as one of the symptoms.
One of the symptoms is that where it is meant to be saving a register
prior to a function call, it instead generates a completely stupid
instruction - and that stupid instruction happens to be the first
instruction listed in i370.md.

Right at the moment the symptom is:

/ID SAVE-JOB-123456 @BLD000 9999 9999 9999 9999
/SYS REGION=9999,XREGION=64M
/FILE SYSPRINT PRT OSRECFM(F) OSLRECL(256)
/FILE SYSIN N(MATH.C) SHR
/FILE O N(MATH.S) NEW RECFM(V) SP(1000)
/FILE SYSINCL PDS(*.H)
/FILE INCLUDE PDS(*.H)
/PARM -Os -S -DUSE_MEMMGR -DMUSIC -o dd:o -
/LOAD XMON
<stdin>: In function `acos':
<stdin>:137: Internal compiler error in ?, at <stdin>:724
Please submit a full bug report,
with preprocessed source if appropriate.
See <URL:http://gcc.gnu.org/bugs.html> for instructions.

compiling something from my C runtime library.  But I basically get
different behaviour depending on what I initialize uninitialized memory
to.

Any ideas on what to look for now?  I can probably isolate which bit
of the malloc()ed memory is being referenced before initialization.
But finding out who is doing the reference could be tricky.

I might be able to trace it from a different approach, getting more
information about that internal error, now that I know where some
of the involved memory is.  I'll get that <stdin> converted into a
PC filename first.

BFN.  Paul.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: i370 port - music/sp - possible generic gcc problem
  2009-11-28 16:35     ` Paul Edwards
@ 2009-11-28 17:03       ` Richard Guenther
  2009-11-28 23:44         ` Paul Edwards
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Guenther @ 2009-11-28 17:03 UTC (permalink / raw)
  To: Paul Edwards; +Cc: gcc

On Sat, Nov 28, 2009 at 5:35 PM, Paul Edwards <mutazilah@gmail.com> wrote:
>>> Anyway, I tracked down the particular malloc() which gave changed
>>> behaviour depending on whether the malloc() did a memory initialization
>>> to NULs or not.
>
>> Well, GC hands out non-zeroed memory - the callers are responsible
>> for initializing it.  So the fix below is not a fix but papering over an
>> issue elswhere.
>
> Hi Richard.
>
> If GC does that, then how come there is all this effort to do
> mmap testing to see if it has the facility to zero memory, and

I can't see what you are refering to.

> why is the surrounding code (in GCC 4.4's alloc_page())
> calling XCNEWVEC instead of XNEWVEC?

That's the page table entries, not the data itself.

There wouldn't be the need for ggc_alloc_cleared if ggc_alloc
would already zero pages.

Richard.

> Thanks.  Paul.
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: i370 port - music/sp - possible generic gcc problem
  2009-11-28 16:03   ` Richard Guenther
@ 2009-11-28 16:35     ` Paul Edwards
  2009-11-28 17:03       ` Richard Guenther
  0 siblings, 1 reply; 7+ messages in thread
From: Paul Edwards @ 2009-11-28 16:35 UTC (permalink / raw)
  To: Richard Guenther; +Cc: gcc

>> Anyway, I tracked down the particular malloc() which gave changed
>> behaviour depending on whether the malloc() did a memory initialization
>> to NULs or not.

> Well, GC hands out non-zeroed memory - the callers are responsible
> for initializing it.  So the fix below is not a fix but papering over an
> issue elswhere.

Hi Richard.

If GC does that, then how come there is all this effort to do
mmap testing to see if it has the facility to zero memory, and
why is the surrounding code (in GCC 4.4's alloc_page())
calling XCNEWVEC instead of XNEWVEC?

Thanks.  Paul.

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: i370 port - music/sp - possible generic gcc problem
  2009-11-28 15:14 ` i370 port - music/sp - possible generic gcc problem Paul Edwards
@ 2009-11-28 16:03   ` Richard Guenther
  2009-11-28 16:35     ` Paul Edwards
  0 siblings, 1 reply; 7+ messages in thread
From: Richard Guenther @ 2009-11-28 16:03 UTC (permalink / raw)
  To: Paul Edwards; +Cc: gcc

On Sat, Nov 28, 2009 at 4:13 PM, Paul Edwards <mutazilah@gmail.com> wrote:
> I think I have found a bug in gcc, that still exists in gcc 4.4
>
> I found the problem on 3.2.3 though.
>
> While MVS and VM have basically been working fine, when I did
> the port to MUSIC/SP I started getting strange compilation failures.
>
> Initializing the stack to NULs made the problem go away, but I
> persisted, and instead initialized the stack to x'01' to try to get
> consistent failures.
>
> Even with that, and the malloced memory initialized to consistent
> garbage, I still didn't get the desired consistency in failures.
> But it was consistent enough that I could just run it 6 times and
> see if there were any failures.
>
>
> Anyway, I tracked down the particular malloc() which gave changed
> behaviour depending on whether the malloc() did a memory initialization
> to NULs or not.

Well, GC hands out non-zeroed memory - the callers are responsible
for initializing it.  So the fix below is not a fix but papering over an
issue elswhere.

Richard.

> It's this one (showing 3.2.3):
>
> C:\devel\gcc\gcc>cvs diff -l -c15
> cvs diff: Diffing .
> Index: ggc-page.c
> ===================================================================
> RCS file: c:\cvsroot/gcc/gcc/ggc-page.c,v
> retrieving revision 1.1.1.1
> diff -c -1 -5 -r1.1.1.1 ggc-page.c
> *** ggc-page.c  15 Feb 2006 10:22:25 -0000      1.1.1.1
> --- ggc-page.c  28 Nov 2009 14:13:41 -0000
> ***************
> *** 640,670 ****
>  #ifdef USING_MALLOC_PAGE_GROUPS
>   else
>     {
>       /* Allocate a large block of memory and serve out the aligned
>        pages therein.  This results in much less memory wastage
>        than the traditional implementation of valloc.  */
>
>       char *allocation, *a, *enda;
>       size_t alloc_size, head_slop, tail_slop;
>       int multiple_pages = (entry_size == G.pagesize);
>
>       if (multiple_pages)
>       alloc_size = GGC_QUIRE_SIZE * G.pagesize;
>       else
>       alloc_size = entry_size + G.pagesize - 1;
> !       allocation = xmalloc (alloc_size);
>
>       page = (char *) (((size_t) allocation + G.pagesize - 1) &
> -G.pagesize);
>       head_slop = page - allocation;
>       if (multiple_pages)
>       tail_slop = ((size_t) allocation + alloc_size) & (G.pagesize - 1);
>       else
>       tail_slop = alloc_size - entry_size - head_slop;
>       enda = allocation + alloc_size - tail_slop;
>
>       /* We allocated N pages, which are likely not aligned, leaving
>        us with N-1 usable pages.  We plan to place the page_group
>        structure somewhere in the slop.  */
>       if (head_slop >= sizeof (page_group))
>       group = (page_group *)page - 1;
>       else
> --- 640,670 ----
>  #ifdef USING_MALLOC_PAGE_GROUPS
>   else
>     {
>       /* Allocate a large block of memory and serve out the aligned
>        pages therein.  This results in much less memory wastage
>        than the traditional implementation of valloc.  */
>
>       char *allocation, *a, *enda;
>       size_t alloc_size, head_slop, tail_slop;
>       int multiple_pages = (entry_size == G.pagesize);
>
>       if (multiple_pages)
>       alloc_size = GGC_QUIRE_SIZE * G.pagesize;
>       else
>       alloc_size = entry_size + G.pagesize - 1;
> !       allocation = xcalloc (1, alloc_size);
>
>       page = (char *) (((size_t) allocation + G.pagesize - 1) &
> -G.pagesize);
>       head_slop = page - allocation;
>       if (multiple_pages)
>       tail_slop = ((size_t) allocation + alloc_size) & (G.pagesize - 1);
>       else
>       tail_slop = alloc_size - entry_size - head_slop;
>       enda = allocation + alloc_size - tail_slop;
>
>       /* We allocated N pages, which are likely not aligned, leaving
>        us with N-1 usable pages.  We plan to place the page_group
>        structure somewhere in the slop.  */
>       if (head_slop >= sizeof (page_group))
>       group = (page_group *)page - 1;
>       else
>
>
> I suspect that it has stayed hidden for so long because most people
> probably have this mmap_anon:
>
> /* Define if mmap can get us zeroed pages using MAP_ANON(YMOUS). */
> #undef HAVE_MMAP_ANON
>
>
> #ifdef HAVE_MMAP_ANON
> # undef HAVE_MMAP_DEV_ZERO
>
> # include <sys/mman.h>
> # ifndef MAP_FAILED
> #  define MAP_FAILED -1
> # endif
> # if !defined (MAP_ANONYMOUS) && defined (MAP_ANON)
> #  define MAP_ANONYMOUS MAP_ANON
> # endif
> # define USING_MMAP
>
> #endif
>
> #ifndef USING_MMAP
> #define USING_MALLOC_PAGE_GROUPS
> #endif
>
>
> Seems pretty clear that zeroed pages are required.
>
> Looking at the code above and below this block, it uses xcalloc
> instead.
>
> It will take a couple of days to confirm that this is the last
> presumed bug affecting the MUSIC/SP port.
>
> In the meantime, can someone confirm that this code is wrong,
> and that xcalloc is definitely required?
>
> I had a look at the gcc4 code, and it is calling XNEWVEC which
> is also using xmalloc instead of xcalloc, so I presume it is still
> a problem today, under the right circumstances.
>
> It took about a week to track this one down.  :-)
>
> One problem I have had for years, even on the MVS port, is that
> I need to use -Os to get the exact same register selection on the
> PC as the mainframe.  -O0 and -O2 get slightly different register
> allocations, although all versions of the code are correct.  If I'm
> lucky, this fix may make that problem go away, but as I said,
> it'll take a couple of days before the results are in, as each build
> takes about 2 hours (partly because i need to use -Os for
> consistency).
>
> Thanks.  Paul.
>
>

^ permalink raw reply	[flat|nested] 7+ messages in thread

* i370 port - music/sp - possible generic gcc problem
  2009-11-24 14:05 i370 port - 3.4.6 to 4.4 upgrade attempt Ulrich Weigand
@ 2009-11-28 15:14 ` Paul Edwards
  2009-11-28 16:03   ` Richard Guenther
  0 siblings, 1 reply; 7+ messages in thread
From: Paul Edwards @ 2009-11-28 15:14 UTC (permalink / raw)
  To: gcc

I think I have found a bug in gcc, that still exists in gcc 4.4

I found the problem on 3.2.3 though.

While MVS and VM have basically been working fine, when I did
the port to MUSIC/SP I started getting strange compilation failures.

Initializing the stack to NULs made the problem go away, but I
persisted, and instead initialized the stack to x'01' to try to get
consistent failures.

Even with that, and the malloced memory initialized to consistent
garbage, I still didn't get the desired consistency in failures.
But it was consistent enough that I could just run it 6 times and
see if there were any failures.


Anyway, I tracked down the particular malloc() which gave changed
behaviour depending on whether the malloc() did a memory initialization
to NULs or not.

It's this one (showing 3.2.3):

C:\devel\gcc\gcc>cvs diff -l -c15
cvs diff: Diffing .
Index: ggc-page.c
===================================================================
RCS file: c:\cvsroot/gcc/gcc/ggc-page.c,v
retrieving revision 1.1.1.1
diff -c -1 -5 -r1.1.1.1 ggc-page.c
*** ggc-page.c  15 Feb 2006 10:22:25 -0000      1.1.1.1
--- ggc-page.c  28 Nov 2009 14:13:41 -0000
***************
*** 640,670 ****
  #ifdef USING_MALLOC_PAGE_GROUPS
    else
      {
        /* Allocate a large block of memory and serve out the aligned
         pages therein.  This results in much less memory wastage
         than the traditional implementation of valloc.  */

        char *allocation, *a, *enda;
        size_t alloc_size, head_slop, tail_slop;
        int multiple_pages = (entry_size == G.pagesize);

        if (multiple_pages)
        alloc_size = GGC_QUIRE_SIZE * G.pagesize;
        else
        alloc_size = entry_size + G.pagesize - 1;
!       allocation = xmalloc (alloc_size);

        page = (char *) (((size_t) allocation + G.pagesize - 1) 
& -G.pagesize);
        head_slop = page - allocation;
        if (multiple_pages)
        tail_slop = ((size_t) allocation + alloc_size) & (G.pagesize - 1);
        else
        tail_slop = alloc_size - entry_size - head_slop;
        enda = allocation + alloc_size - tail_slop;

        /* We allocated N pages, which are likely not aligned, leaving
         us with N-1 usable pages.  We plan to place the page_group
         structure somewhere in the slop.  */
        if (head_slop >= sizeof (page_group))
        group = (page_group *)page - 1;
        else
--- 640,670 ----
  #ifdef USING_MALLOC_PAGE_GROUPS
    else
      {
        /* Allocate a large block of memory and serve out the aligned
         pages therein.  This results in much less memory wastage
         than the traditional implementation of valloc.  */

        char *allocation, *a, *enda;
        size_t alloc_size, head_slop, tail_slop;
        int multiple_pages = (entry_size == G.pagesize);

        if (multiple_pages)
        alloc_size = GGC_QUIRE_SIZE * G.pagesize;
        else
        alloc_size = entry_size + G.pagesize - 1;
!       allocation = xcalloc (1, alloc_size);

        page = (char *) (((size_t) allocation + G.pagesize - 1) 
& -G.pagesize);
        head_slop = page - allocation;
        if (multiple_pages)
        tail_slop = ((size_t) allocation + alloc_size) & (G.pagesize - 1);
        else
        tail_slop = alloc_size - entry_size - head_slop;
        enda = allocation + alloc_size - tail_slop;

        /* We allocated N pages, which are likely not aligned, leaving
         us with N-1 usable pages.  We plan to place the page_group
         structure somewhere in the slop.  */
        if (head_slop >= sizeof (page_group))
        group = (page_group *)page - 1;
        else


I suspect that it has stayed hidden for so long because most people
probably have this mmap_anon:

/* Define if mmap can get us zeroed pages using MAP_ANON(YMOUS). */
#undef HAVE_MMAP_ANON


#ifdef HAVE_MMAP_ANON
# undef HAVE_MMAP_DEV_ZERO

# include <sys/mman.h>
# ifndef MAP_FAILED
#  define MAP_FAILED -1
# endif
# if !defined (MAP_ANONYMOUS) && defined (MAP_ANON)
#  define MAP_ANONYMOUS MAP_ANON
# endif
# define USING_MMAP

#endif

#ifndef USING_MMAP
#define USING_MALLOC_PAGE_GROUPS
#endif


Seems pretty clear that zeroed pages are required.

Looking at the code above and below this block, it uses xcalloc
instead.

It will take a couple of days to confirm that this is the last
presumed bug affecting the MUSIC/SP port.

In the meantime, can someone confirm that this code is wrong,
and that xcalloc is definitely required?

I had a look at the gcc4 code, and it is calling XNEWVEC which
is also using xmalloc instead of xcalloc, so I presume it is still
a problem today, under the right circumstances.

It took about a week to track this one down.  :-)

One problem I have had for years, even on the MVS port, is that
I need to use -Os to get the exact same register selection on the
PC as the mainframe.  -O0 and -O2 get slightly different register
allocations, although all versions of the code are correct.  If I'm
lucky, this fix may make that problem go away, but as I said,
it'll take a couple of days before the results are in, as each build
takes about 2 hours (partly because i need to use -Os for
consistency).

Thanks.  Paul.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-11-29 14:18 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-11-29 14:31 i370 port - music/sp - possible generic gcc problem Paul Edwards
  -- strict thread matches above, loose matches on Subject: below --
2009-11-29  7:57 Paul Edwards
2009-11-24 14:05 i370 port - 3.4.6 to 4.4 upgrade attempt Ulrich Weigand
2009-11-28 15:14 ` i370 port - music/sp - possible generic gcc problem Paul Edwards
2009-11-28 16:03   ` Richard Guenther
2009-11-28 16:35     ` Paul Edwards
2009-11-28 17:03       ` Richard Guenther
2009-11-28 23:44         ` Paul Edwards

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).