Bug 231459 - security/openssl: fails to link with lld as system linker on i386
Summary: security/openssl: fails to link with lld as system linker on i386
Status: Open
Alias: None
Product: Ports & Packages
Classification: Unclassified
Component: Individual Port(s) (show other bugs)
Version: Latest
Hardware: Any Any
: --- Affects Only Me
Assignee: Bernard Spil
URL:
Keywords:
Depends on:
Blocks: 214864
  Show dependency treegraph
 
Reported: 2018-09-18 17:30 UTC by Ed Maste
Modified: 2019-02-17 19:10 UTC (History)
2 users (show)

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


Attachments
Fix LLD on i386 (731 bytes, patch)
2018-09-18 17:56 UTC, Nathan
no flags Details | Diff
Fix LLD on i386 (549 bytes, patch)
2018-09-18 18:02 UTC, Nathan
no flags Details | Diff
svn diff for security/openssl111 (478 bytes, patch)
2018-09-28 14:09 UTC, Bernard Spil
brnrd: maintainer-approval+
Details | Diff
OpenSSL 1.1 LLD fix (1.29 KB, patch)
2018-09-29 01:07 UTC, Nathan
brnrd: maintainer-approval-
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Maste freebsd_committer 2018-09-18 17:30:46 UTC
/usr/bin/ld: error: unknown argument: -Bforcearchive
cc: error: linker command failed with exit code 1 (use -v to see invocation)

This happens because OpenSSL tries to detect GNU ld with:

./work/openssl-1.0.2p/Makefile.shared:DETECT_GNU_LD=($(CC) -Wl,-V /dev/null 2>&1 | grep '^GNU ld' )>/dev/null

and provides a different link invocation for non-GNU ld, which ends up with the -Bforcearchive flag (which is not supported by GNU ld or lld)

See https://www.sigbus.info/software-compatibility-and-our-own-user-agent-problem.html for some more info.

A patch like this is probably sufficient:

-./work/openssl-1.0.2p/Makefile.shared:DETECT_GNU_LD=($(CC) -Wl,-V /dev/null 2>&1 | grep '^GNU ld' )>/dev/null
+./work/openssl-1.0.2p/Makefile.shared:DETECT_GNU_LD=($(CC) -Wl,-V /dev/null 2>&1 | grep 'GNU' )>/dev/null
Comment 1 Nathan 2018-09-18 17:56:44 UTC
Created attachment 197212 [details]
Fix LLD on i386

Test with/without patch and emaste's suggestion worked; This is the patch with the fix for LLD on i386
Comment 2 Ed Maste freebsd_committer 2018-09-18 17:59:31 UTC
Comment on attachment 197212 [details]
Fix LLD on i386

I'll defer to others for confirmation bust the portrevision bump isn't needed: this does not introduce a change if LLD is not in use, and if it is the port does not build today.

sed expression LGTM
Comment 3 Nathan 2018-09-18 18:00:30 UTC
K I will update the portrevision. Habit of changing if version doesn't change
Comment 4 Nathan 2018-09-18 18:02:02 UTC
Created attachment 197213 [details]
Fix LLD on i386

Un-bump PORTREVISION
Comment 5 Ed Maste freebsd_committer 2018-09-18 18:06:57 UTC
LGTM
Comment 6 Ed Maste freebsd_committer 2018-09-26 13:20:36 UTC
Patch in attachment 197213 [details] works for security/openssl-unsafe
Comment 7 Ed Maste freebsd_committer 2018-09-26 14:48:21 UTC
With this patch (adapted for 2 of them) these successfully built:

openssl
openssl-devel
openssl-unsafe

