git: aaa3d65392f6 - stable/14 - crunchgen: fix "keep" for an ELF world, break it out

From: Kyle Evans <kevans_at_FreeBSD.org>
Date: Sun, 26 Nov 2023 04:07:51 UTC
The branch stable/14 has been updated by kevans:

URL: https://cgit.FreeBSD.org/src/commit/?id=aaa3d65392f6844b9c6ed0a9692c715aaec32adf

commit aaa3d65392f6844b9c6ed0a9692c715aaec32adf
Author:     Kyle Evans <kevans@FreeBSD.org>
AuthorDate: 2023-11-10 04:33:58 +0000
Commit:     Kyle Evans <kevans@FreeBSD.org>
CommitDate: 2023-11-26 04:07:12 +0000

    crunchgen: fix "keep" for an ELF world, break it out
    
    "keep" currently adds a leading underscore, which hasn't been useful or
    accurate since a.out days.  Preserve the symbol name as it's given
    rather than mangle it to match ELF-style symbol names.
    
    This was partially fixed back in
    6cd35234a092d ("Assume ELF-style symbol names now.") for crunchgen, but
    the keeplist wasn't changed to match it.
    
    While we're here, break it out to bsd.crunchgen.mk for later use in
    bsdbox.
    
    Reviewed by:    adrian, imp
    
    (cherry picked from commit 8f2848eafa682f1af629f8ee5e32fec607ab0ba1)
---
 share/mk/bsd.crunchgen.mk             | 4 ++++
 usr.sbin/crunch/crunchgen/crunchgen.c | 2 +-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/share/mk/bsd.crunchgen.mk b/share/mk/bsd.crunchgen.mk
index 182ca387fe2b..bdbb6c5a22b0 100644
--- a/share/mk/bsd.crunchgen.mk
+++ b/share/mk/bsd.crunchgen.mk
@@ -18,6 +18,7 @@
 #  CRUNCH_SRCDIR_${P}: base source directory for program ${P}
 #  CRUNCH_BUILDOPTS_${P}: additional build options for ${P}
 #  CRUNCH_ALIAS_${P}: additional names to be used for ${P}
+#  CRUNCH_KEEP_${P}: additional symbols to keep for ${P}
 #
 # By default, any name appearing in CRUNCH_PROGS or CRUNCH_ALIAS_${P}
 # will be used to generate a hard link to the resulting binary.
@@ -101,6 +102,9 @@ ${CONF}: Makefile
 .ifdef CRUNCH_LIBS_${P}
 	echo special ${P} lib ${CRUNCH_LIBS_${P}} >>${.TARGET}
 .endif
+.ifdef CRUNCH_KEEP_${P}
+	echo special ${P} keep ${CRUNCH_KEEP_${P}} >>${.TARGET}
+.endif
 .for A in ${CRUNCH_ALIAS_${P}}
 	echo ln ${P} ${A} >>${.TARGET}
 .endfor
diff --git a/usr.sbin/crunch/crunchgen/crunchgen.c b/usr.sbin/crunch/crunchgen/crunchgen.c
index dfde38ed0b70..7b5f892cffbe 100644
--- a/usr.sbin/crunch/crunchgen/crunchgen.c
+++ b/usr.sbin/crunch/crunchgen/crunchgen.c
@@ -1128,7 +1128,7 @@ prog_makefile_rules(FILE *outmk, prog_t *p)
 	fprintf(outmk, "\n");
 	fprintf(outmk, "\tcrunchide -k _crunched_%s_stub ", p->ident);
 	for (lst = p->keeplist; lst != NULL; lst = lst->next)
-		fprintf(outmk, "-k _%s ", lst->str);
+		fprintf(outmk, "-k %s ", lst->str);
 	fprintf(outmk, "%s.lo\n", p->name);
 }