Do not error when -E provided (PR pch/78970).
[official-gcc.git] / libgo / runtime / go-fieldtrack.c
blob2b3ac325c10e4264ae465ab181ef9fa05754bea6
1 /* go-fieldtrack.c -- structure field data analysis.
3 Copyright 2012 The Go Authors. All rights reserved.
4 Use of this source code is governed by a BSD-style
5 license that can be found in the LICENSE file. */
7 #include "runtime.h"
8 #include "go-type.h"
10 /* The compiler will track fields that have the tag go:"track". Any
11 function that refers to such a field will call this function with a
12 string
13 fieldtrack "package.type.field"
15 This function does not actually do anything. Instead, we gather
16 the field tracking information by looking for strings of that form
17 in the read-only data section. This is, of course, a horrible
18 hack, but it's good enough for now. We can improve it, e.g., by a
19 linker plugin, if this turns out to be useful. */
21 void
22 __go_fieldtrack (byte *p __attribute__ ((unused)))
26 /* A runtime function to add all the tracked fields to a
27 map[string]bool. */
29 extern const char _etext[] __attribute__ ((weak));
30 extern const char __etext[] __attribute__ ((weak));
31 extern const char __data_start[] __attribute__ ((weak));
32 extern const char _edata[] __attribute__ ((weak));
33 extern const char __edata[] __attribute__ ((weak));
34 extern const char __bss_start[] __attribute__ ((weak));
36 extern void mapassign1 (const struct __go_map_type *, void *hmap,
37 const void *key, const void *val)
38 __asm__ (GOSYM_PREFIX "runtime.mapassign1");
40 // The type descriptor for map[string] bool. */
41 extern const char __go_td_MN6_string__N4_bool[] __attribute__ ((weak));
43 void runtime_Fieldtrack (void *) __asm__ (GOSYM_PREFIX "runtime.Fieldtrack");
45 void
46 runtime_Fieldtrack (void *m)
48 const char *p;
49 const char *pend;
50 const char *prefix;
51 size_t prefix_len;
53 if (__go_td_MN6_string__N4_bool == NULL)
54 return;
56 p = __data_start;
57 if (p == NULL)
58 p = __etext;
59 if (p == NULL)
60 p = _etext;
61 if (p == NULL)
62 return;
64 pend = __edata;
65 if (pend == NULL)
66 pend = _edata;
67 if (pend == NULL)
68 pend = __bss_start;
69 if (pend == NULL)
70 return;
72 prefix = "fieldtrack ";
73 prefix_len = __builtin_strlen (prefix);
75 while (p < pend)
77 const char *q1;
78 const char *q2;
80 q1 = __builtin_memchr (p + prefix_len, '"', pend - (p + prefix_len));
81 if (q1 == NULL)
82 break;
84 if (__builtin_memcmp (q1 - prefix_len, prefix, prefix_len) != 0)
86 p = q1 + 1;
87 continue;
90 q1++;
91 q2 = __builtin_memchr (q1, '"', pend - q1);
92 if (q2 == NULL)
93 break;
95 if (__builtin_memchr (q1, '\0', q2 - q1) == NULL)
97 String s;
98 _Bool b;
100 s.str = (const byte *) q1;
101 s.len = q2 - q1;
102 b = 1;
103 mapassign1((const void*) __go_td_MN6_string__N4_bool, m, &s, &b);
106 p = q2;