Small ChangeLog tweak.
[official-gcc.git] / libgo / mkrsysinfo.sh
bloba86e9143bf4622c94989e7a085171ce5f8432dca
1 #!/bin/sh
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.
7 # Create runtime_sysinfo.go from gen-sysinfo.go and errno.i.
9 OUT=tmp-runtime_sysinfo.go
11 set -e
13 echo 'package runtime' > ${OUT}
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 'in6_addr' | \
27 grep -v 'sockaddr_in6' | \
28 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1timeval\2/g' \
29 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1timespec\2/g' \
30 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1timespec\2/g' \
31 >> ${OUT}
33 # On AIX, the _arpcom struct, is filtered by the above grep sequence, as it as
34 # a field of type _in6_addr, but other types depend on _arpcom, so we need to
35 # put it back.
36 grep '^type _arpcom ' gen-sysinfo.go | \
37 sed -e 's/_in6_addr/[16]byte/' >> ${OUT}
39 # The time structures need special handling: we need to name the
40 # types, so that we can cast integers to the right types when
41 # assigning to the structures.
42 timeval=`grep '^type _timeval ' gen-sysinfo.go`
43 timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
44 timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
45 echo "type timeval_sec_t $timeval_sec" >> ${OUT}
46 echo "type timeval_usec_t $timeval_usec" >> ${OUT}
47 echo $timeval | \
48 sed -e 's/type _timeval /type timeval /' \
49 -e 's/tv_sec *[a-zA-Z0-9_]*/tv_sec timeval_sec_t/' \
50 -e 's/tv_usec *[a-zA-Z0-9_]*/tv_usec timeval_usec_t/' >> ${OUT}
51 echo >> ${OUT}
52 echo "func (tv *timeval) set_usec(x int32) {" >> ${OUT}
53 echo " tv.tv_usec = timeval_usec_t(x)" >> ${OUT}
54 echo "}" >> ${OUT}
56 timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
57 if test "$timespec" = ""; then
58 # IRIX 6.5 has __timespec instead.
59 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
61 timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
62 timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
63 echo "type timespec_sec_t $timespec_sec" >> ${OUT}
64 echo "type timespec_nsec_t $timespec_nsec" >> ${OUT}
65 echo $timespec | \
66 sed -e 's/^type ___timespec /type timespec /' \
67 -e 's/^type _timespec /type timespec /' \
68 -e 's/tv_sec *[a-zA-Z0-9_]*/tv_sec timespec_sec_t/' \
69 -e 's/tv_nsec *[a-zA-Z0-9_]*/tv_nsec timespec_nsec_t/' >> ${OUT}
70 echo >> ${OUT}
71 echo "func (ts *timespec) set_sec(x int64) {" >> ${OUT}
72 echo " ts.tv_sec = timespec_sec_t(x)" >> ${OUT}
73 echo "}" >> ${OUT}
74 echo >> ${OUT}
75 echo "func (ts *timespec) set_nsec(x int32) {" >> ${OUT}
76 echo " ts.tv_nsec = timespec_nsec_t(x)" >> ${OUT}
77 echo "}" >> ${OUT}
79 # Define the epollevent struct. This needs special attention because
80 # the C definition uses a union and is sometimes packed.
81 if grep '^const _epoll_data_offset ' ${OUT} >/dev/null 2>&1; then
82 val=`grep '^const _epoll_data_offset ' ${OUT} | sed -e 's/const _epoll_data_offset = \(.*\)$/\1/'`
83 if test "$val" = "4"; then
84 echo 'type epollevent struct { events uint32; data [8]byte }' >> ${OUT}
85 elif test "$val" = "8"; then
86 echo 'type epollevent struct { events uint32; pad [4]byte; data [8]byte }' >> ${OUT}
87 else
88 echo 1>&2 "unknown epoll data offset value ${val}"
89 exit 1
92 # Make sure EPOLLET is positive.
93 if grep '^const _EPOLLET = [0-9]' gen-sysinfo.go > /dev/null 2>&1; then
94 echo "const _EPOLLETpos = _EPOLLET" >> ${OUT}
95 else
96 echo "const _EPOLLETpos = 0x80000000" >> ${OUT}
98 # Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
99 if ! grep '^const _EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
100 echo "const _EPOLLRDHUP = 0x2000" >> ${OUT}
102 if ! grep '^const _EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
103 echo "const _EPOLL_CLOEXEC = 02000000" >> ${OUT}
106 # AIX 7.1 is a 64 bits value for _FCLOEXEC (referenced by O_CLOEXEC)
107 # which leads to a constant overflow when using O_CLOEXEC in some
108 # go code. Issue wan not present in 6.1 (no O_CLOEXEC) and is no
109 # more present in 7.2 (_FCLOEXEC is a 32 bit value).
110 if test "${GOOS}" = "aix" && `oslevel | grep -q "^7.1"`; then
111 sed -e 's/const __FCLOEXEC = .*/const __FCLOEXEC = 0/' ${OUT} > ${OUT}-2
112 mv ${OUT}-2 ${OUT}
115 # Make sure _MAP_FAILED is defined.
116 if ! grep '^const _MAP_FAILED =' gen-sysinfo.go > /dev/null 2>&1; then
117 echo "const _MAP_FAILED = ^uintptr(0)" >> ${OUT}
119 # Make sure _MAP_ANON is defined.
120 if ! grep '^const _MAP_ANON =' gen-sysinfo.go > /dev/null 2>&1; then
121 if grep '^const _MAP_ANONYMOUS ' gen-sysinfo.go > /dev/null 2>&1; then
122 echo "const _MAP_ANON = _MAP_ANONYMOUS" >> ${OUT}
123 else
124 echo "const _MAP_ANON = 0" >> ${OUT}
127 # Make sure _MADV_DONTNEED is defined.
128 if ! grep '^const _MADV_DONTNEED =' gen-sysinfo.go > /dev/null 2>&1; then
129 echo "const _MADV_DONTNEED = 0" >> ${OUT}
131 # Make sure _MADV_FREE is defined.
132 if ! grep '^const _MADV_FREE =' gen-sysinfo.go > /dev/null 2>&1; then
133 echo "const _MADV_FREE = 0" >> ${OUT}
135 # Make sure _MADV_HUGEPAGE is defined.
136 if ! grep '^const _MADV_HUGEPAGE =' gen-sysinfo.go > /dev/null 2>&1; then
137 echo "const _MADV_HUGEPAGE = 0" >> ${OUT}
139 # Make sure _MADV_NOHUGEPAGE is defined.
140 if ! grep '^const _MADV_NOHUGEPAGE =' gen-sysinfo.go > /dev/null 2>&1; then
141 echo "const _MADV_NOHUGEPAGE = 0" >> ${OUT}
144 # The semt structure, for Solaris.
145 grep '^type _sem_t ' gen-sysinfo.go | \
146 sed -e 's/_sem_t/semt/' >> ${OUT}
148 # Solaris 2 needs _u?pad128_t, but its default definition in terms of long
149 # double is commented by -fdump-go-spec.
150 if grep "^// type _pad128_t" gen-sysinfo.go > /dev/null 2>&1; then
151 echo "type _pad128_t struct { _l [4]int32; }" >> ${OUT}
153 if grep "^// type _upad128_t" gen-sysinfo.go > /dev/null 2>&1; then
154 echo "type _upad128_t struct { _l [4]uint32; }" >> ${OUT}
157 # The Solaris 11 Update 1 _zone_net_addr_t struct.
158 grep '^type _zone_net_addr_t ' gen-sysinfo.go | \
159 sed -e 's/_in6_addr/[16]byte/' \
160 >> ${OUT}
162 # The Solaris 12 _flow_arp_desc_t struct.
163 grep '^type _flow_arp_desc_t ' gen-sysinfo.go | \
164 sed -e 's/_in6_addr_t/[16]byte/g' \
165 >> ${OUT}
167 # The Solaris 12 _flow_l3_desc_t struct.
168 grep '^type _flow_l3_desc_t ' gen-sysinfo.go | \
169 sed -e 's/_in6_addr_t/[16]byte/g' \
170 >> ${OUT}
172 # The Solaris 12 _mac_ipaddr_t struct.
173 grep '^type _mac_ipaddr_t ' gen-sysinfo.go | \
174 sed -e 's/_in6_addr_t/[16]byte/g' \
175 >> ${OUT}
177 # The Solaris 12 _mactun_info_t struct.
178 grep '^type _mactun_info_t ' gen-sysinfo.go | \
179 sed -e 's/_in6_addr_t/[16]byte/g' \
180 >> ${OUT}
182 # The Solaris port_event_t struct.
183 grep '^type _port_event_t ' gen-sysinfo.go | \
184 sed -e s'/_port_event_t/portevent/' \
185 >> ${OUT}
187 # The *BSD kevent struct.
188 grep '^type _kevent ' gen-sysinfo.go | \
189 sed -e s'/_kevent/keventt/' \
190 -e 's/ udata [^;}]*/ udata *byte/' \
191 >> ${OUT}