summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/gcc/gcc-7.2/0041-gcc-libcpp-support-ffile-prefix-map-old-new.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/recipes-devtools/gcc/gcc-7.2/0041-gcc-libcpp-support-ffile-prefix-map-old-new.patch')
-rw-r--r--meta/recipes-devtools/gcc/gcc-7.2/0041-gcc-libcpp-support-ffile-prefix-map-old-new.patch284
1 files changed, 284 insertions, 0 deletions
diff --git a/meta/recipes-devtools/gcc/gcc-7.2/0041-gcc-libcpp-support-ffile-prefix-map-old-new.patch b/meta/recipes-devtools/gcc/gcc-7.2/0041-gcc-libcpp-support-ffile-prefix-map-old-new.patch
new file mode 100644
index 0000000000..5260e363d2
--- /dev/null
+++ b/meta/recipes-devtools/gcc/gcc-7.2/0041-gcc-libcpp-support-ffile-prefix-map-old-new.patch
@@ -0,0 +1,284 @@
1From 4eadc99bdd0974761bf48f0fd32994dd9a3ffcfe Mon Sep 17 00:00:00 2001
2From: Hongxu Jia <hongxu.jia@windriver.com>
3Date: Wed, 16 Mar 2016 02:27:43 -0400
4Subject: [PATCH 41/47] gcc/libcpp: support -ffile-prefix-map=<old>=<new>
5
6Similar -fdebug-prefix-map, add option -ffile-prefix-map to map one
7directory name (old) to another (new) in __FILE__, __BASE_FILE__ and
8__builtin_FILE ().
9
10https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70268
11
12Upstream-Status: Submitted [gcc-patches@gcc.gnu.org]
13Signed-off-by: Hongxu Jia <hongxu.jia@windriver.com>
14---
15 gcc/c-family/c-opts.c | 13 +++++++
16 gcc/c-family/c.opt | 4 +++
17 gcc/dwarf2out.c | 1 +
18 gcc/gimplify.c | 2 ++
19 libcpp/Makefile.in | 10 +++---
20 libcpp/file-map.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++
21 libcpp/include/file-map.h | 30 ++++++++++++++++
22 libcpp/macro.c | 2 ++
23 8 files changed, 149 insertions(+), 5 deletions(-)
24 create mode 100644 libcpp/file-map.c
25 create mode 100644 libcpp/include/file-map.h
26
27diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c
28index ea0e01b101c..a741c75a78f 100644
29--- a/gcc/c-family/c-opts.c
30+++ b/gcc/c-family/c-opts.c
31@@ -39,6 +39,14 @@ along with GCC; see the file COPYING3. If not see
32 #include "opts.h"
33 #include "plugin.h" /* For PLUGIN_INCLUDE_FILE event. */
34 #include "mkdeps.h"
35+#include "file-map.h"
36+#include "c-target.h"
37+#include "tm.h" /* For BYTES_BIG_ENDIAN,
38+ DOLLARS_IN_IDENTIFIERS,
39+ STDC_0_IN_SYSTEM_HEADERS,
40+ TARGET_FLT_EVAL_METHOD_NON_DEFAULT and
41+ TARGET_OPTF. */
42+#include "tm_p.h" /* For C_COMMON_OVERRIDE_OPTIONS. */
43 #include "dumpfile.h"
44
45 #ifndef DOLLARS_IN_IDENTIFIERS
46@@ -517,6 +525,11 @@ c_common_handle_option (size_t scode, const char *arg, int value,
47 cpp_opts->narrow_charset = arg;
48 break;
49
50+ case OPT_ffile_prefix_map_:
51+ if (add_file_prefix_map (arg) < 0)
52+ error ("invalid argument %qs to -ffile-prefix-map", arg);
53+ break;
54+
55 case OPT_fwide_exec_charset_:
56 cpp_opts->wide_charset = arg;
57 break;
58diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt
59index c4ef7796282..73333dfd57c 100644
60--- a/gcc/c-family/c.opt
61+++ b/gcc/c-family/c.opt
62@@ -1372,6 +1372,10 @@ fexec-charset=
63 C ObjC C++ ObjC++ Joined RejectNegative
64 -fexec-charset=<cset> Convert all strings and character constants to character set <cset>.
65
66+ffile-prefix-map=
67+C ObjC C++ ObjC++ Joined RejectNegative
68+-ffile-prefix-map=<old=new> Map one directory name to another in __FILE__, __BASE_FILE__ and __builtin_FILE ()
69+
70 fextended-identifiers
71 C ObjC C++ ObjC++
72 Permit universal character names (\\u and \\U) in identifiers.
73diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
74index 98c51576ec2..762f69ae88e 100644
75--- a/gcc/dwarf2out.c
76+++ b/gcc/dwarf2out.c
77@@ -23421,6 +23421,7 @@ gen_producer_string (void)
78 case OPT_fltrans_output_list_:
79 case OPT_fresolution_:
80 case OPT_fdebug_prefix_map_:
81+ case OPT_ffile_prefix_map_:
82 /* Ignore these. */
83 continue;
84 default:
85diff --git a/gcc/gimplify.c b/gcc/gimplify.c
86index fd27eb1523f..5542b379f28 100644
87--- a/gcc/gimplify.c
88+++ b/gcc/gimplify.c
89@@ -58,6 +58,8 @@ along with GCC; see the file COPYING3. If not see
90 #include "gomp-constants.h"
91 #include "tree-dump.h"
92 #include "gimple-walk.h"
93+#include "file-map.h"
94+
95 #include "langhooks-def.h" /* FIXME: for lhd_set_decl_assembler_name */
96 #include "builtins.h"
97 #include "asan.h"
98diff --git a/libcpp/Makefile.in b/libcpp/Makefile.in
99index 0bd3787c25e..d3b52956b52 100644
100--- a/libcpp/Makefile.in
101+++ b/libcpp/Makefile.in
102@@ -84,12 +84,12 @@ DEPMODE = $(CXXDEPMODE)
103
104
105 libcpp_a_OBJS = charset.o directives.o directives-only.o errors.o \
106- expr.o files.o identifiers.o init.o lex.o line-map.o macro.o \
107- mkdeps.o pch.o symtab.o traditional.o
108+ expr.o file-map.o files.o identifiers.o init.o lex.o line-map.o \
109+ macro.o mkdeps.o pch.o symtab.o traditional.o
110
111 libcpp_a_SOURCES = charset.c directives.c directives-only.c errors.c \
112- expr.c files.c identifiers.c init.c lex.c line-map.c macro.c \
113- mkdeps.c pch.c symtab.c traditional.c
114+ expr.c file-map.c files.c identifiers.c init.c lex.c line-map.c \
115+ macro.c mkdeps.c pch.c symtab.c traditional.c
116
117 all: libcpp.a $(USED_CATALOGS)
118
119@@ -263,7 +263,7 @@ po/$(PACKAGE).pot: $(libcpp_a_SOURCES)
120
121 TAGS_SOURCES = $(libcpp_a_SOURCES) internal.h ucnid.h \
122 include/line-map.h include/symtab.h include/cpp-id-data.h \
123- include/cpplib.h include/mkdeps.h system.h
124+ include/cpplib.h include/mkdeps.h system.h include/file-map.h
125
126 TAGS: $(TAGS_SOURCES)
127 cd $(srcdir) && etags $(TAGS_SOURCES)
128diff --git a/libcpp/file-map.c b/libcpp/file-map.c
129new file mode 100644
130index 00000000000..18035ef6a72
131--- /dev/null
132+++ b/libcpp/file-map.c
133@@ -0,0 +1,92 @@
134+/* Map one directory name to another in __FILE__, __BASE_FILE__
135+ and __builtin_FILE ().
136+ Copyright (C) 2001-2016 Free Software Foundation, Inc.
137+
138+This program is free software; you can redistribute it and/or modify it
139+under the terms of the GNU General Public License as published by the
140+Free Software Foundation; either version 3, or (at your option) any
141+later version.
142+
143+This program is distributed in the hope that it will be useful,
144+but WITHOUT ANY WARRANTY; without even the implied warranty of
145+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
146+GNU General Public License for more details.
147+
148+You should have received a copy of the GNU General Public License
149+along with this program; see the file COPYING3. If not see
150+<http://www.gnu.org/licenses/>.
151+
152+ In other words, you are welcome to use, share and improve this program.
153+ You are forbidden to forbid anyone else to use, share and improve
154+ what you give them. Help stamp out software-hoarding! */
155+
156+#include "config.h"
157+#include "system.h"
158+#include "file-map.h"
159+
160+/* Structure recording the mapping from source file and directory
161+ names at compile time to __FILE__ */
162+typedef struct file_prefix_map
163+{
164+ const char *old_prefix;
165+ const char *new_prefix;
166+ size_t old_len;
167+ size_t new_len;
168+ struct file_prefix_map *next;
169+} file_prefix_map;
170+
171+/* Linked list of such structures. */
172+static file_prefix_map *file_prefix_maps;
173+
174+/* Record prefix mapping of __FILE__. ARG is the argument to
175+ -ffile-prefix-map and must be of the form OLD=NEW. */
176+int
177+add_file_prefix_map (const char *arg)
178+{
179+ file_prefix_map *map;
180+ const char *p;
181+
182+ p = strchr (arg, '=');
183+ if (!p)
184+ {
185+ fprintf(stderr, "invalid argument %qs to -ffile-prefix-map", arg);
186+ return -1;
187+ }
188+ map = XNEW (file_prefix_map);
189+ map->old_prefix = xstrndup (arg, p - arg);
190+ map->old_len = p - arg;
191+ p++;
192+ map->new_prefix = xstrdup (p);
193+ map->new_len = strlen (p);
194+ map->next = file_prefix_maps;
195+ file_prefix_maps = map;
196+
197+ return 0;
198+}
199+
200+/* Perform user-specified mapping of __FILE__ prefixes. Return
201+ the new name corresponding to filename. */
202+
203+const char *
204+remap_file_filename (const char *filename)
205+{
206+ file_prefix_map *map;
207+ char *s;
208+ const char *name;
209+ size_t name_len;
210+
211+ for (map = file_prefix_maps; map; map = map->next)
212+ if (filename_ncmp (filename, map->old_prefix, map->old_len) == 0)
213+ break;
214+ if (!map)
215+ return filename;
216+ name = filename + map->old_len;
217+ name_len = strlen (name) + 1;
218+ s = (char *) alloca (name_len + map->new_len);
219+ memcpy (s, map->new_prefix, map->new_len);
220+ memcpy (s + map->new_len, name, name_len);
221+
222+ return xstrdup (s);
223+}
224+
225+
226diff --git a/libcpp/include/file-map.h b/libcpp/include/file-map.h
227new file mode 100644
228index 00000000000..87503152d27
229--- /dev/null
230+++ b/libcpp/include/file-map.h
231@@ -0,0 +1,30 @@
232+/* Map one directory name to another in __FILE__, __BASE_FILE__
233+ and __builtin_FILE ().
234+ Copyright (C) 2001-2016 Free Software Foundation, Inc.
235+
236+This program is free software; you can redistribute it and/or modify it
237+under the terms of the GNU General Public License as published by the
238+Free Software Foundation; either version 3, or (at your option) any
239+later version.
240+
241+This program is distributed in the hope that it will be useful,
242+but WITHOUT ANY WARRANTY; without even the implied warranty of
243+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
244+GNU General Public License for more details.
245+
246+You should have received a copy of the GNU General Public License
247+along with this program; see the file COPYING3. If not see
248+<http://www.gnu.org/licenses/>.
249+
250+ In other words, you are welcome to use, share and improve this program.
251+ You are forbidden to forbid anyone else to use, share and improve
252+ what you give them. Help stamp out software-hoarding! */
253+
254+#ifndef LIBCPP_FILE_MAP_H
255+#define LIBCPP_FILE_MAP_H
256+
257+const char * remap_file_filename (const char *filename);
258+
259+int add_file_prefix_map (const char *arg);
260+
261+#endif /* !LIBCPP_FILE_MAP_H */
262diff --git a/libcpp/macro.c b/libcpp/macro.c
263index de18c2210cf..2748c70d520 100644
264--- a/libcpp/macro.c
265+++ b/libcpp/macro.c
266@@ -26,6 +26,7 @@ along with this program; see the file COPYING3. If not see
267 #include "system.h"
268 #include "cpplib.h"
269 #include "internal.h"
270+#include "file-map.h"
271
272 typedef struct macro_arg macro_arg;
273 /* This structure represents the tokens of a macro argument. These
274@@ -301,6 +302,7 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node,
275 if (!name)
276 abort ();
277 }
278+ name = remap_file_filename (name);
279 len = strlen (name);
280 buf = _cpp_unaligned_alloc (pfile, len * 2 + 3);
281 result = buf;
282--
2832.12.2
284