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