Module Name:    src
Committed By:   christos
Date:           Sat Jan  9 02:00:14 UTC 2016

Modified Files:
        src/external/gpl3/gcc.old/dist/gcc: Makefile.in common.opt debug.h
            final.c opts-global.c opts.c
        src/external/gpl3/gcc.old/dist/gcc/config/rs6000: ppc-asm.h
        src/external/gpl3/gcc.old/usr.bin/backend: Makefile
Added Files:
        src/external/gpl3/gcc.old/dist/gcc: regsub.c

Log Message:
add -fdebug-regex-map=regex=subst which works like sed -e s/regex/subst/
to aid with /usr/obj remapping for MKREPRO


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/external/gpl3/gcc.old/dist/gcc/Makefile.in \
    src/external/gpl3/gcc.old/dist/gcc/final.c
cvs rdiff -u -r1.3 -r1.4 src/external/gpl3/gcc.old/dist/gcc/common.opt \
    src/external/gpl3/gcc.old/dist/gcc/debug.h \
    src/external/gpl3/gcc.old/dist/gcc/opts.c
cvs rdiff -u -r1.1.1.1 -r1.2 src/external/gpl3/gcc.old/dist/gcc/opts-global.c
cvs rdiff -u -r0 -r1.1 src/external/gpl3/gcc.old/dist/gcc/regsub.c
cvs rdiff -u -r1.3 -r1.4 \
    src/external/gpl3/gcc.old/dist/gcc/config/rs6000/ppc-asm.h
cvs rdiff -u -r1.3 -r1.4 src/external/gpl3/gcc.old/usr.bin/backend/Makefile

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

Modified files:

Index: src/external/gpl3/gcc.old/dist/gcc/Makefile.in
diff -u src/external/gpl3/gcc.old/dist/gcc/Makefile.in:1.4 src/external/gpl3/gcc.old/dist/gcc/Makefile.in:1.5
--- src/external/gpl3/gcc.old/dist/gcc/Makefile.in:1.4	Sun Nov  1 19:51:18 2015
+++ src/external/gpl3/gcc.old/dist/gcc/Makefile.in	Fri Jan  8 21:00:14 2016
@@ -1336,6 +1336,7 @@ OBJS = \
 	regmove.o \
 	regrename.o \
 	regstat.o \
+	regsub.o \
 	reload.o \
 	reload1.o \
 	reorg.o \
Index: src/external/gpl3/gcc.old/dist/gcc/final.c
diff -u src/external/gpl3/gcc.old/dist/gcc/final.c:1.4 src/external/gpl3/gcc.old/dist/gcc/final.c:1.5
--- src/external/gpl3/gcc.old/dist/gcc/final.c:1.4	Tue Dec 22 11:48:44 2015
+++ src/external/gpl3/gcc.old/dist/gcc/final.c	Fri Jan  8 21:00:14 2016
@@ -1535,8 +1535,8 @@ add_debug_prefix_map (const char *arg)
 /* Perform user-specified mapping of debug filename prefixes.  Return
    the new name corresponding to FILENAME.  */
 
