This is the mail archive of the gcc-prs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

middle-end/7736: gcc destroys stack layout when a local label is used


>Number:         7736
>Category:       middle-end
>Synopsis:       gcc destroys stack layout when a local label is used
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Tue Aug 27 10:26:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Piotr Wyderski
>Release:        3.0, 3.0.1, 3.0.4 (supposably all versions)
>Organization:
>Environment:
IA-32 Celeron, Red Hat Linux 7.2.
>Description:
When a local label is used in a function, gcc generates
broken code. The simplest example is:

void test(void) {
    ({ __label__ x;
    x:
    goto x;
    });
}

gcc -S -O2 1.c, which produces:

.file "1.c"
.text
.align 16
.globl test
.type test,@function
test:
pushl %ebp
movl %esp, %ebp
subl $8, %esp
.L2:
jmp .L2
.Lfe1:
.size test,.Lfe1-test
.ident "GCC: (GNU) 3.0.4"

The error is because of "subl $8,%esp". This is NOT an alignment issue,
because sometimes (when a function is slightly larger) it produces things
like:

    push edx
    push edx
    // very small function body here, which _doesn't_ use edx nor ecx.
    pop   ecx
    pop   eax
    ret

There's no such an error when a global (i.e. normal) label is used
instead, code is generated properly. I've tested that on many ways
and I am completely sure this wrong behaviour is because of local
labels. When the function code is quite large, it causes a crash of
the application, thus this bug is critical.
>How-To-Repeat:
Use a local label in a (small) function and read assembly output.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]