summaryrefslogtreecommitdiffstats
path: root/meta/packages/gcc/gcc-4.0.2/GCOV_PREFIX_STRIP-cross-profile_4.1.patch
diff options
context:
space:
mode:
Diffstat (limited to 'meta/packages/gcc/gcc-4.0.2/GCOV_PREFIX_STRIP-cross-profile_4.1.patch')
-rw-r--r--meta/packages/gcc/gcc-4.0.2/GCOV_PREFIX_STRIP-cross-profile_4.1.patch371
1 files changed, 0 insertions, 371 deletions
diff --git a/meta/packages/gcc/gcc-4.0.2/GCOV_PREFIX_STRIP-cross-profile_4.1.patch b/meta/packages/gcc/gcc-4.0.2/GCOV_PREFIX_STRIP-cross-profile_4.1.patch
deleted file mode 100644
index 92ce00a1e3..0000000000
--- a/meta/packages/gcc/gcc-4.0.2/GCOV_PREFIX_STRIP-cross-profile_4.1.patch
+++ /dev/null
@@ -1,371 +0,0 @@
12005-05-04 Grigory Zagorodnev <grigory.zagorodnev@intel.com>
2 H.J. Lu <hongjiu.lu@intel.com>
3
4 * gcov-io.c (gcov_open): When in libgcov library
5 use given data file relocation prefix to build file name.
6 * gcov-io.h (gcov_open): Updated proto to accept
7 data file relocation prefix.
8 * libgcov.c (create_file_directory): New function.
9 (gcov_prefix): New static variable to hold data file
10 relocation prefix.
11 (gcov_version): Use relocation prefix.
12 (gcov_exit): Always try to create directory for output
13 file. Relocate filename at each use.
14 (__gcov_init): Initialize directory relocation prefix
15 if required. Strip off leading directories from
16 the initial filename.
17 * tsystem.h: include filenames.h
18 (DIR_SEPARATOR): Macro copied from system.h.
19 (DIR_SEPARATOR_2): Likewise.
20 * doc/gcov.texi (Cross-profiling): New node documenting
21 cross-profiling management.
22 * doc/invoke.texi (-fprofile-arcs): xref to cross-profiling.
23
24--- gcc-4/gcc/doc/gcov.texi.prefix 2005-03-28 11:56:34.000000000 -0800
25+++ gcc-4/gcc/doc/gcov.texi 2005-05-04 15:07:44.000000000 -0700
26@@ -42,6 +42,7 @@ test code coverage in your programs.
27 * Invoking Gcov:: How to use gcov.
28 * Gcov and Optimization:: Using gcov with GCC optimization.
29 * Gcov Data Files:: The files used by gcov.
30+* Cross-profiling:: Data files relocation.
31 @end menu
32
33 @node Gcov Intro
34@@ -531,3 +532,36 @@ information.
35 The full details of the file format is specified in @file{gcov-io.h},
36 and functions provided in that header file should be used to access the
37 coverage files.
38+
39+@node Cross-profiling
40+@section Data files relocation to support cross-profiling
41+
42+Running the program will cause profile output to be generated. For each
43+source file compiled with @option{-fprofile-arcs}, an accompanying @file{.gcda}
44+file will be placed in the object file directory. That implicitly requires
45+running the program at the same system as it was build or having same
46+absolute directory structure on the target system (program will try
47+to create needed directory structure).
48+
49+To support cross-profiling, program compiled with @option{-fprofile-arcs}
50+performs data file relocation basing on two environment variables:
51+
52+@itemize @bullet
53+@item
54+GCOV_PREFIX contains the prefix to add to the absolute paths
55+in the object file.
56+
57+@item
58+GCOV_PREFIX_STRIP indicates the how many initial directory names to strip off
59+the hardwired absolute paths. Default value is 0.
60+@end itemize
61+
62+For example, if object file @file{/user/build/foo.o} was build with
63+@option{-fprofile-arcs}, the final executable will try to create data file
64+@file{/user/build/foo.gcda} when running at the target system and will
65+fail if corresponding directory does not exists and is not allowed to create.
66+
67+In this case, manipulating environment variables you can relocate data file
68+to the suitable local directory. For our example, setting @samp{GCOV_PREFIX=/target/run}
69+and @samp{GCOV_PREFIX_STRIP=1} values will force use of @file{/target/run/build/foo.gcda}
70+file name.
71--- gcc-4/gcc/doc/invoke.texi.prefix 2005-05-04 11:21:00.000000000 -0700
72+++ gcc-4/gcc/doc/invoke.texi 2005-05-04 15:07:44.000000000 -0700
73@@ -3420,6 +3420,7 @@ explicitly specified and it is not the f
74 the basename of the source file. In both cases any suffix is removed
75 (e.g.@: @file{foo.gcda} for input file @file{dir/foo.c}, or
76 @file{dir/foo.gcda} for output file specified as @option{-o dir/foo.o}).
77+@xref{Cross-profiling}.
78
79 @cindex @command{gcov}
80 @item --coverage
81--- gcc-4/gcc/gcov-io.c.prefix 2005-04-28 16:11:30.000000000 -0700
82+++ gcc-4/gcc/gcov-io.c 2005-05-04 20:02:35.000000000 -0700
83@@ -55,13 +55,14 @@ static inline gcov_unsigned_t from_file
84
85 GCOV_LINKAGE int
86 #if IN_LIBGCOV
87-gcov_open (const char *name)
88+gcov_open (const char *prefix, const char *name)
89 #else
90 gcov_open (const char *name, int mode)
91 #endif
92 {
93 #if IN_LIBGCOV
94 const int mode = 0;
95+ char *tmp;
96 #endif
97 #if GCOV_LOCKED
98 struct flock s_flock;
99@@ -82,6 +83,13 @@ gcov_open (const char *name, int mode)
100 #if !IN_LIBGCOV
101 gcov_var.endian = 0;
102 #endif
103+
104+#if IN_LIBGCOV
105+ /* Build complete filename with prefix */
106+ tmp = alloca (strlen (prefix) + strlen (name) + 1);
107+ name = strcat (strcpy (tmp, prefix), name);
108+#endif
109+
110 #if GCOV_LOCKED
111 if (mode > 0)
112 fd = open (name, O_RDWR);
113--- gcc-4/gcc/gcov-io.h.prefix 2005-05-02 17:43:08.000000000 -0700
114+++ gcc-4/gcc/gcov-io.h 2005-05-04 15:07:44.000000000 -0700
115@@ -515,7 +515,7 @@ GCOV_LINKAGE struct gcov_var
116 functions for writing. Your file may become corrupted if you break
117 these invariants. */
118 #if IN_LIBGCOV
119-GCOV_LINKAGE int gcov_open (const char */*name*/) ATTRIBUTE_HIDDEN;
120+GCOV_LINKAGE int gcov_open (const char */*prefix*/, const char */*name*/) ATTRIBUTE_HIDDEN;
121 #else
122 GCOV_LINKAGE int gcov_open (const char */*name*/, int /*direction*/);
123 GCOV_LINKAGE int gcov_magic (gcov_unsigned_t, gcov_unsigned_t);
124--- gcc-4/gcc/libgcov.c.prefix 2005-04-28 16:11:30.000000000 -0700
125+++ gcc-4/gcc/libgcov.c 2005-05-04 15:07:44.000000000 -0700
126@@ -92,6 +92,70 @@ static struct gcov_info *gcov_list;
127 object file included in multiple programs. */
128 static gcov_unsigned_t gcov_crc32;
129
130+/* Directory prefix to relocate coverage data file names */
131+static char *gcov_prefix = 0;
132+
133+/* Level of dirs to strip off the initial filename to relocate */
134+static int gcov_prefix_strip = 0;
135+
136+static int
137+create_file_directory (const char *prefix, const char *filename)
138+{
139+ char *dname;
140+ char sep, *r, *s;
141+ size_t plen, flen;
142+
143+ /* Detect directory separator */
144+ s = strrchr (prefix, DIR_SEPARATOR);
145+#ifdef DIR_SEPARATOR_2
146+ if (! s)
147+ s = strrchr (prefix, DIR_SEPARATOR_2);
148+#endif
149+ if (s)
150+ sep = *s;
151+ else
152+ sep = DIR_SEPARATOR;
153+
154+ /* join prefix and filename, split path */
155+ plen = strlen(prefix);
156+ flen = strlen(filename);
157+ r = alloca(plen + flen + 1);
158+ strncpy(r, prefix, plen);
159+ strncpy(r + plen, filename, flen);
160+ r[plen + flen] = '\0';
161+ s = strrchr(r, sep);
162+ if (s)
163+ *(s + 1) = '\0';
164+
165+ if (access (r, F_OK) == 0)
166+ return 0;
167+
168+ /* Skip consecutive separators. */
169+ for (dname = r; *dname && *dname == sep; ++dname);
170+ while (1)
171+ {
172+ char *s = strchr (dname, sep);
173+ if (s == 0)
174+ break;
175+ *s = '\0';
176+ /* Try to make directory if it doesn't already exist. */
177+ if (access (r, F_OK) == -1
178+ && mkdir (r, 0755) == -1
179+ /* The directory might have been made by another process. */
180+ && errno != EEXIST)
181+ {
182+ *s = sep;
183+ fprintf (stderr, "profiling:%s:Cannot create directory\n", r);
184+ return -1;
185+ };
186+ *s = sep;
187+ /* Skip consecutive separators. */
188+ for (dname = s + 1; *dname && *dname == sep; ++dname)
189+ ;
190+ }
191+ return 0;
192+}
193+
194 static int
195 gcov_version (struct gcov_info *ptr, gcov_unsigned_t version)
196 {
197@@ -103,8 +167,8 @@ gcov_version (struct gcov_info *ptr, gco
198 GCOV_UNSIGNED2STRING (e, GCOV_VERSION);
199
200 fprintf (stderr,
201- "profiling:%s:Version mismatch - expected %.4s got %.4s\n",
202- ptr->filename, e, v);
203+ "profiling:%s%s:Version mismatch - expected %.4s got %.4s\n",
204+ gcov_prefix, ptr->filename, e, v);
205 return 0;
206 }
207 return 1;
208@@ -205,9 +269,16 @@ gcov_exit (void)
209 fi_stride &= ~(__alignof__ (struct gcov_fn_info) - 1);
210 }
211
212- if (!gcov_open (gi_ptr->filename))
213+ if (create_file_directory (gcov_prefix, gi_ptr->filename))
214+ {
215+ fprintf (stderr, "profiling:%s%s:Skip\n", gcov_prefix,
216+ gi_ptr->filename);
217+ continue;
218+ }
219+ else if (!gcov_open (gcov_prefix, gi_ptr->filename))
220 {
221- fprintf (stderr, "profiling:%s:Cannot open\n", gi_ptr->filename);
222+ fprintf (stderr, "profiling:%s%s:Cannot open\n", gcov_prefix,
223+ gi_ptr->filename);
224 continue;
225 }
226
227@@ -217,8 +288,8 @@ gcov_exit (void)
228 /* Merge data from file. */
229 if (tag != GCOV_DATA_MAGIC)
230 {
231- fprintf (stderr, "profiling:%s:Not a gcov data file\n",
232- gi_ptr->filename);
233+ fprintf (stderr, "profiling:%s%s:Not a gcov data file\n",
234+ gcov_prefix, gi_ptr->filename);
235 goto read_fatal;
236 }
237 length = gcov_read_unsigned ();
238@@ -245,8 +316,8 @@ gcov_exit (void)
239 || gcov_read_unsigned () != fi_ptr->checksum)
240 {
241 read_mismatch:;
242- fprintf (stderr, "profiling:%s:Merge mismatch for %s\n",
243- gi_ptr->filename,
244+ fprintf (stderr, "profiling:%s%s:Merge mismatch for %s\n",
245+ gcov_prefix, gi_ptr->filename,
246 f_ix + 1 ? "function" : "summaries");
247 goto read_fatal;
248 }
249@@ -305,7 +376,8 @@ gcov_exit (void)
250
251 read_error:;
252 fprintf (stderr, error < 0 ? "profiling:%s:Overflow merging\n"
253- : "profiling:%s:Error merging\n", gi_ptr->filename);
254+ : "profiling:%s%s:Error merging\n", gcov_prefix,
255+ gi_ptr->filename);
256
257 read_fatal:;
258 gcov_close ();
259@@ -355,8 +427,8 @@ gcov_exit (void)
260 && (!GCOV_LOCKED || cs_all->runs == cs_prg->runs)
261 && memcmp (cs_all, cs_prg, sizeof (*cs_all)))
262 {
263- fprintf (stderr, "profiling:%s:Invocation mismatch - some data files may have been removed%s",
264- gi_ptr->filename, GCOV_LOCKED
265+ fprintf (stderr, "profiling:%s%s:Invocation mismatch - some data files may have been removed%s",
266+ gcov_prefix, gi_ptr->filename, GCOV_LOCKED
267 ? "" : " or concurrent update without locking support");
268 all.checksum = ~0u;
269 }
270@@ -419,9 +491,9 @@ gcov_exit (void)
271 gcov_write_unsigned (0);
272 if ((error = gcov_close ()))
273 fprintf (stderr, error < 0 ?
274- "profiling:%s:Overflow writing\n" :
275- "profiling:%s:Error writing\n",
276- gi_ptr->filename);
277+ "profiling:%s%s:Overflow writing\n" :
278+ "profiling:%s%s:Error writing\n",
279+ gcov_prefix, gi_ptr->filename);
280 }
281 }
282
283@@ -431,11 +503,69 @@ gcov_exit (void)
284 void
285 __gcov_init (struct gcov_info *info)
286 {
287+ /* Save initial filename pointer to calculate CRC. */
288+ const char *ptr = info->filename;
289+
290 if (!info->version)
291 return;
292+
293+ /* Initialize directory prefix if requred */
294+ if (gcov_prefix == 0)
295+ {
296+ if ((gcov_prefix = getenv("GCOV_PREFIX")))
297+ {
298+ char *tmp;
299+
300+ /* Normalize prefix: take off trailing separator. */
301+ tmp = gcov_prefix + strlen(gcov_prefix) - 1;
302+ if (IS_DIR_SEPARATOR(*tmp))
303+ *tmp = '\0';
304+
305+ /* Check if the level of dirs to strip off specified */
306+ if ((tmp = getenv("GCOV_PREFIX_STRIP")))
307+ {
308+ gcov_prefix_strip = atoi (tmp);
309+ /* Do not consider negative values. */
310+ if (gcov_prefix_strip < 0)
311+ gcov_prefix_strip = 0;
312+ };
313+ }
314+ else
315+ gcov_prefix = (char *) "";
316+ };
317+
318+ /* Strip off leading directories from the initial filename */
319+ if (gcov_prefix_strip > 0)
320+ {
321+ char sep, *s;
322+ int level;
323+ const char *fname = info->filename;
324+
325+ /* Detect directory separator */
326+ s = strrchr (fname, DIR_SEPARATOR);
327+#ifdef DIR_SEPARATOR_2
328+ if (! s)
329+ s = strrchr (fname, DIR_SEPARATOR_2);
330+#endif
331+ if (s)
332+ sep = *s;
333+ else
334+ sep = DIR_SEPARATOR;
335+
336+ /* Skip selected directory levels */
337+ for ( level = gcov_prefix_strip; level > 0; level--)
338+ if ((s = strchr(fname + 1, sep)))
339+ fname = s;
340+ else
341+ break;
342+
343+ /* From this point info block refers stripped file name and
344+ further operations must add prefix to get complete name.*/
345+ info->filename = fname;
346+ };
347+
348 if (gcov_version (info, info->version))
349 {
350- const char *ptr = info->filename;
351 gcov_unsigned_t crc32 = gcov_crc32;
352
353 do
354--- gcc-4/gcc/tsystem.h.prefix 2005-03-29 16:06:26.000000000 -0800
355+++ gcc-4/gcc/tsystem.h 2005-05-04 15:07:44.000000000 -0700
356@@ -131,4 +131,15 @@ extern int errno;
357 unreachable default case of a switch. Do not use gcc_assert(0). */
358 #define gcc_unreachable() (abort ())
359
360+/* Filename handling macros. */
361+#include "filenames.h"
362+
363+/* These should be phased out in favor of IS_DIR_SEPARATOR, where possible. */
364+#ifndef DIR_SEPARATOR
365+# define DIR_SEPARATOR '/'
366+# ifdef HAVE_DOS_BASED_FILE_SYSTEM
367+# define DIR_SEPARATOR_2 '\\'
368+# endif
369+#endif
370+
371 #endif /* ! GCC_TSYSTEM_H */