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