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

            Bug ID: 117320
           Summary: wrong debug info for function with cold alternative
                    (-g -O2)
           Product: gcc
           Version: 14.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: debug
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eggert at cs dot ucla.edu
  Target Milestone: ---

Created attachment 59464
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59464&action=edit
wrong debug info for backtrace_function with gcc -g -O2 x86-64

We ran into a problem when debugging GNU Emacs and I reproduced it with gcc
(GCC) 14.2.1 20240912 (Red Hat 14.2.1-3) on x86-64.

Decompress and compile the attached file eval.i.gz and check the results with:

  gzip -d eval.i.gz
  gcc -g -O2 -c eval.i
  nm eval.o | grep -E 'backtrace_(next|function)'
  gdb -ex 'print backtrace_next' -ex 'print backtrace_function' eval.o

nm outputs:

  0000000000000bf0 T backtrace_function
  00000000000002c8 t backtrace_function.cold
  00000000000001bf t backtrace_function.part.0
  0000000000000c90 T backtrace_next

However, gdb outputs:

  $1 = {union specbinding *(union specbinding *)} 0xc90 <backtrace_next>
  $2 = {Lisp_Object (union specbinding *)} 0xa369 <backtrace_function>

Although gdb reports the correct address for backtrace_next, it reports the
wrong address for backtrace_function.

The problem appears to occur because backtrace_function is optimized into cold
and hot parts, in different sections, and GCC outputs incorrect debug info in
this case.

Reply via email to