* gcc.dg/ipa/inlinehint-4.c: Also pass --param inline-unit-growth=20.
[official-gcc.git] / libgo / runtime / go-fieldtrack.c
blob7be259e45054112ac274ba53ae5c40b140338b6c
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 _edata[] __attribute__ ((weak));
31 #ifdef _AIX
32 // Following symbols do not exist on AIX
33 const char *__etext = NULL;
34 const char *__data_start = NULL;
35 const char *__edata = NULL;
36 const char *__bss_start = NULL;
37 #else
38 extern const char __etext[] __attribute__ ((weak));
39 extern const char __data_start[] __attribute__ ((weak));
40 extern const char __edata[] __attribute__ ((weak));
41 extern const char __bss_start[] __attribute__ ((weak));
42 #endif
44 extern void *mapassign (const struct __go_map_type *, void *hmap,
45 const void *key)
46 __asm__ (GOSYM_PREFIX "runtime.mapassign");
48 // The type descriptor for map[string] bool. */
49 extern const char __go_td_MN6_string__N4_bool[] __attribute__ ((weak));
51 void runtime_Fieldtrack (void *) __asm__ (GOSYM_PREFIX "runtime.Fieldtrack");
53 void
54 runtime_Fieldtrack (void *m)
56 const char *p;
57 const char *pend;
58 const char *prefix;
59 size_t prefix_len;
61 if (__go_td_MN6_string__N4_bool == NULL)
62 return;
64 p = __data_start;
65 if (p == NULL)
66 p = __etext;
67 if (p == NULL)
68 p = _etext;
69 if (p == NULL)
70 return;
72 pend = __edata;
73 if (pend == NULL)
74 pend = _edata;
75 if (pend == NULL)
76 pend = __bss_start;
77 if (pend == NULL)
78 return;
80 prefix = "fieldtrack ";
81 prefix_len = __builtin_strlen (prefix);
83 while (p < pend)
85 const char *q1;
86 const char *q2;
88 q1 = __builtin_memchr (p + prefix_len, '"', pend - (p + prefix_len));
89 if (q1 == NULL)
90 break;
92 if (__builtin_memcmp (q1 - prefix_len, prefix, prefix_len) != 0)
94 p = q1 + 1;
95 continue;
98 q1++;
99 q2 = __builtin_memchr (q1, '"', pend - q1);
100 if (q2 == NULL)
101 break;
103 if (__builtin_memchr (q1, '\0', q2 - q1) == NULL)
105 String s;
106 void *p;
108 s.str = (const byte *) q1;
109 s.len = q2 - q1;
110 p = mapassign((const void*) __go_td_MN6_string__N4_bool, m, &s);
111 *(_Bool*)p = 1;
114 p = q2;