Bug 224673 - misc/seabios: fails to link with lld as /usr/bin/ld and does honour LD env variable override
Summary: misc/seabios: fails to link with lld as /usr/bin/ld and does honour LD env va...
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: Roger Pau Monné
Depends on:
Blocks: 214864
  Show dependency treegraph
Reported: 2017-12-29 14:53 UTC by Ed Maste
Modified: 2021-09-13 07:22 UTC (History)
1 user (show)

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

Conditionally set tools path (561 bytes, patch)
2017-12-29 17:28 UTC, Roger Pau Monné
no flags Details | Diff
Force GNU ld usage (787 bytes, application/mbox)
2018-03-23 18:38 UTC, Roger Pau Monné
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Ed Maste freebsd_committer 2017-12-29 14:53:59 UTC
When lld is /usr/bin/ld (WITH_LLD_IS_LD in src.conf) seabios fails to build due to a test for an old binutils ld issue:

The version of LD on this system (ld) does not properly handle
alignments.  As a result, this project can not be built.

The problem may be the result of this LD bug report:

Please update to a working version of binutils and retry.

Normally we can use LLD_UNSAFE=yes in the ports Makefile which sets LD=ld.bfd and adds -fuse-ld=bfd to LDFLAGS, but seabios's Makefile doesn't honour LD set from the environment because it overrides it with:


FWIW lld also fails to link the test case, but I suspect the failure is not the same as the old binutils issue. I do not know if lld can successfully link seabios. lld's error (from the invocation in scripts/test-build.sh) is:

ld.lld: error: tmp/tmp_testcompile1.lds:4: unable to move location counter backward for: .mysection
Comment 1 Roger Pau Monné freebsd_committer 2017-12-29 16:16:09 UTC
Sabios already requires Gcc in order to compile, so I would just set USE_BINUTILS=yes to force it to use GNU ld.
Comment 2 Ed Maste freebsd_committer 2017-12-29 16:58:26 UTC
It fails with MAKE_BINUTILS as well, for the same reason; seabios ignores any attempt to specify the linker and just uses ld found in $PATH.
Comment 3 Roger Pau Monné freebsd_committer 2017-12-29 17:28:37 UTC
Created attachment 189198 [details]
Conditionally set tools path

I think something like this should work in order to pick the variables defined in the environment. I can send this upstream if it solves our issues.
Comment 4 Ed Maste freebsd_committer 2017-12-29 17:44:21 UTC
seabios builds for me with that patch, with lld as /usr/bin/ld and LLD_UNSAFE=yes in the port's Makefile
Comment 5 Roger Pau Monné freebsd_committer 2018-03-23 18:38:41 UTC
Created attachment 191758 [details]
Force GNU ld usage
Comment 6 Ed Maste freebsd_committer 2018-03-27 20:43:37 UTC
Via tobik@ in ports r465725, BINARY_ALIAS=ld=ld.bfd may be an effective workaround if LLD_UNSAFE does not work.
Comment 7 Roger Pau Monné freebsd_committer 2018-03-28 07:17:48 UTC
Oh, so it's better to use LLD_UNSAFE rather than USE_BINUTILS and setting LD?

I thought the proposed approach was better because it's exactly the same that SeaBIOS already uses in order to compile with GCC (USE_GCC and pass HOSTCC=... in the make rune).
Comment 8 Ed Maste freebsd_committer 2018-04-02 14:57:50 UTC
> Oh, so it's better to use LLD_UNSAFE rather than USE_BINUTILS and setting LD?

Either approach should work; I just went through all "failing with lld as /usr/bin/ld" PRs that were still open and added this info as a possible workaround in case other approaches weren't working.

I think your argument for the approach in your patch is fine and as the maintainer you should choose anyhow :-)
Comment 9 Roger Pau Monné freebsd_committer 2018-04-05 13:37:21 UTC
Should be fixed by r466430.
Comment 10 Fangrui Song 2021-08-17 05:23:49 UTC
FWIW I have a patch series in 2020-04 to make seabios linkable with ld.lld
 https://mail.coreboot.org/hyperkitty/list/seabios@seabios.org/thread/KBHQU4OLW2THG5Q5F5X7EWTQDJHKNVYC/ ([PATCH v3 0/5] Make seabios linkable with lld)

It got stuck and my ~9 pings were in vain. Perhaps someone else needs to express interests to push it forward.
Comment 11 Roger Pau Monné freebsd_committer 2021-09-13 07:22:19 UTC
(In reply to Fangrui Song from comment #10)
I'm not involved in SeaBIOS development except for some odd fixes to get it to build.

There have been some discussion about the series, which then stalled AFAICT. Maybe you can try to resend and add some more description to patch #3 to address Kevin concerns?