Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/gnu Add the -iremap option to gcc(1) and cpp(1). This optio...



details:   https://anonhg.NetBSD.org/src/rev/3d578ce72d6a
branches:  trunk
changeset: 748959:3d578ce72d6a
user:      joerg <joerg%NetBSD.org@localhost>
date:      Wed Nov 11 19:03:52 2009 +0000

description:
Add the -iremap option to gcc(1) and cpp(1).  This option specifies a
prefix transformation rule for __FILE__ and can be used to avoid
hard-coding the location of the source tree in the resulting binary.

diffstat:

 gnu/dist/gcc4/gcc/c-opts.c            |   5 ++
 gnu/dist/gcc4/gcc/c.opt               |   4 ++
 gnu/dist/gcc4/gcc/doc/cpp.texi        |   1 +
 gnu/dist/gcc4/gcc/doc/cppopts.texi    |   6 +++
 gnu/dist/gcc4/gcc/doc/invoke.texi     |   9 ++++-
 gnu/dist/gcc4/gcc/gcc.h               |   2 +-
 gnu/dist/gcc4/libcpp/include/cpplib.h |   3 +
 gnu/dist/gcc4/libcpp/macro.c          |  60 ++++++++++++++++++++++++++++++++++-
 gnu/usr.bin/gcc4/cpp/cpp.1            |  13 +++++++-
 gnu/usr.bin/gcc4/gcc/gcc.1            |  13 +++++++-
 10 files changed, 111 insertions(+), 5 deletions(-)

diffs (271 lines):

diff -r 926cb215d258 -r 3d578ce72d6a gnu/dist/gcc4/gcc/c-opts.c
--- a/gnu/dist/gcc4/gcc/c-opts.c        Wed Nov 11 17:08:16 2009 +0000
+++ b/gnu/dist/gcc4/gcc/c-opts.c        Wed Nov 11 19:03:52 2009 +0000
@@ -163,6 +163,7 @@
     case OPT_isysroot:
     case OPT_isystem:
     case OPT_iquote:
+    case OPT_iremap:
       error ("missing path after %qs", opt);
       break;
 
@@ -841,6 +842,10 @@
       add_path (xstrdup (arg), SYSTEM, 0, true);
       break;
 
+    case OPT_iremap:
+      add_cpp_remap_path (arg);
+      break;
+
     case OPT_iwithprefix:
       add_prefixed_path (arg, SYSTEM);
       break;
diff -r 926cb215d258 -r 3d578ce72d6a gnu/dist/gcc4/gcc/c.opt
--- a/gnu/dist/gcc4/gcc/c.opt   Wed Nov 11 17:08:16 2009 +0000
+++ b/gnu/dist/gcc4/gcc/c.opt   Wed Nov 11 19:03:52 2009 +0000
@@ -783,6 +783,10 @@
 C ObjC C++ ObjC++ Joined Separate
 -iquote <dir>  Add <dir> to the end of the quote include path
 
+iremap
+C ObjC C++ ObjC++ Joined Separate
+-iremap <src:dst>      Convert <src> to <dst> if it occurs as prefix in __FILE__.
+
 iwithprefix
 C ObjC C++ ObjC++ Joined Separate
 -iwithprefix <dir>     Add <dir> to the end of the system include path
diff -r 926cb215d258 -r 3d578ce72d6a gnu/dist/gcc4/gcc/doc/cpp.texi
--- a/gnu/dist/gcc4/gcc/doc/cpp.texi    Wed Nov 11 17:08:16 2009 +0000
+++ b/gnu/dist/gcc4/gcc/doc/cpp.texi    Wed Nov 11 19:03:52 2009 +0000
@@ -4196,6 +4196,7 @@
 @c man begin SYNOPSIS
 cpp [@option{-D}@var{macro}[=@var{defn}]@dots{}] [@option{-U}@var{macro}]
     [@option{-I}@var{dir}@dots{}] [@option{-iquote}@var{dir}@dots{}]
+    [@option{-iremap}@var{src}:@var{dst}]
     [@option{-W}@var{warn}@dots{}]
     [@option{-M}|@option{-MM}] [@option{-MG}] [@option{-MF} @var{filename}]
     [@option{-MP}] [@option{-MQ} @var{target}@dots{}]
diff -r 926cb215d258 -r 3d578ce72d6a gnu/dist/gcc4/gcc/doc/cppopts.texi
--- a/gnu/dist/gcc4/gcc/doc/cppopts.texi        Wed Nov 11 17:08:16 2009 +0000
+++ b/gnu/dist/gcc4/gcc/doc/cppopts.texi        Wed Nov 11 19:03:52 2009 +0000
@@ -513,6 +513,12 @@
 @xref{Search Path}.
 @end ifset
 
