2017-06-22 21:03:20 +00:00
|
|
|
|
|
|
|
# Setup variables for the linker.
|
|
|
|
#
|
|
|
|
# LINKER_TYPE is the major type of linker. Currently binutils and lld support
|
|
|
|
# automatic detection.
|
|
|
|
#
|
|
|
|
# LINKER_VERSION is a numeric constant equal to:
|
|
|
|
# major * 10000 + minor * 100 + tiny
|
|
|
|
# It too can be overridden on the command line.
|
|
|
|
#
|
2017-06-23 17:21:37 +00:00
|
|
|
# LINKER_FEATURES may contain one or more of the following, based on
|
|
|
|
# linker support for that feature:
|
|
|
|
#
|
2018-02-07 14:50:06 +00:00
|
|
|
# - build-id: support for generating a Build-ID note
|
|
|
|
# - retpoline: support for generating PLT with retpoline speculative
|
|
|
|
# execution vulnerability mitigation
|
2017-06-23 17:21:37 +00:00
|
|
|
#
|
2018-06-20 16:10:14 +00:00
|
|
|
# LINKER_FREEBSD_VERSION is the linker's internal source version.
|
|
|
|
#
|
2017-06-22 21:03:24 +00:00
|
|
|
# These variables with an X_ prefix will also be provided if XLD is set.
|
|
|
|
#
|
2017-06-22 21:03:20 +00:00
|
|
|
# This file may be included multiple times, but only has effect the first time.
|
|
|
|
#
|
|
|
|
|
|
|
|
.if !target(__<bsd.linker.mk>__)
|
|
|
|
__<bsd.linker.mk>__:
|
|
|
|
|
2018-10-23 06:31:25 +00:00
|
|
|
_ld_vars=LD $${_empty_var_}
|
|
|
|
.if !empty(_WANT_TOOLCHAIN_CROSS_VARS)
|
|
|
|
# Only the toplevel makefile needs to compute the X_LINKER_* variables.
|
|
|
|
_ld_vars+=XLD X_
|
|
|
|
.endif
|
|
|
|
|
|
|
|
.for ld X_ in ${_ld_vars}
|
2017-06-22 21:03:24 +00:00
|
|
|
.if ${ld} == "LD" || !empty(XLD)
|
2017-06-22 21:03:27 +00:00
|
|
|
# Try to import LINKER_TYPE and LINKER_VERSION from parent make.
|
|
|
|
# The value is only used/exported for the same environment that impacts
|
|
|
|
# LD and LINKER_* settings here.
|
2018-06-20 16:10:14 +00:00
|
|
|
_exported_vars= ${X_}LINKER_TYPE ${X_}LINKER_VERSION ${X_}LINKER_FEATURES \
|
|
|
|
${X_}LINKER_FREEBSD_VERSION
|
2017-06-22 21:03:27 +00:00
|
|
|
${X_}_ld_hash= ${${ld}}${MACHINE}${PATH}
|
|
|
|
${X_}_ld_hash:= ${${X_}_ld_hash:hash}
|
2020-08-26 10:21:38 +00:00
|
|
|
# Only import if none of the vars are set differently somehow else.
|
2017-06-22 21:03:27 +00:00
|
|
|
_can_export= yes
|
|
|
|
.for var in ${_exported_vars}
|
2020-08-26 10:21:38 +00:00
|
|
|
.if defined(${var}) && (!defined(${var}__${${X_}_ld_hash}) || ${${var}__${${X_}_ld_hash}} != ${${var}})
|
|
|
|
.if defined(${var}__${${X_}_ld_hash})
|
2022-02-04 23:59:00 +00:00
|
|
|
.info Cannot import ${X_}LINKER variables since cached ${var} is different: ${${var}__${${X_}_ld_hash}} != ${${var}}
|
2020-08-26 10:21:38 +00:00
|
|
|
.endif
|
2017-06-22 21:03:27 +00:00
|
|
|
_can_export= no
|
|
|
|
.endif
|
|
|
|
.endfor
|
|
|
|
.if ${_can_export} == yes
|
|
|
|
.for var in ${_exported_vars}
|
2019-11-15 16:43:36 +00:00
|
|
|
.if defined(${var}__${${X_}_ld_hash})
|
|
|
|
${var}= ${${var}__${${X_}_ld_hash}}
|
2017-06-22 21:03:27 +00:00
|
|
|
.endif
|
|
|
|
.endfor
|
|
|
|
.endif
|
|
|
|
|
2017-06-22 21:03:24 +00:00
|
|
|
.if ${ld} == "LD" || (${ld} == "XLD" && ${XLD} != ${LD})
|
2017-06-22 22:53:07 +00:00
|
|
|
.if !defined(${X_}LINKER_TYPE) || !defined(${X_}LINKER_VERSION)
|
2020-08-13 14:14:51 +00:00
|
|
|
_ld_version!= (${${ld}} -v 2>&1 || echo none) | sed -n 1p
|
2017-06-22 21:03:20 +00:00
|
|
|
.if ${_ld_version} == "none"
|
2017-06-30 16:34:17 +00:00
|
|
|
.warning Unable to determine linker type from ${ld}=${${ld}}
|
2017-06-22 21:03:20 +00:00
|
|
|
.endif
|
|
|
|
.if ${_ld_version:[1..2]} == "GNU ld"
|
2017-06-23 03:55:00 +00:00
|
|
|
${X_}LINKER_TYPE= bfd
|
2018-06-20 16:10:14 +00:00
|
|
|
${X_}LINKER_FREEBSD_VERSION= 0
|
2020-02-07 19:04:27 +00:00
|
|
|
_v= ${_ld_version:M[1-9]*.[0-9]*:[1]}
|
2021-07-20 15:04:56 +00:00
|
|
|
.elif ${_ld_version:MLLD}
|
|
|
|
# Strip any leading PACKAGE_VENDOR string (e.g. "Homebrew")
|
|
|
|
_ld_version:=${_ld_version:[*]:C/^.* LLD /LLD /:[@]}
|
2017-06-22 21:03:24 +00:00
|
|
|
${X_}LINKER_TYPE= lld
|
2017-06-22 21:03:20 +00:00
|
|
|
_v= ${_ld_version:[2]}
|
2020-02-15 14:53:26 +00:00
|
|
|
.if ${_ld_version:[3]} == "(FreeBSD"
|
2020-02-24 19:11:52 +00:00
|
|
|
${X_}LINKER_FREEBSD_VERSION:= ${_ld_version:[4]:C/.*-([^-]*)\)/\1/}
|
2020-02-15 14:53:26 +00:00
|
|
|
.else
|
|
|
|
${X_}LINKER_FREEBSD_VERSION= 0
|
|
|
|
.endif
|
2023-07-24 00:34:17 +00:00
|
|
|
.elif ${_ld_version:[1]:S/-classic$//} == "@(\#)PROGRAM:ld"
|
2020-08-13 14:14:51 +00:00
|
|
|
# bootstrap linker on MacOS
|
|
|
|
${X_}LINKER_TYPE= mac
|
2023-07-24 00:50:55 +00:00
|
|
|
_v= ${_ld_version:[2]:C/PROJECT:(ld64|dyld)-//}
|
2020-08-13 14:14:51 +00:00
|
|
|
# Convert version 409.12 to 409.12.0 so that the echo + awk below works
|
|
|
|
.if empty(_v:M[1-9]*.[0-9]*.[0-9]*) && !empty(_v:M[1-9]*.[0-9]*)
|
|
|
|
_v:=${_v}.0
|
|
|
|
.else
|
|
|
|
# Some versions do not contain a minor version so we need to append .0.0 there
|
|
|
|
_v:=${_v}.0.0
|
|
|
|
.endif
|
2017-06-22 21:03:20 +00:00
|
|
|
.else
|
2017-06-30 16:34:17 +00:00
|
|
|
.warning Unknown linker from ${ld}=${${ld}}: ${_ld_version}, defaulting to bfd
|
|
|
|
${X_}LINKER_TYPE= bfd
|
|
|
|
_v= 2.17.50
|
2017-06-22 21:03:20 +00:00
|
|
|
.endif
|
2020-02-07 19:04:27 +00:00
|
|
|
${X_}LINKER_VERSION!= echo "${_v:M[1-9]*.[0-9]*}" | \
|
2017-06-22 21:03:24 +00:00
|
|
|
awk -F. '{print $$1 * 10000 + $$2 * 100 + $$3;}'
|
|
|
|
.undef _ld_version
|
|
|
|
.undef _v
|
2017-06-23 17:21:37 +00:00
|
|
|
${X_}LINKER_FEATURES=
|
|
|
|
.if ${${X_}LINKER_TYPE} != "bfd" || ${${X_}LINKER_VERSION} > 21750
|
|
|
|
${X_}LINKER_FEATURES+= build-id
|
2018-05-10 20:10:02 +00:00
|
|
|
${X_}LINKER_FEATURES+= ifunc
|
2017-06-23 17:21:37 +00:00
|
|
|
.endif
|
2019-12-05 19:37:30 +00:00
|
|
|
.if ${${X_}LINKER_TYPE} == "bfd" && ${${X_}LINKER_VERSION} > 21750
|
|
|
|
${X_}LINKER_FEATURES+= riscv-relaxations
|
|
|
|
.endif
|
2018-02-07 14:50:06 +00:00
|
|
|
.if ${${X_}LINKER_TYPE} == "lld" && ${${X_}LINKER_VERSION} >= 60000
|
|
|
|
${X_}LINKER_FEATURES+= retpoline
|
|
|
|
.endif
|
2020-08-11 16:47:00 +00:00
|
|
|
.if ${${X_}LINKER_TYPE} == "lld" && ${${X_}LINKER_VERSION} >= 90000
|
|
|
|
${X_}LINKER_FEATURES+= ifunc-noplt
|
|
|
|
.endif
|
2017-06-22 22:53:07 +00:00
|
|
|
.endif
|
2017-06-22 22:53:10 +00:00
|
|
|
.else
|
|
|
|
# Use LD's values
|
|
|
|
X_LINKER_TYPE= ${LINKER_TYPE}
|
|
|
|
X_LINKER_VERSION= ${LINKER_VERSION}
|
2017-06-23 17:21:37 +00:00
|
|
|
X_LINKER_FEATURES= ${LINKER_FEATURES}
|
2018-06-20 16:10:14 +00:00
|
|
|
X_LINKER_FREEBSD_VERSION= ${LINKER_FREEBSD_VERSION}
|
2017-06-22 21:03:24 +00:00
|
|
|
.endif # ${ld} == "LD" || (${ld} == "XLD" && ${XLD} != ${LD})
|
|
|
|
|
2017-06-22 21:03:27 +00:00
|
|
|
# Export the values so sub-makes don't have to look them up again, using the
|
|
|
|
# hash key computed above.
|
|
|
|
.for var in ${_exported_vars}
|
2019-11-15 16:43:36 +00:00
|
|
|
${var}__${${X_}_ld_hash}:= ${${var}}
|
|
|
|
.export-env ${var}__${${X_}_ld_hash}
|
|
|
|
.undef ${var}__${${X_}_ld_hash}
|
2017-06-22 21:03:27 +00:00
|
|
|
.endfor
|
|
|
|
|
2017-06-22 21:03:24 +00:00
|
|
|
.endif # ${ld} == "LD" || !empty(XLD)
|
|
|
|
.endfor # .for ld in LD XLD
|
|
|
|
|
2017-06-22 21:03:20 +00:00
|
|
|
|
|
|
|
.endif # !target(__<bsd.linker.mk>__)
|