diff mbox series

libgo patch committed: Export NetBSD specific types in mksysinfo.sh

Message ID CAOyqgcWaLMOm5JHPgJY1k=0Ny1wjVwUiccP6z=smOCYHZEWREQ@mail.gmail.com
State New
Headers show
Series libgo patch committed: Export NetBSD specific types in mksysinfo.sh | expand

Commit Message

Ian Lance Taylor Oct. 14, 2020, 8:56 p.m. UTC
The libgo syscall package depends on many NetBSD-specific types on
NetBSD.  This libgo patch by Nikhil Benesch teaches mksysinfo.sh to
export these types.

This alone is not sufficient to get the syscall package to compile on
NetBSD, but it's a start.

Bootstrapped and ran Go testsuite on x86_64-pc-linux-gnu.  Committed
to mainline.

Ian
ca4422ac96183e3c455b1de7f50187eba50bd587
diff mbox series

Patch

diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index c37df37db51..e6eb8e5c335 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@ 
-c5505c4e626fa4217911443b4db8b065855a0206
+cc1f7d613f9b0666bbf8aac3dd208d5adfe88546
 
 The first line of this file holds the git revision number of the last
 merge done from the gofrontend repository.
diff --git a/libgo/configure.ac b/libgo/configure.ac
index 9a10d3305ab..f87ab65e3ba 100644
--- a/libgo/configure.ac
+++ b/libgo/configure.ac
@@ -580,7 +580,7 @@  AC_C_BIGENDIAN
 
 GCC_CHECK_UNWIND_GETIPINFO
 
