2017-06-22 23:03:20 +02:00
|
|
|
# $FreeBSD$
|
|
|
|
|
|
|
|
# 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 19:21:37 +02:00
|
|
|
# LINKER_FEATURES may contain one or more of the following, based on
|
|
|
|
# linker support for that feature:
|
|
|
|
#
|
|
|
|
# - build-id : support for generating a Build-ID note
|
|
|
|
#
|
2017-06-22 23:03:24 +02:00
|
|
|
# These variables with an X_ prefix will also be provided if XLD is set.
|
|
|
|
#
|
2017-06-22 23:03:20 +02:00
|
|
|
# This file may be included multiple times, but only has effect the first time.
|
|
|
|
#
|
|
|
|
|
|
|
|
.if !target(__<bsd.linker.mk>__)
|
|
|
|
__<bsd.linker.mk>__:
|
|
|
|
|
2017-06-22 23:03:24 +02:00
|
|
|
.for ld X_ in LD $${_empty_var_} XLD X_
|
|
|
|
.if ${ld} == "LD" || !empty(XLD)
|
2017-06-22 23:03:27 +02: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.
|
2017-06-23 19:21:37 +02:00
|
|
|
_exported_vars= ${X_}LINKER_TYPE ${X_}LINKER_VERSION ${X_}LINKER_FEATURES
|
2017-06-22 23:03:27 +02:00
|
|
|
${X_}_ld_hash= ${${ld}}${MACHINE}${PATH}
|
|
|
|
${X_}_ld_hash:= ${${X_}_ld_hash:hash}
|
|
|
|
# Only import if none of the vars are set somehow else.
|
|
|
|
_can_export= yes
|
|
|
|
.for var in ${_exported_vars}
|
|
|
|
.if defined(${var})
|
|
|
|
_can_export= no
|
|
|
|
.endif
|
|
|
|
.endfor
|
|
|
|
.if ${_can_export} == yes
|
|
|
|
.for var in ${_exported_vars}
|
|
|
|
.if defined(${var}.${${X_}_ld_hash})
|
|
|
|
${var}= ${${var}.${${X_}_ld_hash}}
|
|
|
|
.endif
|
|
|
|
.endfor
|
|
|
|
.endif
|
|
|
|
|
2017-06-22 23:03:24 +02:00
|
|
|
.if ${ld} == "LD" || (${ld} == "XLD" && ${XLD} != ${LD})
|
2017-06-23 00:53:07 +02:00
|
|
|
.if !defined(${X_}LINKER_TYPE) || !defined(${X_}LINKER_VERSION)
|
2017-06-30 18:34:17 +02:00
|
|
|
_ld_version!= (${${ld}} --version || echo none) | head -n 1
|
2017-06-22 23:03:20 +02:00
|
|
|
.if ${_ld_version} == "none"
|
2017-06-30 18:34:17 +02:00
|
|
|
.warning Unable to determine linker type from ${ld}=${${ld}}
|
2017-06-22 23:03:20 +02:00
|
|
|
.endif
|
|
|
|
.if ${_ld_version:[1..2]} == "GNU ld"
|
2017-06-23 05:55:00 +02:00
|
|
|
${X_}LINKER_TYPE= bfd
|
2017-06-22 23:22:12 +02:00
|
|
|
_v= ${_ld_version:M[1-9].[0-9]*:[1]}
|
2017-06-22 23:03:20 +02:00
|
|
|
.elif ${_ld_version:[1]} == "LLD"
|
2017-06-22 23:03:24 +02:00
|
|
|
${X_}LINKER_TYPE= lld
|
2017-06-22 23:03:20 +02:00
|
|
|
_v= ${_ld_version:[2]}
|
|
|
|
.else
|
2017-06-30 18:34:17 +02:00
|
|
|
.warning Unknown linker from ${ld}=${${ld}}: ${_ld_version}, defaulting to bfd
|
|
|
|
${X_}LINKER_TYPE= bfd
|
|
|
|
_v= 2.17.50
|
2017-06-22 23:03:20 +02:00
|
|
|
.endif
|
2017-06-22 23:03:24 +02:00
|
|
|
${X_}LINKER_VERSION!= echo "${_v:M[1-9].[0-9]*}" | \
|
|
|
|
awk -F. '{print $$1 * 10000 + $$2 * 100 + $$3;}'
|
|
|
|
.undef _ld_version
|
|
|
|
.undef _v
|
2017-06-23 19:21:37 +02:00
|
|
|
${X_}LINKER_FEATURES=
|
|
|
|
.if ${${X_}LINKER_TYPE} != "bfd" || ${${X_}LINKER_VERSION} > 21750
|
|
|
|
${X_}LINKER_FEATURES+= build-id
|
|
|
|
.endif
|
2017-07-24 17:39:09 +02:00
|
|
|
.if ${${X_}LINKER_TYPE} != "lld" || ${${X_}LINKER_VERSION} >= 50000
|
2017-07-10 16:59:21 +02:00
|
|
|
${X_}LINKER_FEATURES+= filter
|
|
|
|
.endif
|
2017-06-23 00:53:07 +02:00
|
|
|
.endif
|
2017-06-23 00:53:10 +02:00
|
|
|
.else
|
|
|
|
# Use LD's values
|
|
|
|
X_LINKER_TYPE= ${LINKER_TYPE}
|
|
|
|
X_LINKER_VERSION= ${LINKER_VERSION}
|
2017-06-23 19:21:37 +02:00
|
|
|
X_LINKER_FEATURES= ${LINKER_FEATURES}
|
2017-06-22 23:03:24 +02:00
|
|
|
.endif # ${ld} == "LD" || (${ld} == "XLD" && ${XLD} != ${LD})
|
|
|
|
|
2017-06-22 23:03:27 +02: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}
|
|
|
|
${var}.${${X_}_ld_hash}:= ${${var}}
|
|
|
|
.export-env ${var}.${${X_}_ld_hash}
|
|
|
|
.undef ${var}.${${X_}_ld_hash}
|
|
|
|
.endfor
|
|
|
|
|
2017-06-22 23:03:24 +02:00
|
|
|
.endif # ${ld} == "LD" || !empty(XLD)
|
|
|
|
.endfor # .for ld in LD XLD
|
|
|
|
|
2017-06-22 23:03:20 +02:00
|
|
|
|
|
|
|
.endif # !target(__<bsd.linker.mk>__)
|