Bug 230210

Summary: archivers/p7zip: fail to link with lld as /usr/bin/ld on i386
Product: Ports & Packages Reporter: Ed Maste <emaste>
Component: Individual Port(s)Assignee: Mateusz Piotrowski <0mp>
Status: Closed FIXED    
Severity: Affects Only Me CC: 0mp, mmokhi, ndowens04
Priority: --- Flags: mmokhi: maintainer-feedback+
Version: Latest   
Hardware: i386   
OS: Any   
URL: https://reviews.freebsd.org/D16813
See Also: https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=214864

Description Ed Maste freebsd_committer freebsd_triage 2018-07-30 23:52:46 UTC
The migration to the LLVM project's lld linker as the system linker (/usr/bin/ld) for FreeBSD is in progress - it is the case for arm64 and amd64 today, and i386 will switch once ports issues are addressed - see exp-run in PR214864.

Linking archivers/p7zip with lld as /usr/bin/ld on i386 produces errors of the form:
/usr/bin/ld: error: can't create dynamic relocation R_386_PC32 against symbol: memcpy in readonly segment; recompile object files with -fPIC
>>> defined in /lib/libc.so.7
>>> referenced by 7zBuf2.c
>>>               7zBuf2.o:(DynBuf_Write)

http://package18.nyi.freebsd.org/data/headi386PR214864-default/2018-07-30_18h09m59s/logs/errors/p7zip-16.02_1.log
Comment 1 commit-hook freebsd_committer freebsd_triage 2018-08-26 11:12:02 UTC
A commit references this bug:

Author: mmokhi
Date: Sun Aug 26 11:11:02 UTC 2018
New revision: 478120
URL: https://svnweb.freebsd.org/changeset/ports/478120

Log:
  archivers/p7zip: Fix build with lld as /usr/bin/ld on i386

  PR:		230210
  Reported by:	emaste
  Reviewed by:	mat, rakuco, tobik
  Approved by:	rakuco (maintainer)
  Sponsored by:	The FreeBSD Foundation
  Differential Revision:	https://reviews.freebsd.org/D16813

Changes:
  head/archivers/p7zip/Makefile
Comment 2 Nathan 2018-09-13 11:40:38 UTC
This bug looks like it may could be closed but looking at the Makefile why not have just CFLAGS=-fPIC instead of multiple CFLAGS_arch
Comment 3 Mahdi Mokhtari freebsd_committer freebsd_triage 2018-09-13 12:52:45 UTC
(In reply to Nathan from comment #2)
The reason I haven't closed it, was to wait for a feedback on MFH...
About your point on different arches, I wanted to make my changes as smallest as possible so the maintainer takes less time for review and fix to land quicker...
But also, personally I think having different arches with different flags (like what we have now) is better to have more control on different builds because the LLD thing is landing on different arches on different times I guess...
Comment 4 Ed Maste freebsd_committer freebsd_triage 2018-09-13 13:20:39 UTC
The intent is that on all architectures we will have either lld or use an out-of-tree toolchain (i.e., GNU BFD ld 2.17.50 will not be used anywhere), but this is for FreeBSD 13.0.

Generally speaking if -fPIC fixes lld linking on i386 it's most likely a bug in the port, and it may be that it happens to work "by accident" on other architectures. That said, -fPIC can result in a small perf reduction, and should generally be applied only to libraries, so if the port's build infrastructure builds both binaries and libraries with the same CFLAGS then it might be applied more broadly than desired.

As with mmokhi's comment I've tried to limit the scope of LLD workarounds to only those cases where we actually observed breakage, but if someone investigates a port failure and determines that the build should actually have -fPIC it's better to really fix it.
Comment 5 Ed Maste freebsd_committer freebsd_triage 2019-07-24 19:29:21 UTC
lld enabled as system linker for i386 on stable/12 in advance of 12.1
Comment 6 Ed Maste freebsd_committer freebsd_triage 2020-05-26 01:19:53 UTC
It looks like p7zip now builds without LDFLAGS_i386, presumably due to the addition of -fPIC. IMO the LDFLAGS_i386 can be removed.
Comment 7 Mateusz Piotrowski freebsd_committer freebsd_triage 2020-10-03 14:58:53 UTC
I'm testing the port now.
Comment 8 commit-hook freebsd_committer freebsd_triage 2020-10-03 15:09:16 UTC
A commit references this bug:

Author: 0mp
Date: Sat Oct  3 15:08:33 UTC 2020
New revision: 551317
URL: https://svnweb.freebsd.org/changeset/ports/551317

Log:
  Remove unnecessary LDFLAGS_i386

  archivers/p7zip* ports build just fine without those flags.

  PR:		230210
  Reported by:	emaste
  Approved by:	portmgr blanket

Changes:
  head/archivers/p7zip/Makefile
  head/archivers/p7zip-codec-rar/Makefile