public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rjones at redhat dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug go/114699] New: gcc-go -buildmode=c-shared doesn't use -Wl,-z,nodelete so libraries crash when dlclosed
Date: Thu, 11 Apr 2024 21:41:14 +0000	[thread overview]
Message-ID: <bug-114699-4@http.gcc.gnu.org/bugzilla/> (raw)

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

            Bug ID: 114699
           Summary: gcc-go -buildmode=c-shared doesn't use -Wl,-z,nodelete
                    so libraries crash when dlclosed
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: go
          Assignee: ian at airs dot com
          Reporter: rjones at redhat dot com
  Target Milestone: ---

I was chasing a crash in nbdkit-golang-plugin
(https://gitlab.com/nbdkit/nbdkit/-/tree/master/plugins/golang?ref_type=heads).

This crash only happens with gcc-go (and quite reproducibly), but doesn't
happen with golang.  The crash happened when the plugin was being unloaded
with dlclose(3).

Long story short, this is a bug that has already been reported and "fixed"
(or more accurately, worked around) in golang:

https://github.com/golang/go/issues/11100

Because goroutines, the garbage collector, etc is basically running all
the time in golang programs, you cannot safely remove them from memory.
Any attempt to actually dlclose a golang plugin will crash most of the
time when a goroutine/the GC executes some code after dlclose.

golang works around this by linking shared libraries it creates with
-Wl,-z,nodelete:

https://github.com/golang/go/blob/1843464f014c946c1663de76249267486887626f/src/cmd/link/internal/ld/lib.go#L1587

Because gcc-go doesn't do this, the same shared libraries crash when
compiled with it.

Fix (or workaround) is probably to copy what golang does.

             reply	other threads:[~2024-04-11 21:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-11 21:41 rjones at redhat dot com [this message]
2024-04-11 21:43 ` [Bug go/114699] " rjones at redhat dot com
2024-04-11 21:45 ` rjones at redhat dot com
2024-04-11 21:47 ` rjones at redhat dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-114699-4@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).