Bug 236546

Summary: [PATCH] math/mprime: does not work on FreeBSD 12.
Product: Ports & Packages Reporter: Ivan Rozhuk <rozhuk.im>
Component: Individual Port(s)Assignee: Steve Wills <swills>
Status: Closed FIXED    
Severity: Affects Some People CC: dim, emaste, kib, rozhuk.im
Priority: --- Flags: rozhuk.im: maintainer-feedback+
rozhuk.im: merge-quarterly?
Version: Latest   
Hardware: Any   
OS: Any   
Attachments:
Description Flags
patch
none
patch
rozhuk.im: maintainer-approval+
Force mprime linking to use BFD ld
none
readelf -aW output for lld-linked mprime executable
none
readelf -aW output for bfd-linked mprime executable
none
use LLD_UNSAFE instead of gcc to avoid run error on FreeBSD 12 rozhuk.im: maintainer-approval+

Description Ivan Rozhuk 2019-03-15 07:09:26 UTC
Created attachment 202876 [details]
patch

I discover that mprime fail to start on FreeBSD 12.
There is something wrong with compiling/linking the used clang.
Then build with gcc - run ok.

Also multithreaded build enabled.
Comment 1 Ivan Rozhuk 2019-03-15 07:14:56 UTC
Created attachment 202877 [details]
patch
Comment 2 Dimitry Andric freebsd_committer freebsd_triage 2019-03-16 12:28:03 UTC
Created attachment 202908 [details]
Force mprime linking to use BFD ld

There's definitely something fishy going on:

$ gdb /usr/local/bin/mprime-real
GNU gdb (GDB) 8.2.1 [GDB v8.2.1 for FreeBSD]
...
(gdb) run
Starting program: /usr/local/bin/mprime-real
target.c:2238: internal-error: void target_mourn_inferior(ptid_t): Assertion `ptid == inferior_ptid' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Quit this debugging session? (y or n) y

This is a bug, please report it.  For instructions, see:
<http://www.gnu.org/software/gdb/bugs/>.

target.c:2238: internal-error: void target_mourn_inferior(ptid_t): Assertion `ptid == inferior_ptid' failed.
A problem internal to GDB has been detected,
further debugging may prove unreliable.
Create a core file of GDB? (y or n) n

And even worse, the dynamic linker asserts on it:

$ ldd /usr/local/bin/mprime-real
/usr/local/bin/mprime-real:
/usr/local/bin/mprime-real: signal 6

It looks like ld.lld is mangling the executable somehow: when I force the mprime-real executable to be linked with ld.bfd, it does run correctly.  See the force-ld-bfd-1.diff patch.
Comment 3 Dimitry Andric freebsd_committer freebsd_triage 2019-03-16 12:29:42 UTC
Created attachment 202909 [details]
readelf -aW output for lld-linked mprime executable
Comment 4 Dimitry Andric freebsd_committer freebsd_triage 2019-03-16 12:30:05 UTC
Created attachment 202910 [details]
readelf -aW output for bfd-linked mprime executable
Comment 5 Ivan Rozhuk 2019-03-16 16:45:16 UTC
(In reply to Dimitry Andric from comment #2)
LLD_UNSAFE=	yes
should do same.
Comment 6 Dimitry Andric freebsd_committer freebsd_triage 2019-03-16 17:28:37 UTC
(In reply to rozhuk.im from comment #5)
> (In reply to Dimitry Andric from comment #2)
> LLD_UNSAFE=	yes
> should do same.

I thought of that, but it doesn't seem to work since the makefile is rather non-standard and doesn't follow any regular conventions.  But if it works for you, please use it.
Comment 7 Ivan Rozhuk 2019-03-16 17:39:24 UTC
Created attachment 202917 [details]
use LLD_UNSAFE instead of gcc to avoid run error on FreeBSD 12
Comment 8 Ivan Rozhuk 2019-03-16 17:44:26 UTC
(In reply to Dimitry Andric from comment #6)
It wotks for me because I already patch makefiles to proper handle LDFLAGS and other staff.
Comment 9 commit-hook freebsd_committer freebsd_triage 2019-04-12 20:18:14 UTC
A commit references this bug:

Author: swills
Date: Fri Apr 12 20:17:33 UTC 2019
New revision: 498741
URL: https://svnweb.freebsd.org/changeset/ports/498741

Log:
  math/mprime: avoid runtime issue

  PR:		236546
  Submitted by:	rozhuk.im@gmail.com (maintainer)

Changes:
  head/math/mprime/Makefile
  head/math/mprime/files/patch-gwnum_makebsd64
  head/math/mprime/files/patch-gwnum_makemsys
  head/math/mprime/files/patch-linux64_makebsd
  head/math/mprime/files/patch-linux_makebsd
Comment 10 Steve Wills freebsd_committer freebsd_triage 2019-04-12 20:20:14 UTC
Committed, thanks!