openssl111 does not have Makefile.shared, the same approach will likely work but a different patch will be necessary
Comment 8 Nathan 2018-09-26 19:29:39 UTC
(In reply to Ed Maste from comment #7)
I’ll take a look ASAP.
Comment 9 Bernard Spil freebsd_committer 2018-09-28 13:57:40 UTC
(In reply to Nathan from comment #8)
Hi Nathan, please let me know when you've verified that this is functional. I have the commits lined up.
Comment 10 Ed Maste freebsd_committer 2018-09-28 14:02:50 UTC
This PR was originally just for security/openssl and I've confirmed the patch is functional there, and that the patch (with trivially adaption) is functional with the other two security/openssl-* ports.

security/openssl111 will need a completely different patch (but the same approach) and can be separate.
Comment 11 Bernard Spil freebsd_committer 2018-09-28 14:09:04 UTC
Created attachment 197571 [details]
svn diff for security/openssl111

Please verify this as well with lld on i386

Same fix, different file/location
Comment 12 Ed Maste freebsd_committer 2018-09-28 15:17:41 UTC
(In reply to Bernard Spil from comment #11)
This fixes the main problem but an additional issue remains when linking with lld:

--- crypto/cryptlib.o ---
cc  -I. -Icrypto/include -Iinclude -fPIC -pthread -Wa,--noexecstack -Qunused-arguments -O2 -pipe  -fstack-protector -fno-strict-aliasing -DL_ENDIAN -DOPENSSL_PIC -DOPENSSL_BN_ASM_PART_WORDS -DOPENSSL_BN_ASM_MONT -DOPENSSL_BN_ASM_GF2m -DSHA1_ASM -DSHA256_ASM -DSHA512_ASM -DRC4_ASM -DMD5_ASM -DRMD160_ASM -DAES_ASM -DGHASH_ASM -DECP_NISTZ256_ASM -DPADLOCK_ASM -DPOLY1305_ASM -DOPENSSLDIR="\"/usr/local/openssl\"" -DENGINESDIR="\"/usr/local/lib/engines-1.1\"" -D_THREAD_SAFE -D_REENTRANT -DNDEBUG  -MMD -MF crypto/cryptlib.d.tmp -MT crypto/cryptlib.o -c -o crypto/cryptlib.o crypto/cryptlib.c

...

--- libcrypto.so ---
/usr/bin/ld: error: can't create dynamic relocation R_386_PC32 against symbol: OPENSSL_ia32cap_P in readonly segment; recompile object files with -fPIC
>>> defined in crypto/cryptlib.o
>>> referenced by crypto/rc4/rc4-586.o:(RC4_set_key)

/usr/bin/ld: error: can't create dynamic relocation R_386_PC32 against symbol: OPENSSL_ia32cap_P in readonly segment; recompile object files with -fPIC
>>> defined in crypto/cryptlib.o
>>> referenced by crypto/rc4/rc4-586.o:(RC4_options)
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** [libcrypto.so] Error code 1

This is a much trickier issue and will take more work. That said, it wouldn't hurt to apply the config change to all four.
Comment 13 Nathan 2018-09-28 16:15:45 UTC
Sorry sorta forgot about trying to fix this one. Been side tracked on attempts of getting a port to build in mips
Comment 14 Nathan 2018-09-29 01:07:21 UTC
Created attachment 197583 [details]
OpenSSL 1.1 LLD fix

This one is for OpenSSL 1.1  Tested inside poudriere with ld.lld replacing ld

Also moved variables around as they are wrong, because nothing should go after OPTIONS IIRC, according to mat
Comment 15 Bernard Spil freebsd_committer 2018-09-30 11:15:41 UTC
Comment on attachment 197583 [details]
OpenSSL 1.1 LLD fix

(In reply to Nathan from comment #14)
Moved the security/openssl111 bits to https://reviews.freebsd.org/D17362
Comment 16 commit-hook freebsd_committer 2018-10-05 09:17:55 UTC
A commit references this bug:

Author: brnrd
Date: Fri Oct  5 09:17:02 UTC 2018
New revision: 481266
URL: https://svnweb.freebsd.org/changeset/ports/481266

Log:
  security/openssl111: Fix linking with lld on i386

   - Fix shared option
   - While here, fix ordering

  PR:		231459
  Submitted by:	Nathan <ndowens yahoo com>
  Reported by:	emaste
  Differential Revision:	https://reviews.freebsd.org/D17362

Changes:
  head/security/openssl111/Makefile
Comment 17 Bernard Spil freebsd_committer 2018-10-05 09:32:13 UTC
Approved by: emaste, ndowens

was missing from commit msg
Comment 18 Ed Maste freebsd_committer 2019-01-11 14:04:54 UTC
Most recent exp-run still showed a failure in security/openssl and security/openssl-unsafe:

http://package18.nyi.freebsd.org/build.html?mastername=headi386PR214864-default&build=2019-01-05_21h00m02s
http://package18.nyi.freebsd.org/data/headi386PR214864-default/2019-01-05_21h00m02s/logs/errors/openssl-1.0.2q,1.log
http://package18.nyi.freebsd.org/data/headi386PR214864-default/2019-01-05_21h00m02s/logs/errors/openssl-unsafe-1.0.2.20170706.log

ld: error: unknown argument: -Bforcearchive
cc: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

Stop.
Comment 19 commit-hook freebsd_committer 2019-02-17 19:10:35 UTC
A commit references this bug:

Author: brnrd
Date: Sun Feb 17 19:09:55 UTC 2019
New revision: 493181
URL: https://svnweb.freebsd.org/changeset/ports/493181

Log:
  security/openssl: Fix build with lld on i386

  PR:		231459
  Submitted by:	Nathan <ndowens@yahoo.com>
  Reported by:	emaste

Changes:
  head/security/openssl/Makefile