[Bug inline-asm/89839] New: section not reset to text for top level asm

andi-gcc at firstfloor dot org gcc-bugzilla@gcc.gnu.org
Wed Mar 27 00:54:00 GMT 2019


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

            Bug ID: 89839
           Summary: section not reset to text for top level asm
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: inline-asm
          Assignee: unassigned at gcc dot gnu.org
          Reporter: andi-gcc at firstfloor dot org
  Target Milestone: ---

The ELF section from the previous function doesn't get reset before top level
asm statements:

e.g.

__attribute__((section("foo"))) void func(void)
{
}

asm("foo:\n");

gcc -S gives

 .section foo,"ax",@progbits <----------------- sets the section
 .globl func
 .type func, @function
func:
.LFB0:
 .cfi_startproc
 pushq %rbp
 .cfi_def_cfa_offset 16
 .cfi_offset 6, -16
 movq %rsp, %rbp  
 .cfi_def_cfa_register 6
 nop
 popq %rbp
 .cfi_def_cfa 7, 8
 ret
 .cfi_endproc
.LFE0:
 .size func, .-func
<--------------------------- no section reset before the asm
#APP
 foo:


The problem is if foo is some section with special behavior (for example
initcall sections in the Linux kernel) this can cause crashes. I've seen such
problems with LTO on the Linux kernel.

gcc should always reset the section to .text before emitting top level asm.

See with 8.x, but also trunk.


More information about the Gcc-bugs mailing list