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

            Bug ID: 124869
           Summary: Segfault in classify_object_over_fdes when combining
                    -static, -flto, and -lm
           Product: gcc
           Version: 14.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libgcc
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jiannmao at qq dot com
  Target Milestone: ---

Environment
- GCC version: 14.3.0
- OS: Ubuntu 22.04 LTS(x86_64)
- ld: GNU ld (GNU Binutils) 2.41
- glibc version: 2.35

test.c
```C
#include <fenv.h>
int main() {
  feclearexcept(FE_ALL_EXCEPT);
  return 0;
}
```
gcc test.c -static -flto -lm -o a.out
./a.out


Backtrace

```
Program received signal SIGSEGV, Segmentation fault.
classify_object_over_fdes (ob=0x4cb2a0 <object>, this_fde=0x154e4a0f,
range=0x7fffffffdf10)
    at ../../../gcc-14.3.0/libgcc/unwind-dw2-fde.c:732
732       for (; ! last_fde (ob, this_fde); this_fde = next_fde (this_fde))

(gdb) bt
#0  classify_object_over_fdes (ob=0x4cb2a0 <object>, this_fde=0x154e4a0f, ...)
    at ../../../gcc-14.3.0/libgcc/unwind-dw2-fde.c:732
#1  register_pc_range_for_object (begin=<optimized out>, ob=0x4cb2a0 <object>)
    at ../../../gcc-14.3.0/libgcc/unwind-dw2-fde.c:118
#2  __register_frame_info_bases (begin=<optimized out>, ob=0x4cb2a0 <object>,
tbase=0x0, dbase=0x0)
    at ../../../gcc-14.3.0/libgcc/unwind-dw2-fde.c:144
#3  __register_frame_info_bases (...)
    at ../../../gcc-14.3.0/libgcc/unwind-dw2-fde.c:126
#4  __register_frame_info (begin=<optimized out>, ob=0x4cb2a0 <object>)
    at ../../../gcc-14.3.0/libgcc/unwind-dw2-fde.c:159
#5  frame_dummy () at ...
#6  0x0000000000000001 in ?? ()
#7  __libc_start_main_impl ()
#8  _start ()

```

The crash occurs inside libgcc's FDE registration routine during program
initialization, before main() is reached.

The crash does not occur when:
- using GCC 7.3.0
- flto is removed: gcc test.c -static -lm -o a.out
- static is removed: gcc test.c -flto -lm -o a.out

Reply via email to