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>
This commit is contained in:
kamil 2018-06-21 10:55:54 +00:00
parent e700149f57
commit b6ed70bb6e
2 changed files with 13 additions and 8 deletions

View File

@ -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 executables).
.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

View File

@ -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 *p)
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