public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug driver/114839] New: g++-linked FreeBSD static binaries abort upon exception
@ 2024-04-24 17:50 emaste at freebsd dot org
  2024-04-24 17:55 ` [Bug target/114839] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: emaste at freebsd dot org @ 2024-04-24 17:50 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114839
           Summary: g++-linked FreeBSD static binaries abort upon
                    exception
           Product: gcc
           Version: 13.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: driver
          Assignee: unassigned at gcc dot gnu.org
          Reporter: emaste at freebsd dot org
  Target Milestone: ---

When compiling and statically linking a binary on FreeBSD with GCC the EH_FRAME
segment is omitted, and then libgcc's exception unwinder aborts when it cannot
find the EH_FRAME segment. See FreeBSD bug report
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=278551 for full details and
history.

From -dumpspecs it looks like (assuming I understand correctly) that
--eh-frame-header is not passed when static is specified:

...
*link:
%{!static|static-pie:--eh-frame-hdr}   %{m32:-m elf_i386_fbsd}%{!m32:-m
elf_x86_64_fbsd}   %{p:%nconsider using '-pg' instead of '-p' with gprof(1)}  
%{v:-V}   %{assert*} %{R*} %{rpath*} %{defsym*}   %{shared:-Bshareable %{h*}
%{soname*}}     %{!shared:       %{!static:         %{rdynamic:-export-dynamic}
    -dynamic-linker %(fbsd_dynamic_linker) }     %{static:-Bstatic}}  
%{symbolic:-Bsymbolic}

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/114839] g++-linked FreeBSD static binaries abort upon exception
  2024-04-24 17:50 [Bug driver/114839] New: g++-linked FreeBSD static binaries abort upon exception emaste at freebsd dot org
@ 2024-04-24 17:55 ` pinskia at gcc dot gnu.org
  2024-04-24 18:01 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-24 17:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
From gcc/config/freebsd.h:
#if defined(HAVE_LD_EH_FRAME_HDR)
#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
#endif


The !static part comes from r0-95899-g2208d2ac9546de .

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/114839] g++-linked FreeBSD static binaries abort upon exception
  2024-04-24 17:50 [Bug driver/114839] New: g++-linked FreeBSD static binaries abort upon exception emaste at freebsd dot org
  2024-04-24 17:55 ` [Bug target/114839] " pinskia at gcc dot gnu.org
@ 2024-04-24 18:01 ` pinskia at gcc dot gnu.org
  2024-04-24 18:05 ` emaste at freebsd dot org
  2024-04-24 20:29 ` emaste at freebsd dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-24 18:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Hmm, I wonder why freebsd needs to be different from every most other targets
though here:
```
config/alpha/elf.h:#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
config/arc/linux.h:#define LINK_EH_SPEC "--eh-frame-hdr "
config/dragonfly.h:#define LINK_EH_SPEC "--eh-frame-hdr"
config/freebsd.h:#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
config/fuchsia.h:                 "%{!no-eh-frame-hdr: --eh-frame-hdr}" \
config/gnu-user.h:#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
config/netbsd.h:#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
config/openbsd.h:#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "
config/sol2.h:   --eh-frame-hdr to create the required .eh_frame_hdr sections. 
*/
config/sol2.h:#define LINK_EH_SPEC "%{!static|static-pie:--eh-frame-hdr} "

```

Is it the case that unwinder from LLVM needs a .eh_frame_hdr for static
binaries while GCC's libgcc one does not?

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/114839] g++-linked FreeBSD static binaries abort upon exception
  2024-04-24 17:50 [Bug driver/114839] New: g++-linked FreeBSD static binaries abort upon exception emaste at freebsd dot org
  2024-04-24 17:55 ` [Bug target/114839] " pinskia at gcc dot gnu.org
  2024-04-24 18:01 ` pinskia at gcc dot gnu.org
@ 2024-04-24 18:05 ` emaste at freebsd dot org
  2024-04-24 20:29 ` emaste at freebsd dot org
  3 siblings, 0 replies; 5+ messages in thread
From: emaste at freebsd dot org @ 2024-04-24 18:05 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Ed Maste <emaste at freebsd dot org> ---
(In reply to Andrew Pinski from comment #2)

> Is it the case that unwinder from LLVM needs a .eh_frame_hdr for static
> binaries while GCC's libgcc one does not?

That's possible, but in the investigation in the FreeBSD bug report I believe
that GCC's libgcc is being used here:

#0  0x00000000004d4dca in thr_kill ()
#1  0x00000000004c226f in raise ()
#2  0x00000000004df6f9 in abort ()
#3  0x0000000000402bef in uw_init_context_1 (
    context=context@entry=0x7fffdfffdd50, 
    outer_cfa=outer_cfa@entry=0x7fffdfffdf80, 
    outer_ra=0x4b2326 <thread_unwind+54>)
    at ../../../gcc-13.2.0/libgcc/unwind-dw2.c:1336
#4  0x00000000004ad986 in _Unwind_ForcedUnwind (exc=0x800818940, 
    stop=0x4b24d0 <thread_unwind_stop>, stop_argument=0x0)
    at ../../../gcc-13.2.0/libgcc/unwind.inc:212

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug target/114839] g++-linked FreeBSD static binaries abort upon exception
  2024-04-24 17:50 [Bug driver/114839] New: g++-linked FreeBSD static binaries abort upon exception emaste at freebsd dot org
                   ` (2 preceding siblings ...)
  2024-04-24 18:05 ` emaste at freebsd dot org
@ 2024-04-24 20:29 ` emaste at freebsd dot org
  3 siblings, 0 replies; 5+ messages in thread
From: emaste at freebsd dot org @ 2024-04-24 20:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Ed Maste <emaste at freebsd dot org> ---
Thanks - 54568 adds some good context. Based on that I think it may that frame
registration calls are not present in the FreeBSD crt bits used for static
binaries, which could explain the differences in OSes.

We could look into adding the registration calls, but it seems that using
--eh-frame-hdr always is the best path for us.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2024-04-24 20:29 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-24 17:50 [Bug driver/114839] New: g++-linked FreeBSD static binaries abort upon exception emaste at freebsd dot org
2024-04-24 17:55 ` [Bug target/114839] " pinskia at gcc dot gnu.org
2024-04-24 18:01 ` pinskia at gcc dot gnu.org
2024-04-24 18:05 ` emaste at freebsd dot org
2024-04-24 20:29 ` emaste at freebsd dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).