stdlib: Improve fortify with clang
[glibc.git] / scripts / gen-tunables.awk
blob9f5336381e9b34764305ebc7a4e1d2e8b8697d7b
1 # Generate dl-tunable-list.h from dl-tunables.list
3 BEGIN {
4 min_of["STRING"]="0"
5 max_of["STRING"]="0"
6 min_of["INT_32"]="INT32_MIN"
7 max_of["INT_32"]="INT32_MAX"
8 min_of["UINT_64"]="0"
9 max_of["UINT_64"]="UINT64_MAX"
10 min_of["SIZE_T"]="0"
11 max_of["SIZE_T"]="SIZE_MAX"
12 tunable=""
13 ns=""
14 top_ns=""
15 max_name_len=0
16 max_alias_len=0
19 # Skip over blank lines and comments.
20 /^#/ {
21 next
24 /^[ \t]*$/ {
25 next
28 # Beginning of either a top namespace, tunable namespace or a tunable, decided
29 # on the current value of TUNABLE, NS or TOP_NS.
30 $2 == "{" {
31 if (top_ns == "") {
32 top_ns = $1
34 else if (ns == "") {
35 ns = $1
37 else if (tunable == "") {
38 tunable = $1
40 else {
41 printf ("Unexpected occurrence of '{': %s:%d\n", FILENAME, FNR)
42 exit 1
45 next
48 # End of either a top namespace, tunable namespace or a tunable.
49 $1 == "}" {
50 if (tunable != "") {
51 # Tunables definition ended, now fill in default attributes.
52 if (!types[top_ns,ns,tunable]) {
53 types[top_ns,ns,tunable] = "STRING"
55 if (!minvals[top_ns,ns,tunable]) {
56 minvals[top_ns,ns,tunable] = min_of[types[top_ns,ns,tunable]]
58 if (!maxvals[top_ns,ns,tunable]) {
59 maxvals[top_ns,ns,tunable] = max_of[types[top_ns,ns,tunable]]
61 if (!env_alias[top_ns,ns,tunable]) {
62 env_alias[top_ns,ns,tunable] = "{0}"
64 len = length(top_ns"."ns"."tunable)
65 if (len > max_name_len)
66 max_name_len = len
68 tunable = ""
70 else if (ns != "") {
71 ns = ""
73 else if (top_ns != "") {
74 top_ns = ""
76 else {
77 printf ("syntax error: extra }: %s:%d\n", FILENAME, FNR)
78 exit 1
80 next
83 # Everything else, which could either be a tunable without any attributes or a
84 # tunable attribute.
86 if (ns == "") {
87 printf("Line %d: Invalid tunable outside a namespace: %s\n", NR, $0)
88 exit 1
91 if (tunable == "") {
92 # We encountered a tunable without any attributes, so note it with a
93 # default.
94 types[top_ns,ns,$1] = "STRING"
95 next
98 # Otherwise, we have encountered a tunable attribute.
99 split($0, arr, ":")
100 attr = gensub(/^[ \t]+|[ \t]+$/, "", "g", arr[1])
101 val = gensub(/^[ \t]+|[ \t]+$/, "", "g", arr[2])
103 if (attr == "type") {
104 types[top_ns,ns,tunable] = val
106 else if (attr == "minval") {
107 minvals[top_ns,ns,tunable] = val
109 else if (attr == "maxval") {
110 maxvals[top_ns,ns,tunable] = val
112 else if (attr == "env_alias") {
113 env_alias[top_ns,ns,tunable] = sprintf("\"%s\"", val)
114 len = length(val)
115 if (len > max_alias_len)
116 max_alias_len = len
118 else if (attr == "default") {
119 if (types[top_ns,ns,tunable] == "STRING") {
120 default_val[top_ns,ns,tunable] = sprintf(".strval = \"%s\"", val);
122 else {
123 default_val[top_ns,ns,tunable] = sprintf(".numval = %s", val)
128 END {
129 if (ns != "") {
130 print "Unterminated namespace. Is a closing brace missing?"
131 exit 1
134 print "/* AUTOGENERATED by gen-tunables.awk. */"
135 print "#ifndef _TUNABLES_H_"
136 print "# error \"Do not include this file directly.\""
137 print "# error \"Include tunables.h instead.\""
138 print "#endif"
139 print "#include <dl-procinfo.h>\n"
141 # Now, the enum names
142 print "\ntypedef enum"
143 print "{"
144 for (tnm in types) {
145 split (tnm, indices, SUBSEP);
146 t = indices[1];
147 n = indices[2];
148 m = indices[3];
149 printf (" TUNABLE_ENUM_NAME(%s, %s, %s),\n", t, n, m);
151 print "} tunable_id_t;\n"
153 print "\n#ifdef TUNABLES_INTERNAL"
154 # Internal definitions.
155 print "# define TUNABLE_NAME_MAX " (max_name_len + 1)
156 print "# define TUNABLE_ALIAS_MAX " (max_alias_len + 1)
157 print "# include \"dl-tunable-types.h\""
158 # Finally, the tunable list.
159 print "static tunable_t tunable_list[] attribute_relro = {"
160 for (tnm in types) {
161 split (tnm, indices, SUBSEP);
162 t = indices[1];
163 n = indices[2];
164 m = indices[3];
165 printf (" {TUNABLE_NAME_S(%s, %s, %s)", t, n, m)
166 printf (", {TUNABLE_TYPE_%s, %s, %s}, {%s}, {%s}, false, %s},\n",
167 types[t,n,m], minvals[t,n,m], maxvals[t,n,m], default_val[t,n,m],
168 default_val[t,n,m], env_alias[t,n,m]);
170 print "};"
171 print "#endif"