https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98776
Bug ID: 98776 Summary: DW_AT_low_pc is inconsistent with function entry address, when enabling -fpatchable-function-entry Product: gcc Version: 11.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: debug Assignee: unassigned at gcc dot gnu.org Reporter: lvlin at mail dot ustc.edu.cn Target Milestone: --- Target: x86,arm64 -fpatchable-function-entry will generate N NOPs at the beginning of each function. Observe the binary compiled by gcc, the function entry address is inconsistent with the value of DW_AT_low_pc in the corresponding DWARF data. I used a toy example to describe the issue; 1.Compile the source file toy_exam.c $ gcc -o toy_exam.gcc toy_exam.c -g -gdwarf-4 -fpatchable-function-entry=2 -save-temps 2.Check the symbolic address of the function fun_a $ readelf -s toy_exam.gcc |grep -w fun_a 95: 00000000000007f0 80 FUNC GLOBAL DEFAULT 13 fun_a 3.Display assembler contents objdump -d toy_exam.gcc |grep -A 8 -w \<fun_a\>: 00000000000007f0 <fun_a>: 7f0: d503201f nop 7f4: d503201f nop 7f8: a9be7bfd stp x29, x30, [sp, #-32]! 7fc: 910003fd mov x29, sp 800: 52800040 mov w0, #0x2 // #2 804: b90017e0 str w0, [sp, #20] 808: 528000a0 mov w0, #0x5 // #5 80c: b9001be0 str w0, [sp, #24] 4.dump dwarf info $ llvm-dwarfdump toy_exam.gcc |grep -C 10 -w fun_a 0x00000315: DW_TAG_subprogram DW_AT_external (true) DW_AT_name ("fun_a") DW_AT_decl_file ("/home/jianlin/code/test/toy_exam.c") DW_AT_decl_line (14) DW_AT_decl_column (0x06) DW_AT_low_pc (0x00000000000007f8) DW_AT_high_pc (0x0000000000000840) DW_AT_frame_base (DW_OP_call_frame_cfa) DW_AT_GNU_all_tail_call_sites (true) DW_AT_sibling (0x0000035d) 5. Assembler code fun_a: .section __patchable_function_entries .8byte .LPFE2 .text .LPFE2: nop nop .LFB7: .loc 1 15 1 .cfi_startproc stp x29, x30, [sp, -32]! .cfi_def_cfa_offset 32 .cfi_offset 29, -32 .cfi_offset 30, -24 mov x29, sp .loc 1 16 13 $ gcc -v Using built-in specs. COLLECT_GCC=gcc COLLECT_LTO_WRAPPER=/usr/gcc-trunk/libexec/gcc/aarch64-unknown-linux-gnu/11.0.0/lto-wrapper Target: aarch64-unknown-linux-gnu Configured with: ../gcc/configure --prefix=/usr/gcc-trunk --enable-languages=c,c++,fortran --disable-libquadmath --disable-libquadmath-support --disable-werror --disable-bootstrap --enable-gold Thread model: posix Supported LTO compression algorithms: zlib gcc version 11.0.0 20210119 (experimental) (GCC) the first instruction in the compile unit indicated by DW_AT_low_pc does not include NOP. GCC-9, GCC-10 and the latest master branch were respectively tested, and the results were the same.