Module Name:    src
Committed By:   kamil
Date:           Thu Jun 21 10:55:54 UTC 2018

Modified Files:
        src/usr.bin/crunch/crunchgen: crunchgen.1 crunchgen.c

Log Message:
Add new option -s to crunchgen(1) -- enable sanitization

As of today typical sanitizers require dynamic executables, while
crunchgen(1) programs are produced with static properties.

Lack of specified -s will:
 - generate a Makefile file with NOSANITIZER=
 - build programs that are dependencies with NOSANITIZER=

In future there is an option to handle sanitization in statically linked
programs.

An idea with -s LGTM by <christos>


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/usr.bin/crunch/crunchgen/crunchgen.1
cvs rdiff -u -r1.86 -r1.87 src/usr.bin/crunch/crunchgen/crunchgen.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/crunch/crunchgen/crunchgen.1
diff -u src/usr.bin/crunch/crunchgen/crunchgen.1:1.34 src/usr.bin/crunch/crunchgen/crunchgen.1:1.35
--- src/usr.bin/crunch/crunchgen/crunchgen.1:1.34	Mon Oct  9 10:31:50 2017
+++ src/usr.bin/crunch/crunchgen/crunchgen.1	Thu Jun 21 10:55:54 2018
@@ -1,4 +1,4 @@
-.\"	$NetBSD: crunchgen.1,v 1.34 2017/10/09 10:31:50 wiz Exp $
+.\"	$NetBSD: crunchgen.1,v 1.35 2018/06/21 10:55:54 kamil Exp $
 .\"
 .\" Copyright (c) 1994 University of Maryland
 .\" All Rights Reserved.
@@ -24,7 +24,7 @@
 .\"			   Computer Science Department
 .\"			   University of Maryland at College Park
 .\"
-.Dd May 31, 2017
+.Dd June 21, 2018
 .Dt CRUNCHGEN 1
 .Os
 .Sh NAME
@@ -32,7 +32,7 @@
 .Nd generates build environment for a crunched binary
 .Sh SYNOPSIS
 .Nm
-.Op Fl fOopq
+.Op Fl fOopqs
 .Op Fl c Ar c-file-name
 .Op Fl D Ar src-root
 .Op Fl d Ar build-options
@@ -129,6 +129,8 @@ Produce static pie (position independent
 .It Fl q
 Quiet operation.
 Status messages are suppressed.
+.It Fl s
+Enable sanitization.
 .It Fl v Ar varspec
 Append a variable specification to the on-the fly generated Makefile.
 .El

Index: src/usr.bin/crunch/crunchgen/crunchgen.c
diff -u src/usr.bin/crunch/crunchgen/crunchgen.c:1.86 src/usr.bin/crunch/crunchgen/crunchgen.c:1.87
--- src/usr.bin/crunch/crunchgen/crunchgen.c:1.86	Tue May  8 23:05:17 2018
+++ src/usr.bin/crunch/crunchgen/crunchgen.c	Thu Jun 21 10:55:54 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: crunchgen.c,v 1.86 2018/05/08 23:05:17 mrg Exp $	*/
+/*	$NetBSD: crunchgen.c,v 1.87 2018/06/21 10:55:54 kamil Exp $	*/
 /*
  * Copyright (c) 1994 University of Maryland
  * All Rights Reserved.
@@ -38,7 +38,7 @@
 
 #include <sys/cdefs.h>
 #if !defined(lint)
-__RCSID("$NetBSD: crunchgen.c,v 1.86 2018/05/08 23:05:17 mrg Exp $");
+__RCSID("$NetBSD: crunchgen.c,v 1.87 2018/06/21 10:55:54 kamil Exp $");
 #endif
 
 #include <stdlib.h>
@@ -102,7 +102,7 @@ static int goterror = 0;
 
 static const char *pname = "crunchgen";
 
-static int verbose, readcache, useobjs, oneobj, pie;	/* options */
+static int verbose, readcache, useobjs, oneobj, pie, sanitizer;	/* options */
 static int reading_cache;
 static char *machine;
 static char *makeobjdirprefix;
@@ -157,13 +157,14 @@ main(int argc, char **argv)
     if (argc > 0)
 	pname = argv[0];
 
-    while ((optc = getopt(argc, argv, "m:c:d:e:fopqD:L:Ov:")) != -1) {
+    while ((optc = getopt(argc, argv, "m:c:d:e:fopqsD:L:Ov:")) != -1) {
 	switch(optc) {
 	case 'f':	readcache = 0; break;
 	case 'p':	pie = 1; break;
 	case 'q':	verbose = 0; break;
 	case 'O':	oneobj = 0; break;
 	case 'o':       useobjs = 1, oneobj = 0; break;
+	case 's':       sanitizer = 1; break;
 
 	case 'm':	(void)estrlcpy(outmkname, optarg, sizeof(outmkname)); break;
 	case 'c':	(void)estrlcpy(outcfname, optarg, sizeof(outcfname)); break;
@@ -922,6 +923,8 @@ top_makefile_rules(FILE *outmk)
 
     if (!pie)
 	    fprintf(outmk, "NOPIE=\n");
+    if (!sanitizer)
+	    fprintf(outmk, "NOSANITIZER=\n");
     fprintf(outmk, "NOMAN=\n\n");
 
     fprintf(outmk, "DBG=%s\n", dbg);
@@ -1017,7 +1020,7 @@ prog_makefile_rules(FILE *outmk, prog_t 
 	for (lst = vars; lst != NULL; lst = lst->next)
 	    fprintf(outmk, "%s\\n", lst->str);
 	fprintf(outmk, "'\\\n");
-	fprintf(outmk, MAKECMD);
+	fprintf(outmk, MAKECMD "%s ", sanitizer ? "" : "NOSANITIZER=");
 	if (p->objs)
 	    fprintf(outmk, "${%s_OBJS} ) \n\n", p->ident);
 	else

Reply via email to