History log of /freebsd-current/share/mk/bsd.linker.mk
Revision Date Author Comments
# d0b2dbfa 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

Remove $FreeBSD$: one-line sh pattern

Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/


# 7f9318a0 23-Jul-2023 Jessica Clarke <jrtc27@FreeBSD.org>

bsd.linker.mk: Use :C not :S for regex

Whilst ^ and $ are supported with C, those are special cases, and
general regex syntax like groups and alternations are not. Use the
correct modifier so we get a version number out that's not 0 (which is
what happens when it can't be parsed by the later code).

Fixes: c4177f5b41d4 ("bsd.linker.mk: Handle Xcode 15 linker identification")
MFC after: 1 week


# c4177f5b 23-Jul-2023 Jessica Clarke <jrtc27@FreeBSD.org>

bsd.linker.mk: Handle Xcode 15 linker identification

The upcoming Xcode 15 introduces a new linker (called ld-prime or ld-new
in some documentation) to replace the classic ld64, which we need to
handle.

Previously, the linker would identify itself as:

@(#)PROGRAM:ld PROJECT:ld64-<version>

Now, there are two cases. When the classic ld64 is in use, it identifies
itself as:

@(#)PROGRAM:ld-classic PROJECT:ld64-<version>

When the new linker is in use, it identifies itself as:

@(#)PROGRAM:ld PROJECT:dyld-<version>

Thus, tweak the detection to allow a -classic suffix in the PROGRAM
string and to allow a dyld- prefix instead of an ld64- prefix on the
version number in the PROJECT string.

MFC after: 1 week


# bca92be6 04-Feb-2022 John Baldwin <jhb@FreeBSD.org>

Remove more quotes around Makefile .error/.warn/.info strings.

Reviewed by: imp, emaste
Differential Revision: https://reviews.freebsd.org/D34175


# f8147dad 20-Jul-2021 Alex Richardson <arichardson@FreeBSD.org>

bsd.linker.mk: Detect LLD when built with PACKAGE_VENDOR

Recent versions of homebrew's LLD are built with PACKAGE_VENDOR (since
https://github.com/Homebrew/homebrew-core/commit/e7c972b6062af753e564104e58d1fa20c0d1ad7a).
This means that the -v output is now
`Homebrew LLD 12.0.1 (compatible with GNU linkers)` and bsd.linker.mk no
longer detects it as LLD since it only checks whether the first word is
LLD. This change allow me to build on macOS again and should unbreak the
GitHub actions CI.

Reviewed By: imp, uqs
MFC after: 3 days
Differential Revision: https://reviews.freebsd.org/D31224


# 489377c0 26-Aug-2020 Alex Richardson <arichardson@FreeBSD.org>

Avoid recomputing COMPILER_/LINKER_ variables when set explicitly

I noticed that when we build libraries for a different ABI (in CheriBSD) we
were calling ${XCC}/${LD} --version for every directory. It turns out that
this was caused by bsd.compat.mk explicitly setting (X_)COMPILER variables
for that build stage and this stops the _can_export logic from working.
To fix this, we change the check to only set _can_export=no if the variable
is set and it is set to a different value than the cached value.
This noticeably speeds up the tree walk while building compat libraries.
During an upstream amd64 buildworld this also removes 8 --version calls.

Obtained from: CheriBSD
Reviewed By: brooks, emaste
Differential Revision: https://reviews.freebsd.org/D25986


# 01c4f3a7 13-Aug-2020 Alex Richardson <arichardson@FreeBSD.org>

Make bsd.linker.mk work with the MacOS linker

This is not strictly required for crossbuilding but having lots of warnings
from bsd.linker.mk in the output was making it hard to see the actual
warning messages.

Reviewed By: imp
Differential Revision: https://reviews.freebsd.org/D14318


# 91b31c10 11-Aug-2020 Alex Richardson <arichardson@FreeBSD.org>

Allow linking the kernel with a linker that doesn't support -z ifunc-noplt

This can happen when linking with upstream LLD < 9.0.

Reviewed By: markj
Differential Revision: https://reviews.freebsd.org/D25985


# 9caf7b36 24-Feb-2020 Dimitry Andric <dim@FreeBSD.org>

Adjust the regex used for LINKER_FREEBSD_VERSION so it captures the last
dash-separated segment from the upstream commit description. This is
required to parse "git describe --long" output.


# eb834d9f 19-Feb-2020 Dimitry Andric <dim@FreeBSD.org>

Take LINKER_FREEBSD_VERSION from numerical field after dash

Summary:
With COMPILER_FREEBSD_VERSION, we use a numeric value that we bump each
time we make a change that requires re-bootstrapping, but with the
linker variant, we instead take the entire part after "FreeBSD", as in
this example version output:

LLD 9.0.1 (FreeBSD c1a0a213378a458fbea1a5c77b315c7dce08fd05-1300006) (compatible with GNU linkers)

E.g., LINKER_FREEBSD_VERSION is currently being set to
"c1a0a213378a458fbea1a5c77b315c7dce08fd05-1300006". This means that
*any* new upstream lld version will cause re-bootstrapping.

We should only look at the numerical field we append after a dash
instead. This review attempts to make it so.

The only thing I am not happy about is the post-processing of awk output
in Makefile.inc1. I notice that our awk does not have gensub(), so it
can't substitute a numbered sub-regex with \1, \2, etc. Suggestions
welcome. :)

MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D23691


# c246b393 15-Feb-2020 Dimitry Andric <dim@FreeBSD.org>

Tentatively apply D23691, which takes LINKER_FREEBSD_VERSION from the
numerical field after the dash. This avoids re-bootstrapping of the
linker, when only the git commit hash changes.


# d54b0ffe 07-Feb-2020 Dimitry Andric <dim@FreeBSD.org>

Correctly recognize linker versions greater than 10.0.

MFC after: 3 days


# 0869dceb 05-Dec-2019 John Baldwin <jhb@FreeBSD.org>

Add a new "riscv-relaxations" linker feature.

When the linker doesn't have this feature, add -mno-relax to CFLAGS
on RISC-V.

Define the feature for ld.bfd, but not lld. If lld gains relaxation
support in a newer version, we can enable it for those versions of lld
in bsd.linker.mk.

Reviewed by: mhorne
Sponsored by: DARPA
Differential Revision: https://reviews.freebsd.org/D22659


# dc3c6ad6 15-Nov-2019 Alex Richardson <arichardson@FreeBSD.org>

Use __ as the separator for the exported vars in bsd.compiler/linker.mk

By using '__' instead of '.' as the separator we can also support systems
that use dash as /bin/sh (it's the default shell on Ubuntu/Debian). Dash
will unset any environment variables that use a non alphanumeric+undedscore
character and therefore submakes will fail to import the COMPILER_*
variables if we use '.' as the separator.

Reviewed By: emaste
Differential Revision: https://reviews.freebsd.org/D22381


# 7c807d77 12-Nov-2018 Ed Maste <emaste@FreeBSD.org>

retire LINKER_FEATURES filter flag

And build libdl unconditionally. All supported FreeBSD linkers accept
-F / --filter so there is no need to test for support.

Discussed with: kib
Sponsored by: The FreeBSD Foundation


# 74f65486 23-Oct-2018 Alex Richardson <arichardson@FreeBSD.org>

Only compute the X_COMPILER_*/X_LINKER_* variables when needed

When building CheriBSD we have to set XLD/XCC/XCFLAGS on the command line.
This triggers the $XCC != $CC case in bsd.compiler.mk (and the same for LD
in bsd.linker.mk) which causes it to call ${XCC} --version and
${XLD} --version (plus various awk+sed+echo calls) in every subdirectory.
For incremental builds and stages that only walk the source tree this is
often the majority of the time spent in that directory.

By only computing the value of the X_COMPILER_*/X_LINKER_* variables if
_WANT_TOOLCHAIN_CROSS_VARS is set we can reduce the number of cc/ld calls
to once per build stage instead of once per recursive make.

With this change (and no changes to the sources) the `make includes` stage
now takes 28 seconds at -j1 instead of 86 seconds.

Approved By: brooks (mentor)
Differential Revision: https://reviews.freebsd.org/D17046


# a7d84af8 20-Jun-2018 Bryan Drewery <bdrewery@FreeBSD.org>

Add WITH_SYSTEM_LINKER, on by default, that avoids building lld when possible.

This works similar to WITH_SYSTEM_COMPILER added in r300354. It only
supports lld via WITH_LLD_BOOTSTRAP.

When both SYSTEM_COMPILER and SYSTEM_LINKER logic passes then libclang
will not build in cross-tools. If either check fails though then
libclang is built.

The .info is reworked to notify when libclang will be built since if
either clang or lld needs to be rebuilt, but not the other, the
notification can lead to confusion on why "clang is building".

-fuse-ld= is not used with this method so some combinations of compiler
and linker are expected to fail.

A new 'make test-system-linker' target is added to see the logic results.

Makefile.inc1:
CROSS_BINUTILS_PREFIX support had to be moved higher up so that XLD
could be set and MK_LLD_BOOTSTRAP disabled before checking SYSTEM_LINKER
logic as done with SYSTEM_COMPILER. This also required moving where
bsd.linker.mk was read since XLD needs to be set before parsing it. This
creates a situation where src.opts.mk can not test LINKER_FEATURES or
add LLD_BOOTSTAP to BROKEN_OPTIONS.

Reviewed by: emaste (earlier version)
Sponsored by: Dell EMC
Differential Revision: https://reviews.freebsd.org/D15894


# 7ccdc068 07-Jun-2018 Bryan Drewery <bdrewery@FreeBSD.org>

Use simpler sed invocation.

X-MFC-With: r334791
MFC after: 1 week
Submitted by: danfe


# 1930b98d 07-Jun-2018 Bryan Drewery <bdrewery@FreeBSD.org>

Stop using head(1) which is not available in installworld.

installworld should not be executing this anyhow but there is some
obscure case doing it still. The head(1) binary is not part of
ITOOLS and there's no need to add it.

MFC after: 1 week
Sponsored by: Dell EMC


# ff8f1e83 10-May-2018 Ed Maste <emaste@FreeBSD.org>

Error out on attempt to link amd64 kernel with old binutils linker

As of r333461 we require ifunc support to link a working amd64 kernel.
The default in-tree bootstrap linker is lld and it has the required
support, as does any modern out-of-tree binutils linker. The in-tree
GNU ld is from binutils 2.17.50 and it does not have ifunc support,
so produce an error rather than a broken kernel.

Reviewed by: kib
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D15378


# 48164080 07-Feb-2018 Ed Maste <emaste@FreeBSD.org>

add retpoline compiler and linker feature flags

These features indicate that the compiler and linker support the
retpoline speculative execution vulnerability (CVE-2017-5715)
mitigation.

Reviewed by: dim, imp
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D14228


# 0a808537 24-Jul-2017 Ed Maste <emaste@FreeBSD.org>

lld 5.0 supports filter libraries, so enable linker feature flag

Also switch the logic to enable this for any non-lld linker, since
filter library support is fairly simple and is very likely supported
by any other linker capable of linking the FreeBSD base system.

MFC after: 2 months
MFC with: r321369
Sponsored by: The FreeBSD Foundation


# 99ac8154 10-Jul-2017 Konstantin Belousov <kib@FreeBSD.org>

Provide libdl.

Create libdl.so.1 as a filter for libc.so.7 which exports public dl*
functions. The functions are resolved from the rtld instead, the goal
of creating library is to avoid errors from the static linker due to
missed libdl. For static binaries, an empty .o is compiled into
libdl.a so that static binaries still get dl stubs from libc.a.

Right now lld cannot create filter objects, disable libdl on arm64
when binutils are not used.

Reviewed by: bdrewery, dim (previos version); emaste
Exp run: PR 220525, done by antoine
Sponsored by: The FreeBSD Foundation
MFC after: 1 month
Differential revision: https://reviews.freebsd.org/D11504


# d786d510 30-Jun-2017 Ed Maste <emaste@FreeBSD.org>

bsd.linker.mk: add band-aid for linker invocation failure

In some cases bsd.linker.mk reports an error like:

make[4]: ".../share/mk/bsd.linker.mk" line 56:
Unknown linker from LD=ld -m elf32ppc_fbsd:"

For now change this to a .warning, and then assume GNU ld 2.17.50.
At present the linker type detection is used only for enabling build-id,
and we can carry on without it when type detection fails.

Also, show errors from ${LD} --version to aid in failure diagnosis.
Successful invocations of ${LD} --version produce no output on stderr
so this will not create any spam in non-failing builds.

Tested by: swills
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D11424


# cdd89b98 23-Jun-2017 Ed Maste <emaste@FreeBSD.org>

Introduce LINKER_FEATURES to avoid duplicating version logic

Submitted by: bdrewery
Reported by: kib


# 83cff1f8 22-Jun-2017 Ed Maste <emaste@FreeBSD.org>

change GNU ld LINKER_TYPE from binutils to bfd

GNU binutils includes two linkers: ld.bfd and ld.gold. For clarity use
LINKER_TYPE=bfd to refer to ld.bfd, the original binutils linker that
identifies itself as "GNU ld".

Discussed with: bdrewery


# 6f81bd02 22-Jun-2017 Bryan Drewery <bdrewery@FreeBSD.org>

Provide proper values for X_LINKER_TYPE/VERSION when XLD == LD.

MFC after: 2 weeks
Sponsored by: Dell EMC Isilon


# ec39013e 22-Jun-2017 Bryan Drewery <bdrewery@FreeBSD.org>

Don't overwrite already-set LINKER_VERSION/LINKER_TYPE.

MFC after: 2 weeks
Sponsored by: Dell EMC Isilon


# 89bf31fd 22-Jun-2017 Bryan Drewery <bdrewery@FreeBSD.org>

LINKER_VERSION: Support external binutils.

The ports binutils stores the version in the 5th word so just look for
a version using a pattern instead.

Reported by: rpokala
MFC after: 2 weeks
Sponsored by: Dell EMC Isilon


# 19fad655 22-Jun-2017 Bryan Drewery <bdrewery@FreeBSD.org>

Support cached linker values in environment.

This is similar to r289659 for bsd.compiler.mk.

MFC after: 2 weeks
Reviewed by: emaste
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D11310


# 08154765 22-Jun-2017 Bryan Drewery <bdrewery@FreeBSD.org>

Support XLD for setting X_LINKER_TYPE and X_LINKER_VERSION.

This is similar to r300350 for bsd.compiler.mk.

MFC after: 2 weeks
Reviewed by: emaste
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D11309


# 125902b6 22-Jun-2017 Bryan Drewery <bdrewery@FreeBSD.org>

Add basic bsd.linker.mk auto included from bsd.compiler.mk.

This will provide LINKER_TYPE and LINKER_VERSION.

MFC after: 2 weeks
Reviewed by: emaste
Sponsored by: Dell EMC Isilon
Differential Revision: https://reviews.freebsd.org/D11308