public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/65958] New: -fstack-check breaks __builtin(alloca)
@ 2015-05-01  6:48 felix.janda at posteo dot de
  2015-05-01 12:40 ` [Bug c/65958] [arm] " felix.janda at posteo dot de
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: felix.janda at posteo dot de @ 2015-05-01  6:48 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 65958
           Summary: -fstack-check breaks __builtin(alloca)
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: felix.janda at posteo dot de
  Target Milestone: ---
            Target: arm

On arm, gcc-4.9.2 compiles the following snippet to a program which
returns 1 instead of 0 when the option -fstack-check is given.

int main(void)
{
        char *p;
        if(1) {
                char i[48];
                p = __builtin_alloca(8);
                p[0] = 1;
        }
        if(1) {
                char i[48], j[64];
                j[48] = 0;
        }
        return !p[0];
}


I could reproduce the behavior already with gcc-4.7.1.

The issue causes miscompilation of bash's lib/glob/glob.c. See:
https://bugs.gentoo.org/show_bug.cgi?id=518598


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

* [Bug c/65958] [arm] -fstack-check breaks __builtin(alloca)
  2015-05-01  6:48 [Bug c/65958] New: -fstack-check breaks __builtin(alloca) felix.janda at posteo dot de
@ 2015-05-01 12:40 ` felix.janda at posteo dot de
  2015-05-02  9:40 ` [Bug c/65958] -fstack-check breaks alloca on architectures using generic stack checking ebotcazou at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: felix.janda at posteo dot de @ 2015-05-01 12:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Felix Janda <felix.janda at posteo dot de> ---
Actually I can hit this issue also with sh4 and microblaze. The test
program needs to be modified slightly:

int main(void)
{
        char *p;
        if(1) {
                char i[48];
                p = __builtin_alloca(8);
                p[0] = 1;
        }
        if(1) {
                char i[48] , j[64];
                j[52] = 0;
        }
        return !p[0];
}


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

* [Bug c/65958] -fstack-check breaks alloca on architectures using generic stack checking
  2015-05-01  6:48 [Bug c/65958] New: -fstack-check breaks __builtin(alloca) felix.janda at posteo dot de
  2015-05-01 12:40 ` [Bug c/65958] [arm] " felix.janda at posteo dot de
@ 2015-05-02  9:40 ` ebotcazou at gcc dot gnu.org
  2015-05-02  9:43 ` ebotcazou at gcc dot gnu.org
  2015-09-17 11:07 ` [Bug middle-end/65958] " ebotcazou at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2015-05-02  9:40 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|arm                         |
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-05-02
                 CC|                            |ebotcazou at gcc dot gnu.org
   Target Milestone|---                         |6.0
            Summary|[arm] -fstack-check breaks  |-fstack-check breaks alloca
                   |__builtin(alloca)           |on architectures using
                   |                            |generic stack checking
     Ever confirmed|0                           |1

--- Comment #3 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Known issue with architectures doing stack-checking the old way like ARM, but
the underlying issue is more general and related to VLAs:

extern void abort (void);

int foo (int n)
{
  char *p, *q;

  if (1)
    {
      char i[n];
      p = __builtin_alloca (8);
      p[0] = 1;
    }

  q = __builtin_alloca (64);
  __builtin_memset (q, 0, 64);

  return !p[0];
}

int main (void)
{
  if (foo (48) != 0)
    abort ();

  return 0;
}

fails on x86-64 because of it (with or without -fstack-check).


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

* [Bug c/65958] -fstack-check breaks alloca on architectures using generic stack checking
  2015-05-01  6:48 [Bug c/65958] New: -fstack-check breaks __builtin(alloca) felix.janda at posteo dot de
  2015-05-01 12:40 ` [Bug c/65958] [arm] " felix.janda at posteo dot de
  2015-05-02  9:40 ` [Bug c/65958] -fstack-check breaks alloca on architectures using generic stack checking ebotcazou at gcc dot gnu.org
@ 2015-05-02  9:43 ` ebotcazou at gcc dot gnu.org
  2015-09-17 11:07 ` [Bug middle-end/65958] " ebotcazou at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2015-05-02  9:43 UTC (permalink / raw)
  To: gcc-bugs

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

Eric Botcazou <ebotcazou at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |ebotcazou at gcc dot gnu.org

--- Comment #4 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Two things to do here: 1) switch ARM to modern stack-checking and 2) fix the
underlying issue with alloca and VLAs.


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

* [Bug middle-end/65958] -fstack-check breaks alloca on architectures using generic stack checking
  2015-05-01  6:48 [Bug c/65958] New: -fstack-check breaks __builtin(alloca) felix.janda at posteo dot de
                   ` (2 preceding siblings ...)
  2015-05-02  9:43 ` ebotcazou at gcc dot gnu.org
@ 2015-09-17 11:07 ` ebotcazou at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ebotcazou at gcc dot gnu.org @ 2015-09-17 11:07 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Eric Botcazou <ebotcazou at gcc dot gnu.org> ---
Author: ebotcazou
Date: Thu Sep 17 11:06:57 2015
New Revision: 227860

URL: https://gcc.gnu.org/viewcvs?rev=227860&root=gcc&view=rev
Log:
        PR middle-end/65958
        * config/arm/linux-elf.h (STACK_CHECK_STATIC_BUILTIN): Define.
        * config/arm/arm-protos.h (output_probe_stack_range): Declare.
        * config/arm/arm.c: Include common/common-target.h.
        (use_return_insn): Return 0 if the static chain register was saved
        above a non-APCS frame.
        (arm_compute_static_chain_stack_bytes): Adjust for stack checking.
        (struct scratch_reg): New.
        (get_scratch_register_on_entry): New function.
        (release_scratch_register_on_entry): Likewise.
        (arm_emit_probe_stack_range): Likewise.
        (output_probe_stack_range): Likewise.
        (arm_expand_prologue): Factor out code dealing with the IP register
        for nested function and adjust it for stack checking.
        Invoke arm_emit_probe_stack_range if static builtin stack checking
        is enabled.
        (thumb1_expand_prologue): Sorry out if static builtin stack checking
        is enabled.
        (arm_expand_epilogue): Add the saved static chain register, if any, to
        the amount of pre-pushed registers to pop.
        (arm_frame_pointer_required): Return true if static stack checking is
        enabled and we want to catch the exception with the EABI unwinder.
        * config/arm/unspecs.md (UNSPEC_PROBE_STACK): New constant.
        (UNSPEC_PROBE_STACK_RANGE): Likewise.
        * config/arm/arm.md (probe_stack): New insn.
        (probe_stack_range): Likewise.

Added:
    trunk/gcc/testsuite/gcc.target/arm/stack-checking.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/arm/arm-protos.h
    trunk/gcc/config/arm/arm.c
    trunk/gcc/config/arm/arm.md
    trunk/gcc/config/arm/linux-elf.h
    trunk/gcc/config/arm/unspecs.md
    trunk/gcc/testsuite/ChangeLog


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

end of thread, other threads:[~2015-09-17 11:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-05-01  6:48 [Bug c/65958] New: -fstack-check breaks __builtin(alloca) felix.janda at posteo dot de
2015-05-01 12:40 ` [Bug c/65958] [arm] " felix.janda at posteo dot de
2015-05-02  9:40 ` [Bug c/65958] -fstack-check breaks alloca on architectures using generic stack checking ebotcazou at gcc dot gnu.org
2015-05-02  9:43 ` ebotcazou at gcc dot gnu.org
2015-09-17 11:07 ` [Bug middle-end/65958] " ebotcazou at gcc dot gnu.org

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).