Author: emaste
Date: Sat Oct 22 23:49:06 2016
New Revision: 307808
URL: https://svnweb.freebsd.org/changeset/base/307808

Log:
  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.
  
  Reviewed by:  dim
  Sponsored by: The FreeBSD Foundation
  Differential Revision:        https://reviews.freebsd.org/D1663

Modified:
  head/contrib/elftoolchain/elfcopy/main.c

Modified: head/contrib/elftoolchain/elfcopy/main.c
==============================================================================
--- head/contrib/elftoolchain/elfcopy/main.c    Sat Oct 22 23:09:06 2016        
(r307807)
+++ head/contrib/elftoolchain/elfcopy/main.c    Sat Oct 22 23:49:06 2016        
(r307808)
@@ -1529,6 +1529,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)
 {
@@ -1562,12 +1578,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);
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "[email protected]"

Reply via email to