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