Author: emaste
Date: Wed May  3 02:25:11 2017
New Revision: 317720
URL: https://svnweb.freebsd.org/changeset/base/317720

Log:
  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.

Modified:
  stable/11/contrib/elftoolchain/elfcopy/main.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/contrib/elftoolchain/elfcopy/main.c
==============================================================================
--- stable/11/contrib/elftoolchain/elfcopy/main.c       Wed May  3 02:19:45 
2017        (r317719)
+++ stable/11/contrib/elftoolchain/elfcopy/main.c       Wed May  3 02:25:11 
2017        (r317720)
@@ -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);
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to