diff options
Diffstat (limited to 'meta/recipes-devtools/gcc/gcc-6.3/0042-gcc-libcpp-support-ffile-prefix-map-old-new.patch')
-rw-r--r-- | meta/recipes-devtools/gcc/gcc-6.3/0042-gcc-libcpp-support-ffile-prefix-map-old-new.patch | 292 |
1 files changed, 292 insertions, 0 deletions
diff --git a/meta/recipes-devtools/gcc/gcc-6.3/0042-gcc-libcpp-support-ffile-prefix-map-old-new.patch b/meta/recipes-devtools/gcc/gcc-6.3/0042-gcc-libcpp-support-ffile-prefix-map-old-new.patch new file mode 100644 index 0000000000..861f0fd7f1 --- /dev/null +++ b/meta/recipes-devtools/gcc/gcc-6.3/0042-gcc-libcpp-support-ffile-prefix-map-old-new.patch | |||
@@ -0,0 +1,292 @@ | |||
1 | From ba738cc411c9a54e389e336bcaa0a2428dd4a9d2 Mon Sep 17 00:00:00 2001 | ||
2 | From: Hongxu Jia <hongxu.jia@windriver.com> | ||
3 | Date: Wed, 16 Mar 2016 02:27:43 -0400 | ||
4 | Subject: [PATCH 42/46] gcc/libcpp: support -ffile-prefix-map=<old>=<new> | ||
5 | |||
6 | Similar -fdebug-prefix-map, add option -ffile-prefix-map to map one | ||
7 | directory name (old) to another (new) in __FILE__, __BASE_FILE__ and | ||
8 | __builtin_FILE (). | ||
9 | |||
10 | https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70268 | ||
11 | |||
12 | Upstream-Status: Submitted [gcc-patches@gcc.gnu.org] | ||
13 | Signed-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 | 3 ++ | ||
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, 150 insertions(+), 5 deletions(-) | ||
24 | create mode 100644 libcpp/file-map.c | ||
25 | create mode 100644 libcpp/include/file-map.h | ||
26 | |||
27 | diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c | ||
28 | index fec58bc..7a0af43 100644 | ||
29 | --- a/gcc/c-family/c-opts.c | ||
30 | +++ b/gcc/c-family/c-opts.c | ||
31 | @@ -38,6 +38,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 | @@ -503,6 +511,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; | ||
58 | diff --git a/gcc/c-family/c.opt b/gcc/c-family/c.opt | ||
59 | index 660da6c..31f7b34 100644 | ||
60 | --- a/gcc/c-family/c.opt | ||
61 | +++ b/gcc/c-family/c.opt | ||
62 | @@ -1208,6 +1208,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. | ||
73 | diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c | ||
74 | index 80f2df5..a2bfcc0 100644 | ||
75 | --- a/gcc/dwarf2out.c | ||
76 | +++ b/gcc/dwarf2out.c | ||
77 | @@ -21672,6 +21672,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: | ||
85 | diff --git a/gcc/gimplify.c b/gcc/gimplify.c | ||
86 | index e223e59..1433c25 100644 | ||
87 | --- a/gcc/gimplify.c | ||
88 | +++ b/gcc/gimplify.c | ||
89 | @@ -57,6 +57,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 | |||
98 | @@ -2432,6 +2434,7 @@ gimplify_call_expr (tree *expr_p, gimple_seq *pre_p, bool want_value) | ||
99 | case BUILT_IN_FILE: | ||
100 | { | ||
101 | const char *locfile = LOCATION_FILE (EXPR_LOCATION (*expr_p)); | ||
102 | + locfile = remap_file_filename (locfile); | ||
103 | *expr_p = build_string_literal (strlen (locfile) + 1, locfile); | ||
104 | return GS_OK; | ||
105 | } | ||
106 | diff --git a/libcpp/Makefile.in b/libcpp/Makefile.in | ||
107 | index a7d7828..3d29572 100644 | ||
108 | --- a/libcpp/Makefile.in | ||
109 | +++ b/libcpp/Makefile.in | ||
110 | @@ -84,12 +84,12 @@ DEPMODE = $(CXXDEPMODE) | ||
111 | |||
112 | |||
113 | libcpp_a_OBJS = charset.o directives.o directives-only.o errors.o \ | ||
114 | - expr.o files.o identifiers.o init.o lex.o line-map.o macro.o \ | ||
115 | - mkdeps.o pch.o symtab.o traditional.o | ||
116 | + expr.o file-map.o files.o identifiers.o init.o lex.o line-map.o \ | ||
117 | + macro.o mkdeps.o pch.o symtab.o traditional.o | ||
118 | |||
119 | libcpp_a_SOURCES = charset.c directives.c directives-only.c errors.c \ | ||
120 | - expr.c files.c identifiers.c init.c lex.c line-map.c macro.c \ | ||
121 | - mkdeps.c pch.c symtab.c traditional.c | ||
122 | + expr.c file-map.c files.c identifiers.c init.c lex.c line-map.c \ | ||
123 | + macro.c mkdeps.c pch.c symtab.c traditional.c | ||
124 | |||
125 | all: libcpp.a $(USED_CATALOGS) | ||
126 | |||
127 | @@ -263,7 +263,7 @@ po/$(PACKAGE).pot: $(libcpp_a_SOURCES) | ||
128 | |||
129 | TAGS_SOURCES = $(libcpp_a_SOURCES) internal.h ucnid.h \ | ||
130 | include/line-map.h include/symtab.h include/cpp-id-data.h \ | ||
131 | - include/cpplib.h include/mkdeps.h system.h | ||
132 | + include/cpplib.h include/mkdeps.h system.h include/file-map.h | ||
133 | |||
134 | TAGS: $(TAGS_SOURCES) | ||
135 | cd $(srcdir) && etags $(TAGS_SOURCES) | ||
136 | diff --git a/libcpp/file-map.c b/libcpp/file-map.c | ||
137 | new file mode 100644 | ||
138 | index 0000000..18035ef | ||
139 | --- /dev/null | ||
140 | +++ b/libcpp/file-map.c | ||
141 | @@ -0,0 +1,92 @@ | ||
142 | +/* Map one directory name to another in __FILE__, __BASE_FILE__ | ||
143 | + and __builtin_FILE (). | ||
144 | + Copyright (C) 2001-2016 Free Software Foundation, Inc. | ||
145 | + | ||
146 | +This program is free software; you can redistribute it and/or modify it | ||
147 | +under the terms of the GNU General Public License as published by the | ||
148 | +Free Software Foundation; either version 3, or (at your option) any | ||
149 | +later version. | ||
150 | + | ||
151 | +This program is distributed in the hope that it will be useful, | ||
152 | +but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
153 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
154 | +GNU General Public License for more details. | ||
155 | + | ||
156 | +You should have received a copy of the GNU General Public License | ||
157 | +along with this program; see the file COPYING3. If not see | ||
158 | +<http://www.gnu.org/licenses/>. | ||
159 | + | ||
160 | + In other words, you are welcome to use, share and improve this program. | ||
161 | + You are forbidden to forbid anyone else to use, share and improve | ||
162 | + what you give them. Help stamp out software-hoarding! */ | ||
163 | + | ||
164 | +#include "config.h" | ||
165 | +#include "system.h" | ||
166 | +#include "file-map.h" | ||
167 | + | ||
168 | +/* Structure recording the mapping from source file and directory | ||
169 | + names at compile time to __FILE__ */ | ||
170 | +typedef struct file_prefix_map | ||
171 | +{ | ||
172 | + const char *old_prefix; | ||
173 | + const char *new_prefix; | ||
174 | + size_t old_len; | ||
175 | + size_t new_len; | ||
176 | + struct file_prefix_map *next; | ||
177 | +} file_prefix_map; | ||
178 | + | ||
179 | +/* Linked list of such structures. */ | ||
180 | +static file_prefix_map *file_prefix_maps; | ||
181 | + | ||
182 | +/* Record prefix mapping of __FILE__. ARG is the argument to | ||
183 | + -ffile-prefix-map and must be of the form OLD=NEW. */ | ||
184 | +int | ||
185 | +add_file_prefix_map (const char *arg) | ||
186 | +{ | ||
187 | + file_prefix_map *map; | ||
188 | + const char *p; | ||
189 | + | ||
190 | + p = strchr (arg, '='); | ||
191 | + if (!p) | ||
192 | + { | ||
193 | + fprintf(stderr, "invalid argument %qs to -ffile-prefix-map", arg); | ||
194 | + return -1; | ||
195 | + } | ||
196 | + map = XNEW (file_prefix_map); | ||
197 | + map->old_prefix = xstrndup (arg, p - arg); | ||
198 | + map->old_len = p - arg; | ||
199 | + p++; | ||
200 | + map->new_prefix = xstrdup (p); | ||
201 | + map->new_len = strlen (p); | ||
202 | + map->next = file_prefix_maps; | ||
203 | + file_prefix_maps = map; | ||
204 | + | ||
205 | + return 0; | ||
206 | +} | ||
207 | + | ||
208 | +/* Perform user-specified mapping of __FILE__ prefixes. Return | ||
209 | + the new name corresponding to filename. */ | ||
210 | + | ||
211 | +const char * | ||
212 | +remap_file_filename (const char *filename) | ||
213 | +{ | ||
214 | + file_prefix_map *map; | ||
215 | + char *s; | ||
216 | + const char *name; | ||
217 | + size_t name_len; | ||
218 | + | ||
219 | + for (map = file_prefix_maps; map; map = map->next) | ||
220 | + if (filename_ncmp (filename, map->old_prefix, map->old_len) == 0) | ||
221 | + break; | ||
222 | + if (!map) | ||
223 | + return filename; | ||
224 | + name = filename + map->old_len; | ||
225 | + name_len = strlen (name) + 1; | ||
226 | + s = (char *) alloca (name_len + map->new_len); | ||
227 | + memcpy (s, map->new_prefix, map->new_len); | ||
228 | + memcpy (s + map->new_len, name, name_len); | ||
229 | + | ||
230 | + return xstrdup (s); | ||
231 | +} | ||
232 | + | ||
233 | + | ||
234 | diff --git a/libcpp/include/file-map.h b/libcpp/include/file-map.h | ||
235 | new file mode 100644 | ||
236 | index 0000000..8750315 | ||
237 | --- /dev/null | ||
238 | +++ b/libcpp/include/file-map.h | ||
239 | @@ -0,0 +1,30 @@ | ||
240 | +/* Map one directory name to another in __FILE__, __BASE_FILE__ | ||
241 | + and __builtin_FILE (). | ||
242 | + Copyright (C) 2001-2016 Free Software Foundation, Inc. | ||
243 | + | ||
244 | +This program is free software; you can redistribute it and/or modify it | ||
245 | +under the terms of the GNU General Public License as published by the | ||
246 | +Free Software Foundation; either version 3, or (at your option) any | ||
247 | +later version. | ||
248 | + | ||
249 | +This program is distributed in the hope that it will be useful, | ||
250 | +but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
251 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
252 | +GNU General Public License for more details. | ||
253 | + | ||
254 | +You should have received a copy of the GNU General Public License | ||
255 | +along with this program; see the file COPYING3. If not see | ||
256 | +<http://www.gnu.org/licenses/>. | ||
257 | + | ||
258 | + In other words, you are welcome to use, share and improve this program. | ||
259 | + You are forbidden to forbid anyone else to use, share and improve | ||
260 | + what you give them. Help stamp out software-hoarding! */ | ||
261 | + | ||
262 | +#ifndef LIBCPP_FILE_MAP_H | ||
263 | +#define LIBCPP_FILE_MAP_H | ||
264 | + | ||
265 | +const char * remap_file_filename (const char *filename); | ||
266 | + | ||
267 | +int add_file_prefix_map (const char *arg); | ||
268 | + | ||
269 | +#endif /* !LIBCPP_FILE_MAP_H */ | ||
270 | diff --git a/libcpp/macro.c b/libcpp/macro.c | ||
271 | index c251553..3ceec3d 100644 | ||
272 | --- a/libcpp/macro.c | ||
273 | +++ b/libcpp/macro.c | ||
274 | @@ -26,6 +26,7 @@ along with this program; see the file COPYING3. If not see | ||
275 | #include "system.h" | ||
276 | #include "cpplib.h" | ||
277 | #include "internal.h" | ||
278 | +#include "file-map.h" | ||
279 | |||
280 | typedef struct macro_arg macro_arg; | ||
281 | /* This structure represents the tokens of a macro argument. These | ||
282 | @@ -301,6 +302,7 @@ _cpp_builtin_macro_text (cpp_reader *pfile, cpp_hashnode *node, | ||
283 | if (!name) | ||
284 | abort (); | ||
285 | } | ||
286 | + name = remap_file_filename (name); | ||
287 | len = strlen (name); | ||
288 | buf = _cpp_unaligned_alloc (pfile, len * 2 + 3); | ||
289 | result = buf; | ||
290 | -- | ||
291 | 2.8.2 | ||
292 | |||