-AC_CHECK_HEADERS(port.h sched.h semaphore.h sys/file.h sys/mman.h syscall.h sys/epoll.h sys/event.h sys/inotify.h sys/ptrace.h sys/syscall.h sys/user.h sys/utsname.h sys/select.h sys/socket.h net/if.h net/if_arp.h net/route.h netpacket/packet.h sys/prctl.h sys/mount.h sys/vfs.h sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/ether.h linux/fs.h linux/ptrace.h linux/reboot.h netinet/in_syst.h netinet/ip.h netinet/ip_mroute.h netinet/if_ether.h)
+AC_CHECK_HEADERS(port.h sched.h semaphore.h sys/file.h sys/mman.h syscall.h sys/epoll.h sys/event.h sys/inotify.h sys/ptrace.h sys/syscall.h sys/sysctl.h sys/user.h sys/utsname.h sys/select.h sys/socket.h net/bpf.h net/if.h net/if_arp.h net/route.h netpacket/packet.h sys/prctl.h sys/mount.h sys/vfs.h sys/statfs.h sys/timex.h sys/sysinfo.h utime.h linux/ether.h linux/fs.h linux/ptrace.h linux/reboot.h netinet/in_syst.h netinet/ip.h netinet/ip_mroute.h netinet/if_ether.h)
 
 AC_CHECK_HEADERS([netinet/icmp6.h], [], [],
 [#include <netinet/in.h>
diff --git a/libgo/go/runtime/os_netbsd.go b/libgo/go/runtime/os_netbsd.go
index 89a8d076f12..9ebb6520771 100644
--- a/libgo/go/runtime/os_netbsd.go
+++ b/libgo/go/runtime/os_netbsd.go
@@ -33,13 +33,6 @@  func lwp_unpark(lwp int32, hint unsafe.Pointer) int32
 //extern sysctl
 func sysctl(*uint32, uint32, *byte, *uintptr, *byte, uintptr) int32
 
-// From NetBSD's <sys/sysctl.h>
-const (
-	_CTL_HW      = 6
-	_HW_NCPU     = 3
-	_HW_PAGESIZE = 7
-)
-
 func getncpu() int32 {
 	mib := [2]uint32{_CTL_HW, _HW_NCPU}
 	out := uint32(0)
diff --git a/libgo/mksysinfo.sh b/libgo/mksysinfo.sh
index 9671e394cb8..607c97d26fe 100755
--- a/libgo/mksysinfo.sh
+++ b/libgo/mksysinfo.sh
@@ -225,6 +225,22 @@  if ! grep '^const _AT_FDCWD = ' ${OUT} >/dev/null 2>&1; then
   echo "const _AT_FDCWD = -100" >> ${OUT}
 fi
 
+# sysctl constants.
+grep '^const _CTL' gen-sysinfo.go |
+  sed -e 's/^\(const \)_\(CTL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+  grep '^const _SYSCTL' gen-sysinfo.go |
+  sed -e 's/^\(const \)_\(SYSCTL[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+  grep '^const _NET_RT' gen-sysinfo.go |
+  sed -e 's/^\(const \)_\(NET_RT[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+
+# The sysctlnode struct.
+grep '^type _sysctlnode ' gen-sysinfo.go | \
+    sed -e 's/_sysctlnode/Sysctlnode/' \
+		-e 's/sysctl_flags/Flags/' \
+    -e 's/sysctl_name/Name/' \
+    -e 's/sysctl_num/Num/' \
+		>> ${OUT}
+
 # sysconf constants.
 grep '^const __SC' gen-sysinfo.go |
   sed -e 's/^\(const \)__\(SC[^= ]*\)\(.*\)$/\1\2 = __\2/' >> ${OUT}
@@ -533,6 +549,7 @@  fi | sed -e 's/type _dirent64/type Dirent/' \
          -e 's/d_name \[0+1\]/d_name [0+256]/' \
          -e 's/d_name/Name/' \
          -e 's/]int8/]byte/' \
+         -e 's/d_fileno/Fileno/' \
          -e 's/d_ino/Ino/' \
          -e 's/d_namlen/Namlen/' \
          -e 's/d_off/Off/' \
@@ -994,6 +1011,39 @@  grep '^type _rtgenmsg ' gen-sysinfo.go | \
       -e 's/rtgen_family/Family/' \
     >> ${OUT}
 
+# The rt_msghdr struct.
+grep '^type _rt_msghdr ' gen-sysinfo.go | \
+    sed -e 's/_rt_msghdr/RtMsghdr/g' \
+        -e 's/rtm_msglen/Msglen/' \
+        -e 's/rtm_version/Version/' \
+        -e 's/rtm_type/Type/' \
+        -e 's/rtm_index/Index/' \
+        -e 's/rtm_flags/Flags/' \
+        -e 's/rtm_addrs/Addrs/' \
+        -e 's/rtm_pid/Pid/' \
+        -e 's/rtm_seq/Seq/' \
+        -e 's/rtm_errno/Errno/' \
+        -e 's/rtm_use/Use/' \
+        -e 's/rtm_inits/Inits/' \
+        -e 's/rtm_rmx/Rmx/' \
+        -e 's/_rt_metrics/RtMetrics/' \
+      >> ${OUT}
+
+# The rt_metrics struct.
+grep '^type _rt_metrics ' gen-sysinfo.go | \
+    sed -e 's/_rt_metrics/RtMetrics/g' \
+        -e 's/rmx_locks/Locks/' \
+        -e 's/rmx_mtu/Mtu/' \
+        -e 's/rmx_hopcount/Hopcount/' \
+        -e 's/rmx_recvpipe/Recvpipe/' \
+        -e 's/rmx_sendpipe/Sendpipe/' \
+        -e 's/rmx_ssthresh/Ssthresh/' \
+        -e 's/rmx_rtt/Rtt/' \
+        -e 's/rmx_rttvar/Rttvar/' \
+        -e 's/rmx_expire/Expire/' \
+        -e 's/rmx_pksent/Pksent/' \
+      >> ${OUT}
+
 # The routing message flags.
 grep '^const _RT_' gen-sysinfo.go | \
     sed -e 's/^\(const \)_\(RT_[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
@@ -1020,9 +1070,14 @@  grep '^type _ifinfomsg ' gen-sysinfo.go | \
       -e 's/ifi_change/Change/' \
     >> ${OUT}
 
-# The if_msghdr struct.
+# The if_msghdr struct. Upstream uses inconsistent capitalization for this type
+# on AIX, so we do too.
+ifmsghdr_name=IfMsghdr
+if test "${GOOS}" = "aix"; then
+    ifmsghdr_name=IfMsgHdr
+fi
 grep '^type _if_msghdr ' gen-sysinfo.go | \
-    sed -e 's/_if_msghdr/IfMsgHdr/' \
+    sed -e "s/_if_msghdr/${ifmsghdr_name}/" \
 		-e 's/ifm_msglen/Msglen/' \
 		-e 's/ifm_version/Version/' \
 		-e 's/ifm_type/Type/' \
@@ -1032,6 +1087,17 @@  grep '^type _if_msghdr ' gen-sysinfo.go | \
 		-e 's/ifm_addrlen/Addrlen/' \
 		>> ${OUT}
 
+# The if_announcemsghdr struct.
+grep '^type _if_announcemsghdr ' gen-sysinfo.go | \
+    sed -e 's/_if_announcemsghdr/IfAnnounceMsghdr/g' \
+        -e 's/ifan_msglen/Msglen/' \
+        -e 's/ifan_version/Version/' \
+        -e 's/ifan_type/Type/' \
+        -e 's/ifan_index/Index/' \
+        -e 's/ifan_name/Name/' \
+        -e 's/ifan_what/What/' \
+      >> ${OUT}
+
 # The interface information types and flags.
 grep '^const _IFA' gen-sysinfo.go | \
     sed -e 's/^\(const \)_\(IFA[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
@@ -1061,6 +1127,18 @@  grep '^type _ifaddrmsg ' gen-sysinfo.go | \
       -e 's/ifa_index/Index/' \
     >> ${OUT}
 
+# The ifa_msghdr struct.
+grep '^type _ifa_msghdr ' gen-sysinfo.go | \
+    sed -e 's/_ifa_msghdr/IfaMsghdr/g' \
+        -e 's/ifam_msglen/Msglen/' \
+        -e 's/ifam_version/Version/' \
+        -e 's/ifam_type/Type/' \
+        -e 's/ifam_addrs/Addrs/' \
+        -e 's/ifam_flags/Flags/' \
+        -e 's/ifam_metric/Metric/' \
+        -e 's/ifam_index/Index/' \
+      >> ${OUT}
+
 # The rtattr struct.
 grep '^type _rtattr ' gen-sysinfo.go | \
     sed -e 's/_rtattr/RtAttr/' \
@@ -1068,6 +1146,54 @@  grep '^type _rtattr ' gen-sysinfo.go | \
       -e 's/rta_type/Type/' \
     >> ${OUT}
 
+# The bpf_version struct.
+grep '^type _bpf_version ' gen-sysinfo.go | \
+    sed -e 's/_bpf_version/BpfVersion/g' \
+        -e 's/bv_major/Major/' \
+        -e 's/bv_minor/Minor/' \
+      >> ${OUT}
+
+# The bpf_stat struct.
+grep '^type _bpf_stat ' gen-sysinfo.go | \
+    sed -e 's/_bpf_stat/BpfStat/g' \
+        -e 's/bs_recv/Recv/' \
+        -e 's/bs_drop/Drop/' \
+        -e 's/bs_capt/Capt/' \
+        -e 's/bs_padding/Padding/' \
+      >> ${OUT}
+
+# The bpf_insn struct.
+grep '^type _bpf_insn ' gen-sysinfo.go | \
+    sed -e 's/_bpf_insn/BpfInsn/g' \
+        -e 's/code/Code/' \
+        -e 's/jt/Jt/' \
+        -e 's/jf/Jf/' \
+        -e 's/k/K/' \
+      >> ${OUT}
+
+# The bpf_program struct.
+grep '^type _bpf_program ' gen-sysinfo.go | \
+    sed -e 's/_bpf_program/BpfProgram/g' \
+        -e 's/bf_len/Len/' \
+        -e 's/bf_insns/Insns/' \
+        -e 's/_bpf_insn/BpfInsn/' \
+      >> ${OUT}
+
+# The BPF ioctl constants.
+grep '^const _BIOC' gen-sysinfo.go | \
+    grep -v '_val =' | \
+    sed -e 's/^\(const \)_\(BIOC[^= ]*\)\(.*\)$/\1\2 = _\2/' >> ${OUT}
+for c in BIOCFLUSH BIOCGBLEN BIOCGDLT BIOCGETIF BIOCGHDRCMPLT BIOCGRTIMEOUT \
+         BIOCGSTATS BIOCIMMEDIATE BIOCPROMISC BIOCSBLEN BIOCSDLT BIOCSETF \
+         BIOCSETIF BIOCSHDRCMPLT BIOCSRTIMEOUT BIOCVERSION
+do
+  if ! grep "^const ${c}" ${OUT} >/dev/null 2>&1; then
+    if grep "^const _${c}_val" ${OUT} >/dev/null 2>&1; then
+      echo "const ${c} = _${c}_val" >> ${OUT}
+    fi
+  fi
+done
+
 # The in_pktinfo struct.
 grep '^type _in_pktinfo ' gen-sysinfo.go | \
     sed -e 's/_in_pktinfo/Inet4Pktinfo/' \
@@ -1344,10 +1470,11 @@  fi
 
 # Struct sizes.
 set cmsghdr Cmsghdr ip_mreq IPMreq ip_mreqn IPMreqn ipv6_mreq IPv6Mreq \
-    ifaddrmsg IfAddrmsg ifinfomsg IfInfomsg in_pktinfo Inet4Pktinfo \
-    in6_pktinfo Inet6Pktinfo inotify_event InotifyEvent linger Linger \
-    msghdr Msghdr nlattr NlAttr nlmsgerr NlMsgerr nlmsghdr NlMsghdr \
-    rtattr RtAttr rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
+    ifaddrmsg IfAddrmsg ifa_msghdr IfaMsghdr ifinfomsg IfInfomsg \
+    if_msghdr IfMsghdr in_pktinfo Inet4Pktinfo in6_pktinfo Inet6Pktinfo \
+    inotify_event InotifyEvent linger Linger msghdr Msghdr nlattr NlAttr \
+    nlmsgerr NlMsgerr nlmsghdr NlMsghdr rtattr RtAttr rt_msghdr RtMsghdr \
+    rtgenmsg RtGenmsg rtmsg RtMsg rtnexthop RtNexthop \
     sock_filter SockFilter sock_fprog SockFprog ucred Ucred \
     icmp6_filter ICMPv6Filter ip6_mtuinfo IPv6MTUInfo
 while test $# != 0; do
diff --git a/libgo/sysinfo.c b/libgo/sysinfo.c
index 6ea990f471a..ba84071a7bb 100644
--- a/libgo/sysinfo.c
+++ b/libgo/sysinfo.c
@@ -47,6 +47,9 @@ 
 #if defined(HAVE_SYS_SYSCALL_H)
 #include <sys/syscall.h>
 #endif
+#if defined(HAVE_SYS_SYSCTL_H)
+#include <sys/sysctl.h>
+#endif
 #if defined(HAVE_SYS_EPOLL_H)
 #include <sys/epoll.h>
 #endif
@@ -117,6 +120,9 @@ 
 #if defined(HAVE_LINUX_RTNETLINK_H)
 #include <linux/rtnetlink.h>
 #endif
+#if defined(HAVE_NET_BPF_H)
+#include <net/bpf.h>
+#endif
 #if defined(HAVE_NET_IF_H)
 #include <net/if.h>
 #endif
@@ -279,6 +285,54 @@  enum {
 #ifdef NLA_HDRLEN
   NLA_HDRLEN_val = NLA_HDRLEN,
 #endif
+#ifdef BIOCFLUSH
+  BIOCFLUSH_val = BIOCFLUSH,
+#endif
+#ifdef BIOCGBLEN
+  BIOCGBLEN_val = BIOCGBLEN,
+#endif
+#ifdef BIOCGDLT
+  BIOCGDLT_val = BIOCGDLT,
+#endif
+#ifdef BIOCGETIF
+  BIOCGETIF_val = BIOCGETIF,
+#endif
+#ifdef BIOCGHDRCMPLT
+  BIOCGHDRCMPLT_val = BIOCGHDRCMPLT,
+#endif
+#ifdef BIOCGRTIMEOUT
+  BIOCGRTIMEOUT_val = BIOCGRTIMEOUT,
+#endif
+#ifdef BIOCGSTATS
+  BIOCGSTATS_val = BIOCGSTATS,
+#endif
+#ifdef BIOCIMMEDIATE
+  BIOCIMMEDIATE_val = BIOCIMMEDIATE,
+#endif
+#ifdef BIOCPROMISC
+  BIOCPROMISC_val = BIOCPROMISC,
+#endif
+#ifdef BIOCSBLEN
+  BIOCSBLEN_val = BIOCSBLEN,
+#endif
+#ifdef BIOCSDLT
+  BIOCSDLT_val = BIOCSDLT,
+#endif
+#ifdef BIOCSETF
+  BIOCSETF_val = BIOCSETF,
+#endif
+#ifdef BIOCSETIF
+  BIOCSETIF_val = BIOCSETIF,
+#endif
+#ifdef BIOCSHDRCMPLT
+  BIOCSHDRCMPLT_val = BIOCSHDRCMPLT,
+#endif
+#ifdef BIOCSRTIMEOUT
+  BIOCSRTIMEOUT_val = BIOCSRTIMEOUT,
+#endif
+#ifdef BIOCVERSION
+  BIOCVERSION_val = BIOCVERSION,
+#endif
 };
 
 // SIOCGIFMTU can't be added in the above enum as it might