Bug 222172 - lang/fpc: invokes linker directly and does not honour LD env variable override
Summary: lang/fpc: invokes linker directly and does not honour LD env variable override
Status: Closed FIXED
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Ed Maste
URL:
Keywords:
Depends on:
Blocks: 214864
  Show dependency treegraph
 
Reported: 2017-09-09 17:57 UTC by Ed Maste
Modified: 2018-03-29 15:41 UTC (History)
1 user (show)

See Also:
bugzilla: maintainer-feedback? (acm)


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Maste freebsd_committer freebsd_triage 2017-09-09 17:57:07 UTC
I've been investigating building the ports tree with LLVM's lld installed as /usr/bin/ld (via the exp-run in PR 214864). As of today lang/fpc fails when linked with lld, and of those failing it is responsible for the largest number of skipped ports (110).

When linking with lld (with LD=ld.bfd in the environment) the build failed with:

/usr/bin/ld: error: x86_64/units/x86_64-freebsd/i_linux.o: invalid alignment of section headers
pp.pas(247,1) Error: Error while linking
pp.pas(247,1) Fatal: There were 1 errors compiling module, stopping
Fatal: Compilation aborted

I think this may be coming from fpc-3.0.2/compiler/systems/t_bsd.pas from ExeCmd and DllCmd like so:

   149               ExeCmd[1]:='ld $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP -L. -o $EXE $CATRES';
   150               DllCmd[1]:='ld $TARGET $EMUL $OPT -shared -L. -o $EXE $CATRES'

I'll try to have an attempt at a patch.
Comment 1 Ed Maste freebsd_committer freebsd_triage 2017-12-29 14:04:45 UTC
% readelf -h compiler/x86_64/units/x86_64-freebsd/i_linux.o | grep 'section headers'
  Start of section headers:          5997 (bytes into file)
  Size of section headers:           64 (bytes)
  Number of section headers:         18
Comment 2 Ed Maste freebsd_committer freebsd_triage 2017-12-29 17:33:36 UTC
Bug report submitted to fpc for the misaligned section header issue: https://bugs.freepascal.org/view.php?id=32900
Comment 3 Ed Maste freebsd_committer freebsd_triage 2018-03-12 19:30:46 UTC
Misaligned section header issue is now resolved upstream.
Comment 5 Ed Maste freebsd_committer freebsd_triage 2018-03-27 20:23:39 UTC
Via tobik@ in ports r465725, BINARY_ALIAS=ld=ld.bfd may be an effective workaround if LLD_UNSAFE does not work.
Comment 6 Ed Maste freebsd_committer freebsd_triage 2018-03-27 20:28:24 UTC
BINARY_ALIAS=ld=ld.bfd seems to work.
Comment 7 commit-hook freebsd_committer freebsd_triage 2018-03-29 15:40:44 UTC
A commit references this bug:

Author: emaste
Date: Thu Mar 29 15:40:06 UTC 2018
New revision: 465903
URL: https://svnweb.freebsd.org/changeset/ports/465903

Log:
  lang/fpc: Set LLD_UNSAFE

  fpc produces and needs to link an object file with invalid section
  header alignment, which lld refuses to do.  The build fails with:

  /usr/bin/ld: error: x86_64/units/x86_64-freebsd/i_linux.o: \
      invalid alignment of section headers

  Setting LLD_UNSAFE makes the port link with ld.bfd instead.

  PR:		222172
  Approved by:	portmgr (LLD_UNSAFE blanket)
  Sponsored by:	The FreeBSD Foundation

Changes:
  head/lang/fpc/Makefile
Comment 8 Ed Maste freebsd_committer freebsd_triage 2018-03-29 15:41:06 UTC
Workaround committed.