public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "linkw at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug gcov-profile/97594] [11 Regression] new test case gcc.dg/tree-prof/pr97461.c execution failure
Date: Fri, 06 Nov 2020 06:10:23 +0000	[thread overview]
Message-ID: <bug-97594-4-tlFEzWma7S@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-97594-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97594

--- Comment #3 from Kewen Lin <linkw at gcc dot gnu.org> ---


(In reply to Martin Liška from comment #2)
> (In reply to Martin Liška from comment #1)
> > Mine, I see a strange error:
> > 
> > $ Program received signal SIGBUS, Bus error.
> > 0x00003fffb7ceddbc in __GI__IO_link_in () from /lib64/libc.so.6
> > Missing separate debuginfos, use: debuginfo-install
> > glibc-2.17-307.el7.1.ppc64le
> > (gdb) bt
> > #0  0x00003fffb7ceddbc in __GI__IO_link_in () from /lib64/libc.so.6
> > #1  0x00003fffb7cebe58 in _IO_new_file_init_internal () from /lib64/libc.so.6
> 
> All right, so the test-case overloads malloc and returns a memory that is a
> static buffer. For some reason, it leads to SEGBUS.
> Do Power people know what's causing that?

I was testing the patch for PR97705 and met this issue during regression
testing, happened to notice this PR and just realized this one is also a random
issue. (how lucky I am :-))

Checked the assembly insn causing the SEGBUS

   0x00007ffff7cc6940 <+240>:   beq     0x7ffff7cc6b30 <__GI__IO_link_in+736>
   0x00007ffff7cc6944 <+244>:   li      r9,1
   0x00007ffff7cc6948 <+248>:   clrldi  r10,r10,32
=> 0x00007ffff7cc694c <+252>:   lwarx   r8,0,r3
   0x00007ffff7cc6950 <+256>:   subf.   r8,r10,r8

r3             0x100207e6          268568550

As Power ISA pointed out, the EA for lwarx must be a multiple of 4. "If it is
not, either the system alignment error handler is invoked or the results are
boundedly undefined."

So the code of function __GI__IO_link_in has already assumed the address there
would have one reasonable alignment.

By checking the manual of malloc/calloc, it says:

   RETURN VALUE
     The malloc() and calloc() functions return a pointer to the 
     allocated memory, which is  suitably  aligned  for any built-in
     type.  On error, these functions return NULL.  NULL may also be
     returned by a successful call to malloc() with a size of zero,
     or by a successful call to calloc() with nmemb or size equal to
     zero.

I think the assumption there is reasonable, the addresses returned from
user-overloaded malloc/calloc should also take care of this alignment
requirement and adjust the return address respecting this.

The below small patch can get the case to pass.

$ diff ~/gcc/gcc-git/gcc/testsuite/gcc.dg/tree-prof/pr97461.c pr97461.c
20a21,26
> /* The malloc() and calloc() functions return a pointer to the allocated
>    memory, which is suitably aligned for any built-in type.  Use 16
>    bytes here as the basic alignment requirement for user-defined malloc
>    and calloc.  See PR97594 for the details.  */
> #define ROUND_UP_FOR_16B_ALIGNMENT(x) ((x + 15) & (-16))
>
23c29
<     memory_p += size;
---
>     memory_p += ROUND_UP_FOR_16B_ALIGNMENT (size);

  parent reply	other threads:[~2020-11-06  6:10 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-27 14:48 [Bug other/97594] New: " seurer at gcc dot gnu.org
2020-10-27 15:09 ` [Bug gcov-profile/97594] [11 Regression] " rguenth at gcc dot gnu.org
2020-10-27 15:11 ` marxin at gcc dot gnu.org
2020-10-27 15:43 ` marxin at gcc dot gnu.org
2020-11-06  6:10 ` linkw at gcc dot gnu.org [this message]
2020-11-06 13:18 ` marxin at gcc dot gnu.org
2020-11-06 13:49 ` marxin at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-97594-4-tlFEzWma7S@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).