Bug 226991

Summary: lang/smlnj: fails to link with lld as the system linker
Product: Ports & Packages Reporter: Ed Maste <emaste>
Component: Individual Port(s)Assignee: Tobias Kortkamp <tobik>
Status: Closed FIXED    
Severity: Affects Only Me CC: joemann
Priority: --- Flags: bugzilla: maintainer-feedback? (joemann)
Version: Latest   
Hardware: Any   
OS: Any   
Bug Depends on:    
Bug Blocks: 214864    

Description Ed Maste freebsd_committer freebsd_triage 2018-03-27 16:09:30 UTC
I'm working on switching to LLVM's lld linker as the FreeBSD system linker (/usr/bin/ld)[1], and the port in this PR is reported as a new failure in the exp-run, PR 214864.

An excerpt from the build log[2]:
---
cc -o run.x86-freebsd.so -O2 -pipe  -m32 -fstack-protector -fno-strict-aliasing -shared main.o c-libraries.o unix-raise-syserr.o ml-options.o  boot.o load-ml.o run-ml.o globals.o ml-state.o  error.o timers.o unix-timers.o  qualify-name.o swap-bytes.o  unix-fault.o signal-util.o unix-signal.o unix-prof.o prim.o     ../c-libs/posix-os/libposix-os.a  ../c-libs/smlnj-runtime/libsmlnj-runt.a  ../c-libs/smlnj-signals/libsmlnj-sig.a  ../c-libs/smlnj-prof/libsmlnj-prof.a  ../c-libs/smlnj-sockets/libsmlnj-sock.a  ../c-libs/smlnj-time/libsmlnj-time.a  ../c-libs/smlnj-date/libsmlnj-date.a  ../c-libs/smlnj-math/libsmlnj-math.a  ../c-libs/posix-process/libposix-process.a  ../c-libs/posix-procenv/libposix-procenv.a  ../c-libs/posix-filesys/libposix-filesys.a  ../c-libs/posix-io/libposix-io.a  ../c-libs/posix-sysdb/libposix-sysdb.a  ../c-libs/posix-signal/libposix-signal.a  ../c-libs/posix-tty/libposix-tty.a  ../c-libs/posix-error/libposix-error.a ../gc/libgc.a  ../memory/libmem.a ../c-libs/dl/libunix-dynload.a  -lm
/usr/bin/ld: error: can't create dynamic relocation R_386_32 against symbol: __stderrp in readonly segment; recompile object files with -fPIC
>>> defined in /usr/lib32/libc.so.7
>>> referenced by main.c
>>>               main.o:(main)

/usr/bin/ld: error: can't create dynamic relocation R_386_32 against symbol: DebugF in readonly segment; recompile object files with -fPIC
>>> defined in main.o
>>> referenced by main.c
>>>               main.o:(main)

...


strip: open /wrkdirs/usr/ports/lang/smlnj/work/stage/usr/local/smlnj/bin/.run/run.x86-freebsd.so failed: No such file or directory
---

FreeBSD 11 and later have lld available as /usr/bin/ld.lld, so one simple option for testing is to just symlink /usr/bin/ld to ld.lld (and restore it to ld.bfd).

A port Makefile knob, LLD_UNSAFE=yes, exists to indicate that a port does not work with lld, and requires either /usr/bin/ld.bfd or binutils from ports. This should work for the common case of ports written in C using GNU autoconf; it may have no effect on other ports.

[1] https://lists.freebsd.org/pipermail/freebsd-current/2018-March/068985.html
[2] http://package18.nyi.freebsd.org/data/headamd64PR214864-default/2018-03-21_17h43m11s/logs/errors/smlnj-110.77.log
Comment 1 Ed Maste freebsd_committer freebsd_triage 2018-03-27 20:48:38 UTC
Via tobik@ in ports r465725, BINARY_ALIAS=ld=ld.bfd may be an effective workaround if LLD_UNSAFE does not work.
Comment 2 commit-hook freebsd_committer freebsd_triage 2018-03-29 10:33:32 UTC
A commit references this bug:

Author: krion
Date: Thu Mar 29 10:33:01 UTC 2018
New revision: 465878
URL: https://svnweb.freebsd.org/changeset/ports/465878

Log:
  Switch to ld.bfd by default as ld.ldd doesn't have built-in default
  output target.

  PR:		226991
  Submitted by:	emaste
  Approved by:	portmgr (LLD_UNSAFE blanket)

Changes:
  head/lang/smlnj/Makefile
Comment 3 Ed Maste freebsd_committer freebsd_triage 2018-05-31 13:51:17 UTC
Reopen as exp-run reported lang/smlnj still failing.

strip: open /wrkdirs/usr/ports/lang/smlnj/work/stage/usr/local/smlnj/bin/.run/run.x86-freebsd.so failed: No such file or directory
Comment 4 commit-hook freebsd_committer freebsd_triage 2018-07-20 11:03:16 UTC
A commit references this bug:

Author: tobik
Date: Fri Jul 20 11:02:47 UTC 2018
New revision: 475003
URL: https://svnweb.freebsd.org/changeset/ports/475003

Log:
  lang/smlnj: Respect LDFLAGS and let LLD_UNSAFE actually work

  It currently still tries to use lld.

  /usr/bin/ld: error: can't create dynamic relocation R_386_32 against symbol: __stderrp in readonly segment; recompile object files with -fPIC
  >>> defined in /usr/lib32/libc.so.7
  >>> referenced by main.c
  >>>               main.o:(main)

  /usr/bin/ld: error: can't create dynamic relocation R_386_32 against symbol: DebugF in readonly segment; recompile object files with -fPIC
  >>> defined in main.o
  >>> referenced by main.c
  >>>               main.o:(main)

  http://beefy12.nyi.freebsd.org/data/head-amd64-default/p474314_s336154/logs/smlnj-110.77.log

  PR:		226991
  Reported by:	emaste, pkg-fallout

Changes:
  head/lang/smlnj/Makefile
  head/lang/smlnj/files/do-patch-base_runtime_objs_mk.x86-freebsd
  head/lang/smlnj/files/patch-config_install.sh
Comment 5 Tobias Kortkamp freebsd_committer freebsd_triage 2018-07-20 11:03:58 UTC
Should be fixed now.