+@item -iremap @var{src}:@var{dst}
+@opindex iremap
+Replace the prefix @var{src} in __FILE__ with @var{dst} at expansion time.
+This option can be specified more than once.  Processing stops at the first
+match.
+
 @item -fdollars-in-identifiers
 @opindex fdollars-in-identifiers
 @anchor{fdollars-in-identifiers}
diff -r 926cb215d258 -r 3d578ce72d6a gnu/dist/gcc4/gcc/doc/invoke.texi
--- a/gnu/dist/gcc4/gcc/doc/invoke.texi Wed Nov 11 17:08:16 2009 +0000
+++ b/gnu/dist/gcc4/gcc/doc/invoke.texi Wed Nov 11 19:03:52 2009 +0000
@@ -376,7 +376,8 @@
 
 @item Directory Options
 @xref{Directory Options,,Options for Directory Search}.
-@gccoptlist{-B@var{prefix}  -I@var{dir}  -iquote@var{dir}  -L@var{dir}
+@gccoptlist{-B@var{prefix}  -I@var{dir}  -iquote@var{dir}  
+-iremap@var{src}:@var{dst}  -L@var{dir}
 -specs=@var{file}  -I- --sysroot=@var{dir}}
 
 @item Target Options
@@ -6506,6 +6507,12 @@
 "@var{file}"}; they are not searched for @samp{#include <@var{file}>},
 otherwise just like @option{-I}.
 
+@item -iremap @var{src}:@var{dst}
+@opindex iremap
+Replace the prefix @var{src} in __FILE__ with @var{dst} at expansion time.
+This option can be specified more than once.  Processing stops at the first
+match.
+
 @item -L@var{dir}
 @opindex L
 Add directory @var{dir} to the list of directories to be searched
diff -r 926cb215d258 -r 3d578ce72d6a gnu/dist/gcc4/gcc/gcc.h
--- a/gnu/dist/gcc4/gcc/gcc.h   Wed Nov 11 17:08:16 2009 +0000
+++ b/gnu/dist/gcc4/gcc/gcc.h   Wed Nov 11 19:03:52 2009 +0000
@@ -50,7 +50,7 @@
   || !strcmp (STR, "idirafter") || !strcmp (STR, "iprefix") \
   || !strcmp (STR, "iwithprefix") || !strcmp (STR, "iwithprefixbefore") \
   || !strcmp (STR, "iquote") || !strcmp (STR, "isystem") \
-  || !strcmp (STR, "isysroot") \
+  || !strcmp (STR, "-iremap") || !strcmp (STR, "isysroot") \
   || !strcmp (STR, "-param") || !strcmp (STR, "specs") \
   || !strcmp (STR, "MF") || !strcmp (STR, "MT") || !strcmp (STR, "MQ"))
 
diff -r 926cb215d258 -r 3d578ce72d6a gnu/dist/gcc4/libcpp/include/cpplib.h
--- a/gnu/dist/gcc4/libcpp/include/cpplib.h     Wed Nov 11 17:08:16 2009 +0000
+++ b/gnu/dist/gcc4/libcpp/include/cpplib.h     Wed Nov 11 19:03:52 2009 +0000
@@ -623,6 +623,9 @@
 /* Set the include paths.  */
 extern void cpp_set_include_chains (cpp_reader *, cpp_dir *, cpp_dir *, int);
 
+/* Provide src:dst pair for __FILE__ remapping.  */
+extern void add_cpp_remap_path (const char *);
+
 /* Call these to get pointers to the options, callback, and deps
    structures for a given reader.  These pointers are good until you
    call cpp_finish on that reader.  You can either edit the callbacks
diff -r 926cb215d258 -r 3d578ce72d6a gnu/dist/gcc4/libcpp/macro.c
--- a/gnu/dist/gcc4/libcpp/macro.c      Wed Nov 11 17:08:16 2009 +0000
+++ b/gnu/dist/gcc4/libcpp/macro.c      Wed Nov 11 19:03:52 2009 +0000
@@ -109,6 +109,61 @@
   "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
 };
 
+static size_t remap_pairs;
+static char **remap_src;
+static char **remap_dst;
+
+void
+add_cpp_remap_path (const char *arg)
+{
+       const char *arg_dst;
+       size_t len;
+
+       arg_dst = strchr(arg, ':');
+       if (arg_dst == NULL) {
+               fprintf(stderr, "Invalid argument for -iremap");
+               exit(1);
+       }
+       len = arg_dst - arg;
+       ++arg_dst;
+
+       remap_src = xrealloc(remap_src, sizeof(char *) * (remap_pairs + 1));
+       remap_dst = xrealloc(remap_dst, sizeof(char *) * (remap_pairs + 1));
+
+       remap_src[remap_pairs] = xmalloc(len + 1);
+       memcpy(remap_src[remap_pairs], arg, len);
+       remap_src[remap_pairs][len] = '\0';
+       remap_dst[remap_pairs] = xstrdup(arg_dst);
+       ++remap_pairs;
+}
+
+static const char *
+cpp_remap_file (const char *arg, char **tmp_name)
+{
+       char *result;
+       size_t i, len;
+
+       for (i = 0; i < remap_pairs; ++i) {
+               len = strlen (remap_src[i]);
+               if (strncmp (remap_src[i], arg, len))
+                       continue;
+               if (arg[len] == '\0')
+                       return xstrdup (remap_dst[i]);
+               if (arg[len] != '/')
+                       continue;
+               arg += len;
+               len = strlen (remap_dst[i]);
+               result = xmalloc (len + strlen (arg) + 1);
+               memcpy(result, remap_dst[i], len);
+               strcpy(result + len, arg);
+               *tmp_name = result;
+
+               return result;
+       }
+
+       return arg;
+}
+
 /* Helper function for builtin_macro.  Returns the text generated by
    a builtin macro. */
 const uchar *
