git: 092c4b37c180 - main - Mk/Uses: Add elfctl

From: Joseph Mingrone <jrm_at_FreeBSD.org>
Date: Fri, 18 Feb 2022 18:15:23 UTC
The branch main has been updated by jrm:

URL: https://cgit.FreeBSD.org/ports/commit/?id=092c4b37c1802b46f3c54244e5880d4bf7515c0b

commit 092c4b37c1802b46f3c54244e5880d4bf7515c0b
Author:     Joseph Mingrone <jrm@FreeBSD.org>
AuthorDate: 2022-01-31 23:11:26 +0000
Commit:     Joseph Mingrone <jrm@FreeBSD.org>
CommitDate: 2022-02-18 18:15:08 +0000

    Mk/Uses: Add elfctl
    
    Add USES=elfctl to change an ELF binary's feature control note.
    
    Example:
    
    USES=           elfctl
    ELF_FEATURES=   +noaslr,wxneeded:foo
    
    Reported by:    emaste
    Approved by:    brooks, tcberner (portmgr)
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D34125
---
 Mk/Uses/elfctl.mk  | 27 +++++++++++++++++++++++++++
 Mk/bsd.commands.mk |  1 +
 2 files changed, 28 insertions(+)

diff --git a/Mk/Uses/elfctl.mk b/Mk/Uses/elfctl.mk
new file mode 100644
index 000000000000..442f13db596f
--- /dev/null
+++ b/Mk/Uses/elfctl.mk
@@ -0,0 +1,27 @@
+# Change an ELF binary's feature control note
+#
+# Feature:	elfctl
+# Usage:	USES=elfctl
+# Valid ARGS:	none
+#
+# Variables
+#
+#   ELF_FEATURES=	featurelist:path/to/file1 \
+#			featurelist:path/to/file1 \
+			featurelist:path/to/file2
+#
+# The file paths listed in ELF_FEATURES are relative to ${BUILD_WRKSRC}.
+#
+
+.if !defined(_INCLUDE_USES_ELFCTL_MK)
+_INCLUDE_USES_ELFCTL_MK=	yes
+
+.  if ! empty(ELF_FEATURES)
+_USES_build+=	720:elfctl-post-build
+elfctl-post-build:
+.    for feat in ${ELF_FEATURES}
+	${ELFCTL} -i -e ${feat:C/:.*//} ${BUILD_WRKSRC}/${feat:C/.*://}
+.    endfor
+.  endif
+
+.endif
diff --git a/Mk/bsd.commands.mk b/Mk/bsd.commands.mk
index 620c62eb1533..221a04e4b8f2 100644
--- a/Mk/bsd.commands.mk
+++ b/Mk/bsd.commands.mk
@@ -34,6 +34,7 @@ DIALOG4PORTS?=		${LOCALBASE}/bin/dialog4ports
 DIFF?=			/usr/bin/diff
 DIRNAME?=		/usr/bin/dirname
 EGREP?=			/usr/bin/egrep
+ELFCTL?=		/usr/bin/elfctl
 EXPR?=			/bin/expr
 FALSE?=			false	# Shell builtin
 FILE?=			/usr/bin/file