The current -fpatchable-function-entry implementation is done almost behind the backend back. Backend doesn't know if and where patchable area will be generated during RTL passes.
TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY is only used to print out assembly codes for patchable area. This leads to wrong codes with -fpatchable-function-entry: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92424 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93492 Also .cfi_startproc and DWARF info are at the wrong places when -fpatchable-function-entry is used. This patch set has 3 parts: 1. Add a pseudo UNSPECV_PATCHABLE_AREA instruction and define TARGET_ASM_PRINT_PATCHABLE_FUNCTION_ENTRY to work around the -fpatchable-function-entry implementation deficiency. 2. Add patch_area_size and patch_area_entry to cfun to make the patchable area info is available in RTL passes so that backend can handle patchable area properly. It also limits patch_area_size and patch_area_entry to 65535, which is a reasonable maximum size for patchable area. Other backends can also use it properly generate patchable area. 3. Remove workaround in UNSPECV_PATCHABLE_AREA generation. If the patch set is acceptable, I can combine patch 1 and patch 3 into a single patch. H.J. Lu (3): x86: Add UNSPECV_PATCHABLE_AREA Add patch_area_size and patch_area_entry to cfun x86: Simplify UNSPECV_PATCHABLE_AREA generation gcc/config/i386/i386-features.c | 130 ++++++++++++------ gcc/config/i386/i386-passes.def | 2 +- gcc/config/i386/i386-protos.h | 5 +- gcc/config/i386/i386.c | 51 ++++++- gcc/config/i386/i386.h | 14 +- gcc/config/i386/i386.md | 17 +++ gcc/doc/invoke.texi | 1 + gcc/function.c | 35 +++++ gcc/function.h | 6 + gcc/opts.c | 4 +- .../patchable_function_entry-error-1.c | 9 ++ .../patchable_function_entry-error-2.c | 9 ++ .../patchable_function_entry-error-3.c | 20 +++ gcc/testsuite/gcc.target/i386/pr93492-1.c | 73 ++++++++++ gcc/testsuite/gcc.target/i386/pr93492-2.c | 12 ++ gcc/testsuite/gcc.target/i386/pr93492-3.c | 13 ++ gcc/testsuite/gcc.target/i386/pr93492-4.c | 11 ++ gcc/testsuite/gcc.target/i386/pr93492-5.c | 12 ++ gcc/varasm.c | 30 +--- 19 files changed, 375 insertions(+), 79 deletions(-) create mode 100644 gcc/testsuite/c-c++-common/patchable_function_entry-error-1.c create mode 100644 gcc/testsuite/c-c++-common/patchable_function_entry-error-2.c create mode 100644 gcc/testsuite/c-c++-common/patchable_function_entry-error-3.c create mode 100644 gcc/testsuite/gcc.target/i386/pr93492-1.c create mode 100644 gcc/testsuite/gcc.target/i386/pr93492-2.c create mode 100644 gcc/testsuite/gcc.target/i386/pr93492-3.c create mode 100644 gcc/testsuite/gcc.target/i386/pr93492-4.c create mode 100644 gcc/testsuite/gcc.target/i386/pr93492-5.c -- 2.24.1