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

            Bug ID: 64963
           Summary: IPA Cloning/Splitting does not copy function section
                    attributes resulting in kernel miscompilation
           Product: gcc
           Version: 5.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: ipa
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jgreenhalgh at gcc dot gnu.org
                CC: hubicka at gcc dot gnu.org, jamborm at gcc dot gnu.org
              Host: x86_64-unknown-linux-gnu
            Target: aarch64-none-elf

Created attachment 34688
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=34688&action=edit
Cloning fails to maintain section attributes on foo

When we create a clone for constant propagation, or in ipa-split,
we don't clone the section attribute for that function. For kernel
builds this can result in code ending up in the wrong section, resulting
in all sorts of carnage.

The testcase attached shows the issue for cloning (it is much harder
to engineer one for splitting, but the problem is analogous).

You can reproduce the bug with -O3. For AArch64 this gives:

    .cpu generic+fp+simd
    .file    "ipa-clone-1.c"
    .text
    .align    2
    .p2align 3,,7
    .type    foo.constprop.0, %function
foo.constprop.0:
    mov    w0, 35
    ret
    .size    foo.constprop.0, .-foo.constprop.0
    .align    2
    .p2align 3,,7
    .global    bar
    .type    bar, %function
bar:
    b    foo.constprop.0
    .size    bar, .-bar
    .ident    "GCC: (unknown) 5.0.0 20150205 (experimental)"

Note that foo.constprop.0 is in the text section, while foo was declared with:

static int __attribute__ ((noinline section ("test_section")))
foo (int arg)

I would have expected to see:

    .arch armv8-a+fp+simd
    .file    "ipa-clone-1.c"
    .section    test_section,"ax",%progbits
    .align    2
    .p2align 3,,7
    .type    foo.constprop.0, %function
foo.constprop.0:
    mov    w0, 35
    ret
    .size    foo.constprop.0, .-foo.constprop.0
    .text
    .align    2
    .p2align 3,,7
    .global    bar
    .type    bar, %function
bar:
    b    foo.constprop.0
    .size    bar, .-bar
    .ident    "GCC: (unknown) 5.0.0 20150205 (experimental)"

Reply via email to