Date: Thu, 29 Mar 2018 12:52:58 +0000 (UTC) From: Ed Maste <emaste@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r331730 - in stable/11: . share/mk sys/conf Message-ID: <201803291252.w2TCqwSu078410@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: emaste Date: Thu Mar 29 12:52:58 2018 New Revision: 331730 URL: https://svnweb.freebsd.org/changeset/base/331730 Log: MFC kernel build-id support MFC r320244, r320245, r320246, r320247, r320248, r320249, r320250 (bdrewery): Add basic bsd.linker.mk auto included from bsd.compiler.mk. This will provide LINKER_TYPE and LINKER_VERSION. Support XLD for setting X_LINKER_TYPE and X_LINKER_VERSION. This is similar to r300350 for bsd.compiler.mk. Support cached linker values in environment. This is similar to r289659 for bsd.compiler.mk. 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. Don't overwrite already-set LINKER_VERSION/LINKER_TYPE. Provide proper values for X_LINKER_TYPE/VERSION when XLD == LD. Pass along LINKER_* vars during installworld and show in test-system-compiler. MFC r320258, r320272, r320275, r320502 (emaste): 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". 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. enable --build-id for the kernel link A Build-ID is an identifier generated at link time to uniquely identify ELF binaries. It allows efficient confirmation that an executable or shared library and a corresponding standalone debuginfo file match. (Otherwise, a checksum of the debuginfo file must be calculated when opening it in a debugger.) The FreeBSD base system includes GNU bfd ld 2.17.50 as the linker for architectures other than arm64. Build-ID support was added to bfd ld shortly after that version, so was not previously available to us. We can now start making use of Build-ID as we migrate to using lld or bfd ld from ports, conditionally enabled based on the LINKER_TYPE and LINKER_VERSION make variables added in r320244 and subsequent commits. Introduce LINKER_FEATURES to avoid duplicating version logic MFC r327857 (bdrewery, submitted by Dan McGregor): Cache LINKER_FEATURES to fix the wrong ones being used. Sponsored by: Dell EMC Isilon Sponsored by: The FreeBSD Foundation Added: stable/11/share/mk/bsd.linker.mk - copied, changed from r320244, head/share/mk/bsd.linker.mk Modified: stable/11/Makefile.inc1 stable/11/share/mk/Makefile stable/11/share/mk/bsd.compiler.mk stable/11/sys/conf/kern.pre.mk stable/11/sys/conf/kmod.mk Directory Properties: stable/11/ (props changed) Modified: stable/11/Makefile.inc1 ============================================================================== --- stable/11/Makefile.inc1 Thu Mar 29 05:01:49 2018 (r331729) +++ stable/11/Makefile.inc1 Thu Mar 29 12:52:58 2018 (r331730) @@ -147,7 +147,8 @@ TEST_SYSTEM_COMPILER_VARS= \ WANT_COMPILER_TYPE WANT_COMPILER_VERSION WANT_COMPILER_VERSION_FILE \ WANT_COMPILER_FREEBSD_VERSION WANT_COMPILER_FREEBSD_VERSION_FILE \ CC COMPILER_TYPE COMPILER_FEATURES COMPILER_VERSION \ - COMPILER_FREEBSD_VERSION + COMPILER_FREEBSD_VERSION \ + LINKER_TYPE LINKER_FEATURES LINKER_VERSION test-system-compiler: .PHONY .for v in ${TEST_SYSTEM_COMPILER_VARS} ${_+_}@printf "%-35s= %s\n" "${v}" "${${v}}" @@ -179,7 +180,10 @@ CROSSENV+= COMPILER_VERSION=${X_COMPILER_VERSION} \ _COMPILER_METADATA_VARS= COMPILER_VERSION \ COMPILER_TYPE \ COMPILER_FEATURES \ - COMPILER_FREEBSD_VERSION + COMPILER_FREEBSD_VERSION \ + LINKER_VERSION \ + LINKER_FEATURES \ + LINKER_TYPE compiler-metadata.mk: .PHONY .META @: > ${.TARGET} @echo ".info Using cached compiler metadata from build at $$(hostname) on $$(date)" \ Modified: stable/11/share/mk/Makefile ============================================================================== --- stable/11/share/mk/Makefile Thu Mar 29 05:01:49 2018 (r331729) +++ stable/11/share/mk/Makefile Thu Mar 29 12:52:58 2018 (r331730) @@ -33,6 +33,7 @@ FILES= \ bsd.kmod.mk \ bsd.lib.mk \ bsd.libnames.mk \ + bsd.linker.mk \ bsd.links.mk \ bsd.man.mk \ bsd.mkopt.mk \ Modified: stable/11/share/mk/bsd.compiler.mk ============================================================================== --- stable/11/share/mk/bsd.compiler.mk Thu Mar 29 05:01:49 2018 (r331729) +++ stable/11/share/mk/bsd.compiler.mk Thu Mar 29 12:52:58 2018 (r331730) @@ -194,4 +194,5 @@ ${var}.${${X_}_cc_hash}:= ${${var}} .endif # ${cc} == "CC" || !empty(XCC) .endfor # .for cc in CC XCC +.include <bsd.linker.mk> .endif # !target(__<bsd.compiler.mk>__) Copied and modified: stable/11/share/mk/bsd.linker.mk (from r320244, head/share/mk/bsd.linker.mk) ============================================================================== --- head/share/mk/bsd.linker.mk Thu Jun 22 21:03:20 2017 (r320244, copy source) +++ stable/11/share/mk/bsd.linker.mk Thu Mar 29 12:52:58 2018 (r331730) @@ -9,25 +9,85 @@ # major * 10000 + minor * 100 + tiny # It too can be overridden on the command line. # +# 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 +# +# These variables with an X_ prefix will also be provided if XLD is set. +# # This file may be included multiple times, but only has effect the first time. # .if !target(__<bsd.linker.mk>__) __<bsd.linker.mk>__: -_ld_version!= ${LD} --version 2>/dev/null | head -n 1 || echo none +.for ld X_ in LD $${_empty_var_} XLD X_ +.if ${ld} == "LD" || !empty(XLD) +# 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. +_exported_vars= ${X_}LINKER_TYPE ${X_}LINKER_VERSION ${X_}LINKER_FEATURES +${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 + +.if ${ld} == "LD" || (${ld} == "XLD" && ${XLD} != ${LD}) +.if !defined(${X_}LINKER_TYPE) || !defined(${X_}LINKER_VERSION) +_ld_version!= (${${ld}} --version || echo none) | head -n 1 .if ${_ld_version} == "none" -.error Unable to determine linker type from LD=${LD} +.warning Unable to determine linker type from ${ld}=${${ld}} .endif .if ${_ld_version:[1..2]} == "GNU ld" -LINKER_TYPE= binutils -_v= ${_ld_version:[3]} +${X_}LINKER_TYPE= bfd +_v= ${_ld_version:M[1-9].[0-9]*:[1]} .elif ${_ld_version:[1]} == "LLD" -LINKER_TYPE= lld +${X_}LINKER_TYPE= lld _v= ${_ld_version:[2]} .else -.error Unknown linker from LD=${LD}: ${_ld_version} +.warning Unknown linker from ${ld}=${${ld}}: ${_ld_version}, defaulting to bfd +${X_}LINKER_TYPE= bfd +_v= 2.17.50 .endif -LINKER_VERSION!=echo "${_v:M[1-9].[0-9]*}" | awk -F. '{print $$1 * 10000 + $$2 * 100 + $$3;}' +${X_}LINKER_VERSION!= echo "${_v:M[1-9].[0-9]*}" | \ + awk -F. '{print $$1 * 10000 + $$2 * 100 + $$3;}' +.undef _ld_version +.undef _v +${X_}LINKER_FEATURES= +.if ${${X_}LINKER_TYPE} != "bfd" || ${${X_}LINKER_VERSION} > 21750 +${X_}LINKER_FEATURES+= build-id +.endif +.endif +.else +# Use LD's values +X_LINKER_TYPE= ${LINKER_TYPE} +X_LINKER_VERSION= ${LINKER_VERSION} +X_LINKER_FEATURES= ${LINKER_FEATURES} +.endif # ${ld} == "LD" || (${ld} == "XLD" && ${XLD} != ${LD}) + +# 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 + +.endif # ${ld} == "LD" || !empty(XLD) +.endfor # .for ld in LD XLD + .endif # !target(__<bsd.linker.mk>__) Modified: stable/11/sys/conf/kern.pre.mk ============================================================================== --- stable/11/sys/conf/kern.pre.mk Thu Mar 29 05:01:49 2018 (r331729) +++ stable/11/sys/conf/kern.pre.mk Thu Mar 29 12:52:58 2018 (r331730) @@ -109,6 +109,10 @@ DEFINED_PROF= ${PROF} # can override the others. CFLAGS+= ${CONF_CFLAGS} +.if ${LINKER_FEATURES:Mbuild-id} +LDFLAGS+= -Wl,--build-id=sha1 +.endif + # Optional linting. This can be overridden in /etc/make.conf. LINTFLAGS= ${LINTOBJKERNFLAGS} Modified: stable/11/sys/conf/kmod.mk ============================================================================== --- stable/11/sys/conf/kmod.mk Thu Mar 29 05:01:49 2018 (r331729) +++ stable/11/sys/conf/kmod.mk Thu Mar 29 12:52:58 2018 (r331730) @@ -125,6 +125,10 @@ CFLAGS.gcc+= --param large-function-growth=1000 CFLAGS+= -fno-common LDFLAGS+= -d -warn-common +.if ${LINKER_FEATURES:Mbuild-id} +LDFLAGS+= -Wl,--build-id=sha1 +.endif + CFLAGS+= ${DEBUG_FLAGS} .if ${MACHINE_CPUARCH} == amd64 CFLAGS+= -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201803291252.w2TCqwSu078410>