annotate libgo/mkrsysinfo.sh @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 #!/bin/sh
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 # Copyright 2016 The Go Authors. All rights reserved.
kono
parents:
diff changeset
4 # Use of this source code is governed by a BSD-style
kono
parents:
diff changeset
5 # license that can be found in the LICENSE file.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 # Create runtime_sysinfo.go from gen-sysinfo.go and errno.i.
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 OUT=tmp-runtime_sysinfo.go
kono
parents:
diff changeset
10
kono
parents:
diff changeset
11 set -e
kono
parents:
diff changeset
12
kono
parents:
diff changeset
13 echo 'package runtime' > ${OUT}
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 # Get all the consts and types, skipping ones which could not be
kono
parents:
diff changeset
16 # represented in Go and ones which we need to rewrite. We also skip
kono
parents:
diff changeset
17 # function declarations, as we don't need them here. All the symbols
kono
parents:
diff changeset
18 # will all have a leading underscore.
kono
parents:
diff changeset
19 grep -v '^// ' gen-sysinfo.go | \
kono
parents:
diff changeset
20 grep -v '^func' | \
kono
parents:
diff changeset
21 grep -v '^var ' | \
kono
parents:
diff changeset
22 grep -v '^type _timeval ' | \
kono
parents:
diff changeset
23 grep -v '^type _timespec_t ' | \
kono
parents:
diff changeset
24 grep -v '^type _timespec ' | \
kono
parents:
diff changeset
25 grep -v '^type _epoll_' | \
kono
parents:
diff changeset
26 grep -v '^type _*locale[_ ]' | \
kono
parents:
diff changeset
27 grep -v 'in6_addr' | \
kono
parents:
diff changeset
28 grep -v 'sockaddr_in6' | \
kono
parents:
diff changeset
29 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1timeval\2/g' \
kono
parents:
diff changeset
30 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1timespec\2/g' \
kono
parents:
diff changeset
31 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1timespec\2/g' \
kono
parents:
diff changeset
32 >> ${OUT}
kono
parents:
diff changeset
33
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
34 # The C long type, needed because that is the type that ptrace returns.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
35 sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
36 if test "$sizeof_long" = "4"; then
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
37 echo "type _C_long int32" >> ${OUT}
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
38 echo "type _C_ulong uint32" >> ${OUT}
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
39 elif test "$sizeof_long" = "8"; then
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
40 echo "type _C_long int64" >> ${OUT}
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
41 echo "type _C_ulong uint64" >> ${OUT}
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
42 else
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
43 echo 1>&2 "mkrsysinfo.sh: could not determine size of long (got $sizeof_long)"
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
44 exit 1
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
45 fi
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
46
111
kono
parents:
diff changeset
47 # On AIX, the _arpcom struct, is filtered by the above grep sequence, as it as
kono
parents:
diff changeset
48 # a field of type _in6_addr, but other types depend on _arpcom, so we need to
kono
parents:
diff changeset
49 # put it back.
kono
parents:
diff changeset
50 grep '^type _arpcom ' gen-sysinfo.go | \
kono
parents:
diff changeset
51 sed -e 's/_in6_addr/[16]byte/' >> ${OUT}
kono
parents:
diff changeset
52
kono
parents:
diff changeset
53 # Same on Solaris for _mld_hdr_t.
kono
parents:
diff changeset
54 grep '^type _mld_hdr_t ' gen-sysinfo.go | \
kono
parents:
diff changeset
55 sed -e 's/_in6_addr/[16]byte/' >> ${OUT}
kono
parents:
diff changeset
56
kono
parents:
diff changeset
57 # The time structures need special handling: we need to name the
kono
parents:
diff changeset
58 # types, so that we can cast integers to the right types when
kono
parents:
diff changeset
59 # assigning to the structures.
kono
parents:
diff changeset
60 timeval=`grep '^type _timeval ' gen-sysinfo.go`
kono
parents:
diff changeset
61 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
kono
parents:
diff changeset
62 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
kono
parents:
diff changeset
63 echo "type timeval_sec_t $timeval_sec" >> ${OUT}
kono
parents:
diff changeset
64 echo "type timeval_usec_t $timeval_usec" >> ${OUT}
kono
parents:
diff changeset
65 echo $timeval | \
kono
parents:
diff changeset
66 sed -e 's/type _timeval /type timeval /' \
kono
parents:
diff changeset
67 -e 's/tv_sec *[a-zA-Z0-9_]*/tv_sec timeval_sec_t/' \
kono
parents:
diff changeset
68 -e 's/tv_usec *[a-zA-Z0-9_]*/tv_usec timeval_usec_t/' >> ${OUT}
kono
parents:
diff changeset
69 echo >> ${OUT}
kono
parents:
diff changeset
70 echo "func (tv *timeval) set_usec(x int32) {" >> ${OUT}
kono
parents:
diff changeset
71 echo " tv.tv_usec = timeval_usec_t(x)" >> ${OUT}
kono
parents:
diff changeset
72 echo "}" >> ${OUT}
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
kono
parents:
diff changeset
75 if test "$timespec" = ""; then
kono
parents:
diff changeset
76 # IRIX 6.5 has __timespec instead.
kono
parents:
diff changeset
77 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
kono
parents:
diff changeset
78 fi
kono
parents:
diff changeset
79 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
kono
parents:
diff changeset
80 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
kono
parents:
diff changeset
81 echo "type timespec_sec_t $timespec_sec" >> ${OUT}
kono
parents:
diff changeset
82 echo "type timespec_nsec_t $timespec_nsec" >> ${OUT}
kono
parents:
diff changeset
83 echo $timespec | \
kono
parents:
diff changeset
84 sed -e 's/^type ___timespec /type timespec /' \
kono
parents:
diff changeset
85 -e 's/^type _timespec /type timespec /' \
kono
parents:
diff changeset
86 -e 's/tv_sec *[a-zA-Z0-9_]*/tv_sec timespec_sec_t/' \
kono
parents:
diff changeset
87 -e 's/tv_nsec *[a-zA-Z0-9_]*/tv_nsec timespec_nsec_t/' >> ${OUT}
kono
parents:
diff changeset
88 echo >> ${OUT}
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
89 echo "func (ts *timespec) setNsec(ns int64) {" >> ${OUT}
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
90 echo " ts.tv_sec = timespec_sec_t(ns / 1e9)" >> ${OUT}
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
91 echo " ts.tv_nsec = timespec_nsec_t(ns % 1e9)" >> ${OUT}
111
kono
parents:
diff changeset
92 echo "}" >> ${OUT}
kono
parents:
diff changeset
93 echo >> ${OUT}
kono
parents:
diff changeset
94
kono
parents:
diff changeset
95 # Define the epollevent struct. This needs special attention because
kono
parents:
diff changeset
96 # the C definition uses a union and is sometimes packed.
kono
parents:
diff changeset
97 if grep '^const _epoll_data_offset ' ${OUT} >/dev/null 2>&1; then
kono
parents:
diff changeset
98 val=`grep '^const _epoll_data_offset ' ${OUT} | sed -e 's/const _epoll_data_offset = \(.*\)$/\1/'`
kono
parents:
diff changeset
99 if test "$val" = "4"; then
kono
parents:
diff changeset
100 echo 'type epollevent struct { events uint32; data [8]byte }' >> ${OUT}
kono
parents:
diff changeset
101 elif test "$val" = "8"; then
kono
parents:
diff changeset
102 if test "$GOARCH" = "sparc64" -a "$GOOS" = "linux"; then
kono
parents:
diff changeset
103 echo 'type epollevent struct { events uint32; pad [4]byte; data [8]byte; _align [0]int64 }' >> ${OUT}
kono
parents:
diff changeset
104 else
kono
parents:
diff changeset
105 echo 'type epollevent struct { events uint32; pad [4]byte; data [8]byte }' >> ${OUT}
kono
parents:
diff changeset
106 fi
kono
parents:
diff changeset
107 else
kono
parents:
diff changeset
108 echo 1>&2 "unknown epoll data offset value ${val}"
kono
parents:
diff changeset
109 exit 1
kono
parents:
diff changeset
110 fi
kono
parents:
diff changeset
111 fi
kono
parents:
diff changeset
112 # Make sure EPOLLET is positive.
kono
parents:
diff changeset
113 if grep '^const _EPOLLET = [0-9]' gen-sysinfo.go > /dev/null 2>&1; then
kono
parents:
diff changeset
114 echo "const _EPOLLETpos = _EPOLLET" >> ${OUT}
kono
parents:
diff changeset
115 else
kono
parents:
diff changeset
116 echo "const _EPOLLETpos = 0x80000000" >> ${OUT}
kono
parents:
diff changeset
117 fi
kono
parents:
diff changeset
118 # Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
kono
parents:
diff changeset
119 if ! grep '^const _EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
kono
parents:
diff changeset
120 echo "const _EPOLLRDHUP = 0x2000" >> ${OUT}
kono
parents:
diff changeset
121 fi
kono
parents:
diff changeset
122 if ! grep '^const _EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
kono
parents:
diff changeset
123 echo "const _EPOLL_CLOEXEC = 02000000" >> ${OUT}
kono
parents:
diff changeset
124 fi
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 # AIX 7.1 is a 64 bits value for _FCLOEXEC (referenced by O_CLOEXEC)
kono
parents:
diff changeset
127 # which leads to a constant overflow when using O_CLOEXEC in some
kono
parents:
diff changeset
128 # go code. Issue wan not present in 6.1 (no O_CLOEXEC) and is no
kono
parents:
diff changeset
129 # more present in 7.2 (_FCLOEXEC is a 32 bit value).
kono
parents:
diff changeset
130 if test "${GOOS}" = "aix" && `oslevel | grep -q "^7.1"`; then
kono
parents:
diff changeset
131 sed -e 's/const __FCLOEXEC = .*/const __FCLOEXEC = 0/' ${OUT} > ${OUT}-2
kono
parents:
diff changeset
132 mv ${OUT}-2 ${OUT}
kono
parents:
diff changeset
133 fi
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 # Make sure _MAP_FAILED is defined.
kono
parents:
diff changeset
136 if ! grep '^const _MAP_FAILED =' gen-sysinfo.go > /dev/null 2>&1; then
kono
parents:
diff changeset
137 echo "const _MAP_FAILED = ^uintptr(0)" >> ${OUT}
kono
parents:
diff changeset
138 fi
kono
parents:
diff changeset
139 # Make sure _MAP_ANON is defined.
kono
parents:
diff changeset
140 if ! grep '^const _MAP_ANON =' gen-sysinfo.go > /dev/null 2>&1; then
kono
parents:
diff changeset
141 if grep '^const _MAP_ANONYMOUS ' gen-sysinfo.go > /dev/null 2>&1; then
kono
parents:
diff changeset
142 echo "const _MAP_ANON = _MAP_ANONYMOUS" >> ${OUT}
kono
parents:
diff changeset
143 else
kono
parents:
diff changeset
144 echo "const _MAP_ANON = 0" >> ${OUT}
kono
parents:
diff changeset
145 fi
kono
parents:
diff changeset
146 fi
kono
parents:
diff changeset
147 # Make sure _MADV_DONTNEED is defined.
kono
parents:
diff changeset
148 if ! grep '^const _MADV_DONTNEED =' gen-sysinfo.go > /dev/null 2>&1; then
kono
parents:
diff changeset
149 echo "const _MADV_DONTNEED = 0" >> ${OUT}
kono
parents:
diff changeset
150 fi
kono
parents:
diff changeset
151 # Make sure _MADV_FREE is defined.
kono
parents:
diff changeset
152 if ! grep '^const _MADV_FREE =' gen-sysinfo.go > /dev/null 2>&1; then
kono
parents:
diff changeset
153 echo "const _MADV_FREE = 0" >> ${OUT}
kono
parents:
diff changeset
154 fi
kono
parents:
diff changeset
155 # Make sure _MADV_HUGEPAGE is defined.
kono
parents:
diff changeset
156 if ! grep '^const _MADV_HUGEPAGE =' gen-sysinfo.go > /dev/null 2>&1; then
kono
parents:
diff changeset
157 echo "const _MADV_HUGEPAGE = 0" >> ${OUT}
kono
parents:
diff changeset
158 fi
kono
parents:
diff changeset
159 # Make sure _MADV_NOHUGEPAGE is defined.
kono
parents:
diff changeset
160 if ! grep '^const _MADV_NOHUGEPAGE =' gen-sysinfo.go > /dev/null 2>&1; then
kono
parents:
diff changeset
161 echo "const _MADV_NOHUGEPAGE = 0" >> ${OUT}
kono
parents:
diff changeset
162 fi
kono
parents:
diff changeset
163
kono
parents:
diff changeset
164 # The semt structure, for Solaris.
kono
parents:
diff changeset
165 grep '^type _sem_t ' gen-sysinfo.go | \
kono
parents:
diff changeset
166 sed -e 's/_sem_t/semt/' >> ${OUT}
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
kono
parents:
diff changeset
169 # double is commented by -fdump-go-spec.
kono
parents:
diff changeset
170 if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
kono
parents:
diff changeset
171 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
kono
parents:
diff changeset
172 fi
kono
parents:
diff changeset
173 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
kono
parents:
diff changeset
174 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
kono
parents:
diff changeset
175 fi
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 # The Solaris 11 Update 1 _zone_net_addr_t struct.
kono
parents:
diff changeset
178 grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
kono
parents:
diff changeset
179 sed -e 's/_in6_addr/[16]byte/' \
kono
parents:
diff changeset
180 >> ${OUT}
kono
parents:
diff changeset
181
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
182 # The Solaris 11.4 _flow_arp_desc_t struct.
111
kono
parents:
diff changeset
183 grep '^type _flow_arp_desc_t ' gen-sysinfo.go | \
kono
parents:
diff changeset
184 sed -e 's/_in6_addr_t/[16]byte/g' \
kono
parents:
diff changeset
185 >> ${OUT}
kono
parents:
diff changeset
186
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
187 # The Solaris 11.4 _flow_l3_desc_t struct.
111
kono
parents:
diff changeset
188 grep '^type _flow_l3_desc_t ' gen-sysinfo.go | \
kono
parents:
diff changeset
189 sed -e 's/_in6_addr_t/[16]byte/g' \
kono
parents:
diff changeset
190 >> ${OUT}
kono
parents:
diff changeset
191
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
192 # The Solaris 11.3 _mac_ipaddr_t struct.
111
kono
parents:
diff changeset
193 grep '^type _mac_ipaddr_t ' gen-sysinfo.go | \
kono
parents:
diff changeset
194 sed -e 's/_in6_addr_t/[16]byte/g' \
kono
parents:
diff changeset
195 >> ${OUT}
kono
parents:
diff changeset
196
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
197 # The Solaris 11.3 _mactun_info_t struct.
111
kono
parents:
diff changeset
198 grep '^type _mactun_info_t ' gen-sysinfo.go | \
kono
parents:
diff changeset
199 sed -e 's/_in6_addr_t/[16]byte/g' \
kono
parents:
diff changeset
200 >> ${OUT}
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 # The Solaris port_event_t struct.
kono
parents:
diff changeset
203 grep '^type _port_event_t ' gen-sysinfo.go | \
kono
parents:
diff changeset
204 sed -e s'/_port_event_t/portevent/' \
kono
parents:
diff changeset
205 >> ${OUT}
kono
parents:
diff changeset
206
kono
parents:
diff changeset
207 # The *BSD kevent struct.
kono
parents:
diff changeset
208 grep '^type _kevent ' gen-sysinfo.go | \
kono
parents:
diff changeset
209 sed -e s'/_kevent/keventt/' \
kono
parents:
diff changeset
210 -e 's/ udata [^;}]*/ udata *byte/' \
kono
parents:
diff changeset
211 >> ${OUT}
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
212
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
213 # Type 'uint128' is needed in a couple of type definitions on arm64,such
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
214 # as _user_fpsimd_struct, _elf_fpregset_t, etc.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
215 if ! grep '^type uint128' ${OUT} > /dev/null 2>&1; then
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
216 echo "type uint128 [16]byte" >> ${OUT}
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
217 fi