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

            Bug ID: 103525
           Summary: [RISCV] wrong function entry with
                    -fpatchable-function-entry
           Product: gcc
           Version: 10.3.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: demangler
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wcohen at redhat dot com
  Target Milestone: ---

Created attachment 51914
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51914&action=edit
Reproducer to show DW_AT_low_pc doesn't always match label for function entry.

When the riscv linux kernel was compiled with CONFIG_DYNAMIC_FTRACE=y the
addresses listed in DW_AT_low_pc in the debuginfo and the /proc/kallsyms did
not match.  The difference was 0x10 bytes.  The /proc/kallsyms entry would
point to the function label and the DW_AT_low_pc in the DIE for the function
would point to the first instruction after the 8 nop instructions created by
the  -fpatchable-function-entry=8 enable by the CONFIG_DYNAMIC_FTRACE=y.  This
seems to be similar to pr99217 for mips.

Can demonstrate the problem with gcc-10.3.1 with the small reproducer
u32_test.c:

$ rpm -q gcc
gcc-10.3.1-1.fc33.riscv64
$ gcc -fpatchable-function-entry=8 -g -O2 -save-temps u32_test.c -o u32_test
$ llvm-dwarfdump --name="main" u32_test                                         
u32_test:       file format elf64-littleriscv

0x000000cf: DW_TAG_subprogram
              DW_AT_external    (true)
              DW_AT_name        ("main")
              DW_AT_decl_file   ("/home/riscv/u32_test.c")
              DW_AT_decl_line   (8)
              DW_AT_decl_column (0x01)
              DW_AT_prototyped  (true)
              DW_AT_type        (0x00000030 "int")
              DW_AT_low_pc      (0x00000000000103f0)
              DW_AT_high_pc     (0x000000000001040a)
              DW_AT_frame_base  (DW_OP_call_frame_cfa)
              DW_AT_GNU_all_call_sites  (true)
              DW_AT_sibling     (0x0000013c)

$ nm u32_test |grep main                                                        
                 U __libc_start_main@@GLIBC_2.27
00000000000103e0 T main

$gcc -g -O2 -save-temps u32_test.c -o u32_test
$  llvm-dwarfdump --name="main" u32_test 
u32_test:       file format elf64-littleriscv

0x000000cf: DW_TAG_subprogram
              DW_AT_external    (true)
              DW_AT_name        ("main")
              DW_AT_decl_file   ("/home/riscv/u32_test.c")
              DW_AT_decl_line   (8)
              DW_AT_decl_column (0x01)
              DW_AT_prototyped  (true)
              DW_AT_type        (0x00000030 "int")
              DW_AT_low_pc      (0x00000000000103e0)
              DW_AT_high_pc     (0x00000000000103fa)
              DW_AT_frame_base  (DW_OP_call_frame_cfa)
              DW_AT_GNU_all_call_sites  (true)
              DW_AT_sibling     (0x0000013c)
$ nm u32_test |grep main 
                 U __libc_start_main@@GLIBC_2.27
00000000000103e0 T main

Reply via email to