summaryrefslogtreecommitdiffstats
path: root/contrib/elftoolchain
diff options
context:
space:
mode:
authoremaste <emaste@FreeBSD.org>2017-05-03 02:25:11 +0000
committeremaste <emaste@FreeBSD.org>2017-05-03 02:25:11 +0000
commit8455ba0f9806cbf0f1f72a15f9bca48855bfb775 (patch)
treef5d340da3d548dec29d733975a830307c7f55fba /contrib/elftoolchain
parent4d40019791ca3c1c38a469e82d1c36d6e74ac917 (diff)
downloadFreeBSD-src-8455ba0f9806cbf0f1f72a15f9bca48855bfb775.zip
FreeBSD-src-8455ba0f9806cbf0f1f72a15f9bca48855bfb775.tar.gz
MFC r307808: elfcopy: select mode by the end of the program name
The mode of operation (elfcopy, mcs, or strip) is chosen based on the program name. Broaden this to allow a substring match at the end of the name to allow prefixes - for example, bsdstrip or aarch64-freebsd-strip. This improves use of these tools as drop-in replacements for GNU objcopy and strip, which are often built with a limited set of supported targets and installed with a target prefix for cross tools.
Diffstat (limited to 'contrib/elftoolchain')
-rw-r--r--contrib/elftoolchain/elfcopy/main.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/contrib/elftoolchain/elfcopy/main.c b/contrib/elftoolchain/elfcopy/main.c
index e8e1875..b85845a 100644
--- a/contrib/elftoolchain/elfcopy/main.c
+++ b/contrib/elftoolchain/elfcopy/main.c
@@ -1536,6 +1536,22 @@ print_version(void)
exit(EXIT_SUCCESS);
}
+/*
+ * Compare the ending of s with end.
+ */
+static int
+strrcmp(const char *s, const char *end)
+{
+ size_t endlen, slen;
+
+ slen = strlen(s);
+ endlen = strlen(end);
+
+ if (slen >= endlen)
+ s += slen - endlen;
+ return (strcmp(s, end));
+}
+
int
main(int argc, char **argv)
{
@@ -1569,12 +1585,16 @@ main(int argc, char **argv)
if ((ecp->progname = ELFTC_GETPROGNAME()) == NULL)
ecp->progname = "elfcopy";
- if (strcmp(ecp->progname, "strip") == 0)
+ if (strrcmp(ecp->progname, "strip") == 0)
strip_main(ecp, argc, argv);
- else if (strcmp(ecp->progname, "mcs") == 0)
+ else if (strrcmp(ecp->progname, "mcs") == 0)
mcs_main(ecp, argc, argv);
- else
+ else {
+ if (strrcmp(ecp->progname, "elfcopy") != 0 &&
+ strrcmp(ecp->progname, "objcopy") != 0)
+ warnx("program mode not known, defaulting to elfcopy");
elfcopy_main(ecp, argc, argv);
+ }
free_sec_add(ecp);
free_sec_act(ecp);
OpenPOWER on IntegriCloud