]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgo/mkrsysinfo.sh
runtime: portable access to sigev_notify_thread_id
[thirdparty/gcc.git] / libgo / mkrsysinfo.sh
CommitLineData
c0401cf7
ILT
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' | \
5302cd02 21 grep -v '^var ' | \
c0401cf7
ILT
22 grep -v '^type _timeval ' | \
23 grep -v '^type _timespec_t ' | \
24 grep -v '^type _timespec ' | \
25 grep -v '^type _epoll_' | \
03907394 26 grep -v '^type _*locale[_ ]' | \
9bac6639 27 grep -v '^type _in6_addr' | \
c0401cf7 28 grep -v 'sockaddr_in6' | \
5128f8d0 29 egrep -v '^const _*FLT(64|128)_(NORM_)?MAX' | \
c0401cf7 30 sed -e 's/\([^a-zA-Z0-9_]\)_timeval\([^a-zA-Z0-9_]\)/\1timeval\2/g' \
9bac6639 31 -e 's/\([^a-zA-Z0-9_]\)_timeval$/\1timeval/g' \
c0401cf7 32 -e 's/\([^a-zA-Z0-9_]\)_timespec_t\([^a-zA-Z0-9_]\)/\1timespec\2/g' \
9bac6639 33 -e 's/\([^a-zA-Z0-9_]\)_timespec_t$/\1timespec_t/g' \
c0401cf7 34 -e 's/\([^a-zA-Z0-9_]\)_timespec\([^a-zA-Z0-9_]\)/\1timespec\2/g' \
9bac6639
NB
35 -e 's/\([^a-zA-Z0-9_]\)_timespec$/\1timespec/g' \
36 -e 's/\([^a-zA-Z0-9_]\)_in6_addr\([^a-zA-Z0-9_]\)/\1[16]byte\2/g' \
37 -e 's/\([^a-zA-Z0-9_]\)_in6_addr$/\1[16]byte/g' \
38 -e 's/\([^a-zA-Z0-9_]\)_in6_addr_t\([^a-zA-Z0-9_]\)/\1[16]byte\2/g' \
39 -e 's/\([^a-zA-Z0-9_]\)_in6_addr_t$/\1[16]byte/g' \
c0401cf7
ILT
40 >> ${OUT}
41
32b1d51f
ILT
42# The C long type, needed because that is the type that ptrace returns.
43sizeof_long=`grep '^const ___SIZEOF_LONG__ = ' gen-sysinfo.go | sed -e 's/.*= //'`
44if test "$sizeof_long" = "4"; then
45 echo "type _C_long int32" >> ${OUT}
46 echo "type _C_ulong uint32" >> ${OUT}
47elif test "$sizeof_long" = "8"; then
48 echo "type _C_long int64" >> ${OUT}
49 echo "type _C_ulong uint64" >> ${OUT}
50else
51 echo 1>&2 "mkrsysinfo.sh: could not determine size of long (got $sizeof_long)"
52 exit 1
53fi
54
c0401cf7
ILT
55# The time structures need special handling: we need to name the
56# types, so that we can cast integers to the right types when
57# assigning to the structures.
58timeval=`grep '^type _timeval ' gen-sysinfo.go`
59timeval_sec=`echo $timeval | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
60timeval_usec=`echo $timeval | sed -n -e 's/^.*tv_usec \([^ ]*\);.*$/\1/p'`
61echo "type timeval_sec_t $timeval_sec" >> ${OUT}
62echo "type timeval_usec_t $timeval_usec" >> ${OUT}
63echo $timeval | \
64 sed -e 's/type _timeval /type timeval /' \
65 -e 's/tv_sec *[a-zA-Z0-9_]*/tv_sec timeval_sec_t/' \
66 -e 's/tv_usec *[a-zA-Z0-9_]*/tv_usec timeval_usec_t/' >> ${OUT}
980f9a0a
ILT
67echo >> ${OUT}
68echo "func (tv *timeval) set_usec(x int32) {" >> ${OUT}
69echo " tv.tv_usec = timeval_usec_t(x)" >> ${OUT}
70echo "}" >> ${OUT}
71
c0401cf7
ILT
72timespec=`grep '^type _timespec ' gen-sysinfo.go || true`
73if test "$timespec" = ""; then
74 # IRIX 6.5 has __timespec instead.
75 timespec=`grep '^type ___timespec ' gen-sysinfo.go || true`
76fi
77timespec_sec=`echo $timespec | sed -n -e 's/^.*tv_sec \([^ ]*\);.*$/\1/p'`
78timespec_nsec=`echo $timespec | sed -n -e 's/^.*tv_nsec \([^ ]*\);.*$/\1/p'`
79echo "type timespec_sec_t $timespec_sec" >> ${OUT}
80echo "type timespec_nsec_t $timespec_nsec" >> ${OUT}
81echo $timespec | \
82 sed -e 's/^type ___timespec /type timespec /' \
83 -e 's/^type _timespec /type timespec /' \
84 -e 's/tv_sec *[a-zA-Z0-9_]*/tv_sec timespec_sec_t/' \
85 -e 's/tv_nsec *[a-zA-Z0-9_]*/tv_nsec timespec_nsec_t/' >> ${OUT}
86echo >> ${OUT}
aa8901e9
ILT
87echo "func (ts *timespec) setNsec(ns int64) {" >> ${OUT}
88echo " ts.tv_sec = timespec_sec_t(ns / 1e9)" >> ${OUT}
89echo " ts.tv_nsec = timespec_nsec_t(ns % 1e9)" >> ${OUT}
c0401cf7
ILT
90echo "}" >> ${OUT}
91echo >> ${OUT}
c0401cf7 92
812ba636
ILT
93# Define the epollevent struct. This needs special attention because
94# the C definition uses a union and is sometimes packed.
95if grep '^const _epoll_data_offset ' ${OUT} >/dev/null 2>&1; then
96 val=`grep '^const _epoll_data_offset ' ${OUT} | sed -e 's/const _epoll_data_offset = \(.*\)$/\1/'`
97 if test "$val" = "4"; then
98 echo 'type epollevent struct { events uint32; data [8]byte }' >> ${OUT}
99 elif test "$val" = "8"; then
30bc05cf 100 if test "$GOARCH" = "sparc64" -a "$GOOS" = "linux"; then
62c3f75f 101 echo 'type epollevent struct { events uint32; pad [4]byte; data [8]byte; _ [0]int64 }' >> ${OUT}
30bc05cf
ILT
102 else
103 echo 'type epollevent struct { events uint32; pad [4]byte; data [8]byte }' >> ${OUT}
104 fi
812ba636
ILT
105 else
106 echo 1>&2 "unknown epoll data offset value ${val}"
107 exit 1
108 fi
109fi
29849c91 110# Make sure EPOLLET is positive.
eae2ada5 111if grep '^const _EPOLLET = [0-9]' gen-sysinfo.go > /dev/null 2>&1; then
29849c91
ILT
112 echo "const _EPOLLETpos = _EPOLLET" >> ${OUT}
113else
114 echo "const _EPOLLETpos = 0x80000000" >> ${OUT}
115fi
812ba636
ILT
116# Make sure EPOLLRDHUP and EPOLL_CLOEXEC are defined.
117if ! grep '^const _EPOLLRDHUP' ${OUT} >/dev/null 2>&1; then
118 echo "const _EPOLLRDHUP = 0x2000" >> ${OUT}
119fi
120if ! grep '^const _EPOLL_CLOEXEC' ${OUT} >/dev/null 2>&1; then
121 echo "const _EPOLL_CLOEXEC = 02000000" >> ${OUT}
122fi
123
f163907e
ILT
124# AIX 7.1 is a 64 bits value for _FCLOEXEC (referenced by O_CLOEXEC)
125# which leads to a constant overflow when using O_CLOEXEC in some
126# go code. Issue wan not present in 6.1 (no O_CLOEXEC) and is no
127# more present in 7.2 (_FCLOEXEC is a 32 bit value).
128if test "${GOOS}" = "aix" && `oslevel | grep -q "^7.1"`; then
129 sed -e 's/const __FCLOEXEC = .*/const __FCLOEXEC = 0/' ${OUT} > ${OUT}-2
130 mv ${OUT}-2 ${OUT}
131fi
132
133# Make sure _MAP_FAILED is defined.
134if ! grep '^const _MAP_FAILED =' gen-sysinfo.go > /dev/null 2>&1; then
135 echo "const _MAP_FAILED = ^uintptr(0)" >> ${OUT}
136fi
137# Make sure _MAP_ANON is defined.
138if ! grep '^const _MAP_ANON =' gen-sysinfo.go > /dev/null 2>&1; then
139 if grep '^const _MAP_ANONYMOUS ' gen-sysinfo.go > /dev/null 2>&1; then
140 echo "const _MAP_ANON = _MAP_ANONYMOUS" >> ${OUT}
141 else
142 echo "const _MAP_ANON = 0" >> ${OUT}
143 fi
144fi
145# Make sure _MADV_DONTNEED is defined.
146if ! grep '^const _MADV_DONTNEED =' gen-sysinfo.go > /dev/null 2>&1; then
147 echo "const _MADV_DONTNEED = 0" >> ${OUT}
148fi
149# Make sure _MADV_FREE is defined.
150if ! grep '^const _MADV_FREE =' gen-sysinfo.go > /dev/null 2>&1; then
151 echo "const _MADV_FREE = 0" >> ${OUT}
152fi
153# Make sure _MADV_HUGEPAGE is defined.
154if ! grep '^const _MADV_HUGEPAGE =' gen-sysinfo.go > /dev/null 2>&1; then
155 echo "const _MADV_HUGEPAGE = 0" >> ${OUT}
156fi
157# Make sure _MADV_NOHUGEPAGE is defined.
158if ! grep '^const _MADV_NOHUGEPAGE =' gen-sysinfo.go > /dev/null 2>&1; then
159 echo "const _MADV_NOHUGEPAGE = 0" >> ${OUT}
160fi
161
c0401cf7
ILT
162# The semt structure, for Solaris.
163grep '^type _sem_t ' gen-sysinfo.go | \
164 sed -e 's/_sem_t/semt/' >> ${OUT}
165
812ba636
ILT
166# The Solaris port_event_t struct.
167grep '^type _port_event_t ' gen-sysinfo.go | \
168 sed -e s'/_port_event_t/portevent/' \
169 >> ${OUT}
170
171# The *BSD kevent struct.
172grep '^type _kevent ' gen-sysinfo.go | \
173 sed -e s'/_kevent/keventt/' \
174 -e 's/ udata [^;}]*/ udata *byte/' \
175 >> ${OUT}
ab2d47a8
ILT
176
177# Type 'uint128' is needed in a couple of type definitions on arm64,such
178# as _user_fpsimd_struct, _elf_fpregset_t, etc.
179if ! grep '^type uint128' ${OUT} > /dev/null 2>&1; then
180 echo "type uint128 [16]byte" >> ${OUT}
181fi