Bug 42392 - [LTO] ICE with top level asm
Summary: [LTO] ICE with top level asm
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: lto (show other bugs)
Version: 4.5.0
: P3 normal
Target Milestone: 4.5.0
Assignee: Richard Biener
URL:
Keywords: ice-on-valid-code, lto
Depends on:
Blocks:
 
Reported: 2009-12-16 08:35 UTC by Robert Millan
Modified: 2009-12-16 23:07 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2009-12-16 13:43:16


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Millan 2009-12-16 08:35:56 UTC
I got this error when trying to compile GRUB (latest bzr) on amd64 with -flto:

lto1: internal compiler error: compressed stream: buffer error

The culprit was an acinclude check, which can be reduced to the following test case:

asm (".globl start; start: nop");
int
main ()
{
}

I'm not sure this can be considered valid C (or at least valid GNU C). I'm tentatively setting ice-on-invalid-code keyword. If I understand correctly, it is equivalent to:

void start ()
{
  asm ("nop");
}
int
main ()
{
}

In any case I suppose if the code isn't valid, GCC ought to fail more gracefully than this, so I report anyway in case you'd like to know :-)
Comment 1 Andrew Pinski 2009-12-16 08:38:38 UTC
top level asm is valid GNU C code.
Comment 2 Richard Biener 2009-12-16 13:43:16 UTC
The issue here is that the asm doesn't switch sections properly and we emit
LTO sections before the actual assembly.  So we end up with

...
        .section        .gnu.lto_.opts,"",@progbits
        .string "x\001\001,"
        .string "\323\377\001"
        .string ""
...
        .ascii  "\"\306\003T"
        .section        .gnu.lto_main
#APP
        .globl start; start: nop
#NO_APP
        .text
.globl main
        .type   main, @function
main:
        pushl   %ebp
        movl    %esp, %ebp
        popl    %ebp
        ret
        .size   main, .-main
        .comm   gnu_lto_v1,1,1

where after finishing .gnu.lto_.opts we switch "back" to .gnu.lto_main which
then has the toplevel asm appended.

Oops.

Now assembling the testcase w/o LTO also gets us

        .file   "t.c"
#APP
        .globl start; start: nop
#NO_APP
        .text
.globl main
        .type   main, @function
main:
...

thus the asm gets emitted in the default section.  Which means the testcase
is kind of invalid (and the issue is that we emit LTO stuff at the beginning,
not at the end where it could remain unspecified).
Comment 3 Richard Biener 2009-12-16 23:07:20 UTC
Fixed.
Comment 4 Richard Biener 2009-12-16 23:07:29 UTC
Subject: Bug 42392

Author: rguenth
Date: Wed Dec 16 23:07:10 2009
New Revision: 155298

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=155298
Log:
2009-12-16  Richard Guenther  <rguenther@suse.de>

	PR lto/42392
	* langhooks.c (lhd_begin_section): Make sure to switch back
	to the text section, not some random one.

	* gcc.dg/lto/20091216-1_0.c: New testcase.

Added:
    trunk/gcc/testsuite/gcc.dg/lto/20091216-1_0.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/langhooks.c
    trunk/gcc/testsuite/ChangeLog