[Bug target/92424] [aarch64] Broken code with -fpatchable-function-entry and BTI

cvs-commit at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Tue Jan 21 15:56:00 GMT 2020


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

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Szabolcs Nagy <nsz@gcc.gnu.org>:

https://gcc.gnu.org/g:c292cfe539cd7c060caad826d362ed5e845bfbef

commit r10-6114-gc292cfe539cd7c060caad826d362ed5e845bfbef
Author: Szabolcs Nagy <szabolcs.nagy@arm.com>
Date:   Wed Jan 15 12:23:40 2020 +0000

    [AArch64] PR92424: Fix -fpatchable-function-entry=N,M with BTI

    This is a workaround that emits a BTI after the function label if that
    is followed by a patch area. We try to remove the BTI that follows the
    patch area (this may fail e.g. if the first instruction is a PACIASP).

    So before this commit -fpatchable-function-entry=3,1 with bti generates

        .section __patchable_function_entries
        .8byte .LPFE
        .text
      .LPFE:
        nop
      foo:
        nop
        nop
        bti c // or paciasp
        ...

    and after this commit

        .section __patchable_function_entries
        .8byte .LPFE
        .text
      .LPFE:
        nop
      foo:
        bti c
        nop
        nop
        // may be paciasp
        ...

    and with -fpatchable-function-entry=1 (M=0) the code now is

      foo:
        bti c
        .section __patchable_function_entries
        .8byte .LPFE
        .text
      .LPFE:
        nop
        // may be paciasp
        ...

    There is a new bti insn in the middle of the patchable area users need
    to be aware of unless M=0 (patch area is after the new bti) or M=N
    (patch area is before the label, no new bti). Note: bti is not added to
    all functions consistently (it can be turned off per function using a
    target attribute or the compiler may detect that the function is never
    called indirectly), so if bti is inserted in the middle of a patch area
    then user code needs to deal with detecting it.

    Tested on aarch64-none-linux-gnu.

    gcc/ChangeLog:

        PR target/92424
        * config/aarch64/aarch64.c (aarch64_declare_function_name): Set
        cfun->machine->label_is_assembled.
        (aarch64_print_patchable_function_entry): New.
        (TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY): Define.
        * config/aarch64/aarch64.h (struct machine_function): New field,
        label_is_assembled.

    gcc/testsuite/ChangeLog:

        PR target/92424
        * gcc.target/aarch64/pr92424-1.c: New test.
        * gcc.target/aarch64/pr92424-2.c: New test.
        * gcc.target/aarch64/pr92424-3.c: New test.


More information about the Gcc-bugs mailing list