June 17, 2017
https://issues.dlang.org/show_bug.cgi?id=16856

Jonathan M Davis <issues.dlang@jmdavisProg.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|FIXED                       |---

--
June 18, 2017
https://issues.dlang.org/show_bug.cgi?id=16856

--- Comment #9 from Nemanja Boric <4burgos@gmail.com> ---
Thanks to GitHub bot, I am reminded about this issue. I'm back and will start looking next week.

--
June 18, 2017
https://issues.dlang.org/show_bug.cgi?id=16856

Nemanja Boric <4burgos@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|nobody@puremagic.com        |4burgos@gmail.com

--
July 08, 2017
https://issues.dlang.org/show_bug.cgi?id=16856

--- Comment #10 from Nemanja Boric <4burgos@gmail.com> ---
Ok, I finally got some time to get back to this issue.

There's a sigbus really running, but this is caused by GC, because the runtime asserts in the shared library finalizers, so it seems that the instance is no longer there.

I've traced the failing druntime assert (so far, who knows
what else is waiting for us) to this particular commit in rtld.c:

https://github.com/freebsd/freebsd/commit/3ff2e66ecba2094f5c1c1efe7f2d009649527195

So, this is the problem. At the end of the program, fini()s are called for the shared library and the main executable. Then they call `_do_global_dtors_aux`, and at that point they will call _d_dso_registry, which will (the problem is here:) call dlopen (albeit with RTLD_NOLOAD) to obtain the handle for the object by name.

However, since this particular commit, this doesn't work anymore (and it's questionable if it should work) - you can't bump a reference count of an object that's just going to die (dlopen still bumps reference count, even with RTLD_LOAD passed).

I would guess somehow skipping dlopen calls in this scenario should be figured
out.
Maybe skipping just for the current object, or maybe caching the handles when
first obtained (not sure if they can change on their own; I don't think so, but
still). I'll see to submit a PR tomorrow, now I know where the problem is.

It was quite a ride finding this out. Because first call to dlopen was failing
for the
main executable, so documentation says: "use NULL if you want the main
executable instead", so after doing this - I got it working, so I thought
there's something
special with this path. What's interesting is that my confusion is caused by
the bug
in FreeBSD's code - if the current limitation apply - don't reference "doomed"
object,
one shouldn't be able to work around it by passing NULL. I'll see into sending
a patch there as well.

--
July 08, 2017
https://issues.dlang.org/show_bug.cgi?id=16856

--- Comment #11 from Nemanja Boric <4burgos@gmail.com> ---
https://github.com/dlang/druntime/pull/1862

--
July 09, 2017
https://issues.dlang.org/show_bug.cgi?id=16856

--- Comment #12 from github-bugzilla@puremagic.com ---
Commits pushed to master at https://github.com/dlang/druntime

https://github.com/dlang/druntime/commit/ce863ecdd9ba0e56a40c8afa7b247946702f2995 Fix issue 16856: Don't use dlopen from the fini sections

In case finalizers are called from the runtime linker
we shouldn't try to get handle to and reference the
dying shared object. This was used just for the asserting,
so this simply removes the assert making it working on the
platforms where this is strictly forbiden (e.g. FreeBSD 12).

https://github.com/dlang/druntime/commit/1d983500f8d66b2bcb8fac514b2b23394ab60b37 Merge pull request #1862 from Burgos/dso

Fis issue 16856: Don't use dlopen from the fini sections merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>

--
July 14, 2017
https://issues.dlang.org/show_bug.cgi?id=16856

--- Comment #13 from Jonathan M Davis <issues.dlang@jmdavisProg.com> ---
I confirm that this works with the latest TrueOS, though I expect that it wouldn't work on the latest FreeBSD 12, because of the 64-bit inode issue (whereas even though TrueOS is based on FreeBSD CURRENT, it hasn't pulled in those changes yet precisely because of the breakage that they cause). That's a separate bug though: bug #17596.

Thanks!

--
July 14, 2017
https://issues.dlang.org/show_bug.cgi?id=16856

--- Comment #14 from Nemanja Boric <4burgos@gmail.com> ---
Thank you for writing back and you're very welcome! Thanks for pointing out to that issue, I'll follow it closely.

--
July 15, 2017
https://issues.dlang.org/show_bug.cgi?id=16856

--- Comment #15 from Vladimir Panteleev <dlang-bugzilla@thecybershadow.net> ---
(In reply to Jonathan M Davis from comment #13)
> That's a separate bug though: bug #17596.

Clickable link: issue 17596

See the Bugzilla manual: https://www.bugzilla.org/docs/4.4/en/html/hintsandtips.html#idp6611456

--
July 15, 2017
https://issues.dlang.org/show_bug.cgi?id=16856

--- Comment #16 from Jonathan M Davis <issues.dlang@jmdavisProg.com> ---
(In reply to Vladimir Panteleev from comment #15)
> (In reply to Jonathan M Davis from comment #13)
> > That's a separate bug though: bug #17596.
> 
> Clickable link: issue 17596
> 
> See the Bugzilla manual: https://www.bugzilla.org/docs/4.4/en/html/hintsandtips.html#idp6611456

Thanks, I can never remember the exct syntax, and different software for different sites that link in numbers for issues or posts ot other things like this tend to do it slightly differently. And since bugzilla doesn't have the ability to preview or edit your comments, it makes it kind of hard to get right unless you're lucky enough to remember correctly.

--