@@ -130,6 +185,7 @@
       {
        unsigned int len;
        const char *name;
+       char *tmp_name;
        uchar *buf;
        map = linemap_lookup (pfile->line_table, pfile->line_table->highest_line);
 
@@ -137,12 +193,14 @@
          while (! MAIN_FILE_P (map))
            map = INCLUDED_FROM (pfile->line_table, map);
 
-       name = map->to_file;
+       tmp_name = NULL;
+       name = cpp_remap_file (map->to_file, &tmp_name);
        len = strlen (name);
        buf = _cpp_unaligned_alloc (pfile, len * 2 + 3);
        result = buf;
        *buf = '"';
        buf = cpp_quote_string (buf + 1, (const unsigned char *) name, len);
+       free (tmp_name);
        *buf++ = '"';
        *buf = '\0';
       }
diff -r 926cb215d258 -r 3d578ce72d6a gnu/usr.bin/gcc4/cpp/cpp.1
--- a/gnu/usr.bin/gcc4/cpp/cpp.1        Wed Nov 11 17:08:16 2009 +0000
+++ b/gnu/usr.bin/gcc4/cpp/cpp.1        Wed Nov 11 19:03:52 2009 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: cpp.1,v 1.2 2009/04/30 00:45:47 joerg Exp $
+.\" $NetBSD: cpp.1,v 1.3 2009/11/11 19:03:53 joerg Exp $
 .Dd April 30, 2009
 .Dt CPP 1
 .Os
@@ -11,6 +11,7 @@
 .Op Fl U Ns Ar macro
 .Op Fl I Ns Ar dir...
 .Op Fl iquote Ns Ar dir...
+.Op Fl iremap Ns Ar src Ns : Ns Ar dst
 .Op Fl W Ns Ar warn...
 .Op Fl M | Fl MM
 .Op Fl MG
@@ -691,6 +692,16 @@
 .Fl I
 and before the standard system directories.
 .Pp
+.It Fl iremap Ns Ar src Ns : Ns Ar dst
+Replace the prefix
+.Ar src
+in
+.Va __FILE__
+with
+.Ar dst
+at expansion time.
+This option can be specified more than once.
+Processing stops at the first match.
 .It Fl fdollars-in-identifiers
 @anchor{fdollars-in-identifiers} Accept
 .Sy $
diff -r 926cb215d258 -r 3d578ce72d6a gnu/usr.bin/gcc4/gcc/gcc.1
--- a/gnu/usr.bin/gcc4/gcc/gcc.1        Wed Nov 11 17:08:16 2009 +0000
+++ b/gnu/usr.bin/gcc4/gcc/gcc.1        Wed Nov 11 19:03:52 2009 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: gcc.1,v 1.3 2009/04/30 00:30:56 joerg Exp $
+.\" $NetBSD: gcc.1,v 1.4 2009/11/11 19:03:53 joerg Exp $
 .Dd April 30, 2009
 .Dt GCC 1
 .Os
@@ -183,6 +183,7 @@
 .Fl B Ns Ar prefix
 .Fl I Ns Ar dir
 .Fl iquote Ns Ar dir
+.Fl iremap Ns Ar src Ns : Ns Ar dst
 .Fl L Ns Ar dir
 .Fl specs= Ns Ar file
 .Fl I- Fl -sysroot= Ns Ar dir
@@ -6633,6 +6634,16 @@
 .Fl I
 and before the standard system directories.
 .Pp
+.It Fl iremap Ns Ar src Ns : Ns Ar dst
+Replace the prefix
+.Ar src
+in
+.Va __FILE__
+with
+.Ar dst
+at expansion time.
+This option can be specified more than once.
+Processing stops at the first match.
 .It Fl fdollars-in-identifiers
 @anchor{fdollars-in-identifiers} Accept
 .Sy $



Home | Main Index | Thread Index | Old Index