-const char *
-remap_debug_filename (const char *filename)
+static const char *
+remap_debug_prefix_filename (const char *filename)
 {
   debug_prefix_map *map;
   char *s;
@@ -1555,6 +1555,88 @@ remap_debug_filename (const char *filena
   memcpy (s + map->new_len, name, name_len);
   return ggc_strdup (s);
 }
+
+#include <regex.h>
+
+typedef struct debug_regex_map
+{
+  regex_t re;
+  const char *sub;
+  struct debug_regex_map *next;
+} debug_regex_map;
+
+/* Linked list of such structures.  */
+debug_regex_map *debug_regex_maps;
+
+
+/* Record a debug file regex mapping.  ARG is the argument to
+   -fdebug-regex-map and must be of the form OLD=NEW.  */
+
+void
+add_debug_regex_map (const char *arg)
+{
+  debug_regex_map *map;
+  const char *p;
+  char *old;
+  char buf[1024];
+  regex_t re;
+  int e;
+
+  p = strchr (arg, '=');
+  if (!p)
+    {
+      error ("invalid argument %qs to -fdebug-regex-map", arg);
+      return;
+    }
+  
+  old = xstrndup (arg, p - arg);
+  if ((e = regcomp(&re, old, REG_EXTENDED)) != 0)
+    {
+      regerror(e, &re, buf, sizeof(buf));
+      warning (0, "regular expression compilation for %qs in argument to "
+	       "-fdebug-regex-map failed: %qs", old, buf);
+      free(old);
+      return;
+    }
+  free(old);
+
+  map = XNEW (debug_regex_map);
+  map->re = re;
+  p++;
+  map->sub = xstrdup (p);
+  map->next = debug_regex_maps;
+  debug_regex_maps = map;
+}
+
+extern ssize_t aregsub(char **, const char *,
+  const regmatch_t *rm, const char *);
+
+/* Perform user-specified mapping of debug filename regular expressions.  Return
+   the new name corresponding to FILENAME.  */
+
+static const char *
+remap_debug_regex_filename (const char *filename)
+{
+  debug_regex_map *map;
+  char *s;
+  regmatch_t rm[10];
+
+  for (map = debug_regex_maps; map; map = map->next)
+    if (regexec (&map->re, filename, 10, rm, 0) == 0
+       && aregsub (&s, map->sub, rm, filename) >= 0)
+      {
+	 const char *name = ggc_strdup(s);
+	 free(s);
+	 return name;
+      }
+  return filename;
+}
+
+const char *
+remap_debug_filename (const char *filename)
+{
+   return remap_debug_regex_filename (remap_debug_prefix_filename (filename));
+}
 
 /* Return true if DWARF2 debug info can be emitted for DECL.  */
 

Index: src/external/gpl3/gcc.old/dist/gcc/common.opt
diff -u src/external/gpl3/gcc.old/dist/gcc/common.opt:1.3 src/external/gpl3/gcc.old/dist/gcc/common.opt:1.4
--- src/external/gpl3/gcc.old/dist/gcc/common.opt:1.3	Tue Sep 22 23:39:09 2015
+++ src/external/gpl3/gcc.old/dist/gcc/common.opt	Fri Jan  8 21:00:14 2016
@@ -974,7 +974,11 @@ Common RejectNegative Joined Var(common_
 
 fdebug-prefix-map=
 Common Joined RejectNegative Var(common_deferred_options) Defer
-Map one directory name to another in debug information
+Map one directory name prefix to another in debug information
+
+fdebug-regex-map=
+Common Joined RejectNegative Var(common_deferred_options) Defer
+Map one directory name to another in debug information using regular expression matching
 
 fdebug-types-section
 Common Report Var(flag_debug_types_section) Init(0)
Index: src/external/gpl3/gcc.old/dist/gcc/debug.h
diff -u src/external/gpl3/gcc.old/dist/gcc/debug.h:1.3 src/external/gpl3/gcc.old/dist/gcc/debug.h:1.4
--- src/external/gpl3/gcc.old/dist/gcc/debug.h:1.3	Tue Sep 22 23:39:10 2015
+++ src/external/gpl3/gcc.old/dist/gcc/debug.h	Fri Jan  8 21:00:14 2016
@@ -186,6 +186,7 @@ extern void dwarf2out_switch_text_sectio
 
 const char *remap_debug_filename (const char *);
 void add_debug_prefix_map (const char *);
+void add_debug_regex_map (const char *);
 
 /* For -fdump-go-spec.  */
 
Index: src/external/gpl3/gcc.old/dist/gcc/opts.c
diff -u src/external/gpl3/gcc.old/dist/gcc/opts.c:1.3 src/external/gpl3/gcc.old/dist/gcc/opts.c:1.4
--- src/external/gpl3/gcc.old/dist/gcc/opts.c:1.3	Tue Sep 22 23:39:11 2015
+++ src/external/gpl3/gcc.old/dist/gcc/opts.c	Fri Jan  8 21:00:14 2016
@@ -1489,6 +1489,10 @@ common_handle_option (struct gcc_options
       /* Deferred.  */
       break;
 
+    case OPT_fdebug_regex_map_:
+      /* Deferred.  */
+      break;
+
     case OPT_fdiagnostics_show_location_:
       diagnostic_prefixing_rule (dc) = (diagnostic_prefixing_rule_t) value;
       break;

Index: src/external/gpl3/gcc.old/dist/gcc/opts-global.c
diff -u src/external/gpl3/gcc.old/dist/gcc/opts-global.c:1.1.1.1 src/external/gpl3/gcc.old/dist/gcc/opts-global.c:1.2
--- src/external/gpl3/gcc.old/dist/gcc/opts-global.c:1.1.1.1	Tue Sep 22 23:03:15 2015
+++ src/external/gpl3/gcc.old/dist/gcc/opts-global.c	Fri Jan  8 21:00:14 2016
@@ -384,6 +384,10 @@ handle_common_deferred_options (void)
 	  add_debug_prefix_map (opt->arg);
 	  break;
 
+	case OPT_fdebug_regex_map_:
+	  add_debug_regex_map (opt->arg);
+	  break;
+
 	case OPT_fdump_:
 	  if (!dump_switch_p (opt->arg))
 	    error ("unrecognized command line option %<-fdump-%s%>", opt->arg);

Index: src/external/gpl3/gcc.old/dist/gcc/config/rs6000/ppc-asm.h
diff -u src/external/gpl3/gcc.old/dist/gcc/config/rs6000/ppc-asm.h:1.3 src/external/gpl3/gcc.old/dist/gcc/config/rs6000/ppc-asm.h:1.4
--- src/external/gpl3/gcc.old/dist/gcc/config/rs6000/ppc-asm.h:1.3	Tue Sep 22 23:39:16 2015
+++ src/external/gpl3/gcc.old/dist/gcc/config/rs6000/ppc-asm.h	Fri Jan  8 21:00:14 2016
@@ -375,7 +375,7 @@ GLUE(.L,name): \
 #endif
 #endif
 
-#if defined __linux__ && !defined __powerpc64__
+#if defined(__ELF__) && defined(__linux__) && !defined(__powerpc64__)
 	.section .note.GNU-stack
 	.previous
 #endif

Index: src/external/gpl3/gcc.old/usr.bin/backend/Makefile
diff -u src/external/gpl3/gcc.old/usr.bin/backend/Makefile:1.3 src/external/gpl3/gcc.old/usr.bin/backend/Makefile:1.4
--- src/external/gpl3/gcc.old/usr.bin/backend/Makefile:1.3	Wed Sep 23 00:24:16 2015
+++ src/external/gpl3/gcc.old/usr.bin/backend/Makefile	Fri Jan  8 21:00:14 2016
@@ -1,10 +1,10 @@
-#	$NetBSD: Makefile,v 1.3 2015/09/23 04:24:16 mrg Exp $
+#	$NetBSD: Makefile,v 1.4 2016/01/09 02:00:14 christos Exp $
 
 LIBISPRIVATE=	yes
 
 LIB=		backend
 
-SRCS=		${G_OBJS:.o=.c} ${G_out_file:T}
+SRCS=		${G_OBJS:.o=.c} ${G_out_file:T} regsub.c
 
 BOTH_CPPFLAGS+=	-I. -I${GCCARCH} ${G_ALL_CFLAGS:M-D*} ${G_INCLUDES:M-I*:N-I.*}
 CPPFLAGS+=	${BOTH_CPPFLAGS} -DTARGET_NAME=\"${MACHINE_GNU_PLATFORM}\"

Added files:

Index: src/external/gpl3/gcc.old/dist/gcc/regsub.c
diff -u /dev/null src/external/gpl3/gcc.old/dist/gcc/regsub.c:1.1
--- /dev/null	Fri Jan  8 21:00:14 2016
+++ src/external/gpl3/gcc.old/dist/gcc/regsub.c	Fri Jan  8 21:00:14 2016
@@ -0,0 +1,161 @@
+/*	$NetBSD: regsub.c,v 1.1 2016/01/09 02:00:14 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2015 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: regsub.c,v 1.1 2016/01/09 02:00:14 christos Exp $");
+
+#include <sys/param.h>
+
+#include <ctype.h>
+#include <stdlib.h>
+#include <string.h>
+#include <regex.h>
+
+struct str {
+	char *s_ptr;
+	size_t s_max;
+	size_t s_len;
+	int s_fixed;
+};
+
+static int
+addspace(struct str *s, size_t len)
+{
+	void *v;
+
+	if (s->s_max - s->s_len > len)
+		return 0;
+
+	if (s->s_fixed)
+		return -1;
+
+	s->s_max += MAX(len, 64);
+
+	v = realloc(s->s_ptr, s->s_max);
+	if (v == NULL)
+		return -1;
+	s->s_ptr = (char *)v;
+
+	return 0;
+}
+
+static void
+addchar(struct str *s, int c)
+{
+	if (addspace(s, 1) == -1)
+		s->s_len++;
+	else
+		s->s_ptr[s->s_len++] = c;
+	if (c == 0) {
+		--s->s_len;
+		s->s_ptr[s->s_max - 1] = c;	
+	}
+}
+
+static void
+addnstr(struct str *s, const char *buf, size_t len)
+{
+	if (addspace(s, len) != -1)
+		memcpy(s->s_ptr + s->s_len, buf, len);
+	s->s_len += len;
+}
+
+static int
+initstr(struct str *s, char *buf, size_t len)
+{
+	s->s_max = len;
+	s->s_ptr = buf == NULL ? (char *)malloc(len) : buf;
+	s->s_fixed = buf != NULL;
+	s->s_len = 0;
+	return s->s_ptr == NULL ? -1 : 0;
+}
+
+static ssize_t
+regsub1(char **buf, size_t len, const char *sub,
+    const regmatch_t *rm, const char *str)
+{
+        ssize_t i;                 
+        char c; 
+	struct str s;
+
+	if (initstr(&s, *buf, len) == -1)
+		return -1;
+
+        while ((c = *sub++) != '\0') {
+
+		switch (c) {
+		case '&':
+			i = 0;
+			break;
+		case '\\':
+			if (isdigit((unsigned char)*sub))
+				i = *sub++ - '0';
+			else
+				i = -1;
+			break;
+		default:
+			i = -1;
+			break;
+		}
+
+                if (i == -1) {
+                        if (c == '\\' && (*sub == '\\' || *sub == '&'))
+                                c = *sub++;
+			addchar(&s, c);
+                } else if (rm[i].rm_so != -1 && rm[i].rm_eo != -1) {
+                        size_t l = (size_t)(rm[i].rm_eo - rm[i].rm_so);
+			addnstr(&s, str + rm[i].rm_so, l);
+                }
+        }
+
+	addchar(&s, '\0');
+	if (!s.s_fixed) {
+		if (s.s_len >= s.s_max) {
+			free(s.s_ptr);
+			return -1;
+		}
+		*buf = s.s_ptr;
+	}
+	return s.s_len;
+}
+
+ssize_t
+regsub(char *buf, size_t len, const char *sub, const regmatch_t *rm,
+    const char *str)
+{
+	return regsub1(&buf, len, sub, rm, str);
+}
+
+ssize_t
+aregsub(char **buf, const char *sub, const regmatch_t *rm, const char *str)
+{
+	*buf = NULL;
+	return regsub1(buf, 64, sub, rm, str);
+}

Reply via email to