Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gccgo: fix NetBSD support #38538

Closed
bsiegert opened this issue Apr 20, 2020 · 13 comments
Closed

gccgo: fix NetBSD support #38538

bsiegert opened this issue Apr 20, 2020 · 13 comments
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@bsiegert
Copy link
Contributor

What version of Go are you using (go version)?

gcc-9.3.0 with --enable-languages=c,c++,go

Does this issue reproduce with the latest release?

gcc HEAD from git has the same issue.

What operating system and processor architecture are you using (go env)?

NetBSD 9.0 / amd64

What did you do?

I tried to compile gccgo using the GCC 9.3.0 release. NetBSD is nominally supported by gccgo. I did this using the OS packaging setup:

$ cd /usr/pkgsrc/lang/gcc9
$ make package-install PKG_OPTIONS.gcc9="-gcc-objc -gcc-objc++ -nls gcc-go"

What did you expect to see?

I expected a working gccgo compiler.

What did you see instead?

Compilation fails when compiling the runtime package. I have a candidate CL (against gcc HEAD) to fix this, but now there are a lot of errors when compiling the syscall package:

libtool: compile:  /usr/pkgsrc/lang/gcc9/work/build/./gcc/gccgo -B/usr/pkgsrc/lang/gcc9/work/build/./gcc/ -B/usr/pkg/gcc9/x86_64--net
bsd/bin/ -B/usr/pkg/gcc9/x86_64--netbsd/lib/ -isystem /usr/pkg/gcc9/x86_64--netbsd/include -isystem /usr/pkg/gcc9/x86_64--netbsd/sys-
include -fchecking=1 -minline-all-stringops -O2 -g -I . -c -fgo-pkgpath=syscall ../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go ../../
../gcc-9.3.0/libgo/go/syscall/dirent.go ../../../gcc-9.3.0/libgo/go/syscall/endian_little.go ../../../gcc-9.3.0/libgo/go/syscall/env_
unix.go ../../../gcc-9.3.0/libgo/go/syscall/errstr.go ../../../gcc-9.3.0/libgo/go/syscall/exec_bsd.go ../../../gcc-9.3.0/libgo/go/sys
call/exec_unix.go ../../../gcc-9.3.0/libgo/go/syscall/forkpipe2.go ../../../gcc-9.3.0/libgo/go/syscall/libcall_bsd.go ../../../gcc-9.
3.0/libgo/go/syscall/libcall_bsd_regfile.go ../../../gcc-9.3.0/libgo/go/syscall/libcall_posix.go ../../../gcc-9.3.0/libgo/go/syscall/
libcall_posix_nonhurd.go ../../../gcc-9.3.0/libgo/go/syscall/libcall_posix_regfile.go ../../../gcc-9.3.0/libgo/go/syscall/libcall_pos
ix_utimesnano.go ../../../gcc-9.3.0/libgo/go/syscall/libcall_support.go ../../../gcc-9.3.0/libgo/go/syscall/libcall_uname.go ../../..
/gcc-9.3.0/libgo/go/syscall/libcall_wait4.go ../../../gcc-9.3.0/libgo/go/syscall/msan0.go ../../../gcc-9.3.0/libgo/go/syscall/net.go
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go ../../../gcc-9.3.0/libgo/go/syscall/route_netbsd.go ../../../gcc-9.3.0/libgo/go/sysc
all/sleep_select.go ../../../gcc-9.3.0/libgo/go/syscall/sockcmsg_unix.go ../../../gcc-9.3.0/libgo/go/syscall/socket.go ../../../gcc-9
.3.0/libgo/go/syscall/socket_bsd.go ../../../gcc-9.3.0/libgo/go/syscall/socket_posix.go ../../../gcc-9.3.0/libgo/go/syscall/str.go ..
/../../gcc-9.3.0/libgo/go/syscall/syscall.go ../../../gcc-9.3.0/libgo/go/syscall/syscall_errno.go ../../../gcc-9.3.0/libgo/go/syscall
/syscall_funcs.go ../../../gcc-9.3.0/libgo/go/syscall/syscall_netbsd.go ../../../gcc-9.3.0/libgo/go/syscall/syscall_unix.go ../../../
gcc-9.3.0/libgo/go/syscall/timestruct.go libcalls.go sysinfo.go syscall_arch.go  -fPIC -o .libs/syscall.o                           
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:16:28: error: use of undefined type 'BpfInsn'     
   16 | func BpfStmt(code, k int) *BpfInsn {                                                                                        
      |                            ^                                                                  
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:16:28: error: use of undefined type 'BpfInsn'                                  
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:28:47: error: reference to undefined name 'BIOCGBLEN'
   28 |  _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCGBLEN, uintptr(unsafe.Pointer(&l)))                                      
      |                                               ^                                                                         
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:37:47: error: reference to undefined name 'BIOCSBLEN'
   37 |  _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCSBLEN, uintptr(unsafe.Pointer(&l)))                                       
      |                                               ^                                            
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:47:47: error: reference to undefined name 'BIOCGDLT'
   47 |  _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCGDLT, uintptr(unsafe.Pointer(&t)))                                       
      |                                               ^                                                         
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:56:47: error: reference to undefined name 'BIOCSDLT'
   56 |  _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCSDLT, uintptr(unsafe.Pointer(&t)))
      |                                               ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:65:47: error: reference to undefined name 'BIOCPROMISC'
   65 |  _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCPROMISC, uintptr(unsafe.Pointer(&m)))
      |                                               ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:74:47: error: reference to undefined name 'BIOCFLUSH'
   74 |  _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCFLUSH, 0)
      |                                               ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:89:47: error: reference to undefined name 'BIOCGETIF'
   89 |  _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCGETIF, uintptr(unsafe.Pointer(&iv)))
      |                                               ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:100:47: error: reference to undefined name 'BIOCSETIF'
  100 |  _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCSETIF, uintptr(unsafe.Pointer(&iv)))
      |                                               ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:110:47: error: reference to undefined name 'BIOCGRTIMEOUT'
  110 |  _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCGRTIMEOUT, uintptr(unsafe.Pointer(&tv)))
      |                                               ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:119:47: error: reference to undefined name 'BIOCSRTIMEOUT'
  119 |  _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCSRTIMEOUT, uintptr(unsafe.Pointer(tv)))
      |                                               ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:129:47: error: reference to undefined name 'BIOCGSTATS'
  129 |  _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCGSTATS, uintptr(unsafe.Pointer(&s)))
      |                                               ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:138:47: error: reference to undefined name 'BIOCIMMEDIATE'
  138 |  _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCIMMEDIATE, uintptr(unsafe.Pointer(&m)))
      |                                               ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:147:8: error: use of undefined type 'BpfProgram'
  147 |  var p BpfProgram
      |        ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:148:3: error: reference to field 'Len' in object which has no fields or methods
  148 |  p.Len = uint32(len(i))
      |   ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:149:3: error: reference to field 'Insns' in object which has no fields or methods
  149 |  p.Insns = (*BpfInsn)(unsafe.Pointer(&i[0]))
      |   ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:149:14: error: reference to undefined name 'BpfInsn'
  149 |  p.Insns = (*BpfInsn)(unsafe.Pointer(&i[0]))
      |              ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:149:13: error: expected pointer
  149 |  p.Insns = (*BpfInsn)(unsafe.Pointer(&i[0]))
      |             ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:150:47: error: reference to undefined name 'BIOCSETF'
  150 |  _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCSETF, uintptr(unsafe.Pointer(&p)))
      |                                               ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:160:47: error: reference to undefined name 'BIOCVERSION'
  160 |  _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCVERSION, uintptr(unsafe.Pointer(&v)))
      |                                               ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:159:8: error: use of undefined type 'BpfVersion'
  159 |  var v BpfVersion
      |        ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:164:6: error: reference to field 'Major' in object which has no fields or methods
  164 |  if v.Major != BPF_MAJOR_VERSION || v.Minor != BPF_MINOR_VERSION {
      |      ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:164:16: error: reference to undefined name 'BPF_MAJOR_VERSION'
  164 |  if v.Major != BPF_MAJOR_VERSION || v.Minor != BPF_MINOR_VERSION { 
      |                ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:164:38: error: reference to field 'Minor' in object which has no fields or methods
  164 |  if v.Major != BPF_MAJOR_VERSION || v.Minor != BPF_MINOR_VERSION { 
      |                                      ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:164:48: error: reference to undefined name 'BPF_MINOR_VERSION'
  164 |  if v.Major != BPF_MAJOR_VERSION || v.Minor != BPF_MINOR_VERSION { 
      |                                                ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:173:47: error: reference to undefined name 'BIOCGHDRCMPLT'
  173 |  _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCGHDRCMPLT, uintptr(unsafe.Pointer(&f)))
      |                                               ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:182:47: error: reference to undefined name 'BIOCSHDRCMPLT'
  182 |  _, _, err := Syscall(SYS_IOCTL, uintptr(fd), BIOCSHDRCMPLT, uintptr(unsafe.Pointer(&f)))
      |                                               ^
../../../gcc-9.3.0/libgo/go/syscall/exec_bsd.go:85:10: error: reference to undefined name 'raw_ptrace'
   85 |   err1 = raw_ptrace(_PTRACE_TRACEME, 0, nil, nil)
      |          ^
../../../gcc-9.3.0/libgo/go/syscall/forkpipe2.go:10:9: error: reference to undefined name 'Pipe2'
   10 |  return Pipe2(p, O_CLOEXEC)
      |         ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:40:10: error: incompatible type for return value 1 (cannot use type uintptr as type
int)
   40 |   return salign
      |          ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:54:11: error: reference to undefined name 'RawSockaddrDatalink'
   54 |  rsa := (*RawSockaddrDatalink)(unsafe.Pointer(&b[0]))
      |           ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:54:10: error: expected pointer
   54 |  rsa := (*RawSockaddrDatalink)(unsafe.Pointer(&b[0]))
      |          ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:46:36: error: use of undefined type 'SockaddrDatalink'
   46 | func parseSockaddrLink(b []byte) (*SockaddrDatalink, error) { 
      |                                    ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:55:4: error: reference to field 'Len' in object which has no fields or methods
   55 |  sa.Len = rsa.Len
      |    ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:56:4: error: reference to field 'Family' in object which has no fields or methods
   56 |  sa.Family = rsa.Family
      |    ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:57:4: error: reference to field 'Index' in object which has no fields or methods
   57 |  sa.Index = rsa.Index
      |    ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:46:36: error: use of undefined type 'SockaddrDatalink'
   46 | func parseSockaddrLink(b []byte) (*SockaddrDatalink, error) { 
      |                                    ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:182:18: error: reference to undefined name 'CTL_NET'
  182 |  mib := []_C_int{CTL_NET, AF_ROUTE, 0, 0, _C_int(facility), _C_int(param)}
      |                  ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:185:12: error: reference to undefined name 'sysctl'
  185 |  if err := sysctl(mib, nil, &n, nil, 0); err != nil {
      |            ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:192:12: error: reference to undefined name 'sysctl'
  192 |  if err := sysctl(mib, &tab[0], &n, nil, 0); err != nil {
      |            ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:218:9: error: use of undefined type 'RtMsghdr'
  218 |  Header RtMsghdr
      |         ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:227:14: error: reference to field 'Addrs' in object which has no fields or methods
  227 |   if m.Header.Addrs&(1<<i) == 0 {
      |              ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:264:9: error: use of undefined type 'IfMsghdr'
  264 |  Header IfMsghdr
      |         ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:270:13: error: reference to field 'Addrs' in object which has no fields or methods
  270 |  if m.Header.Addrs&RTA_IFP == 0 {
      |             ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:286:9: error: use of undefined type 'IfaMsghdr'
  286 |  Header IfaMsghdr
      |         ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:295:14: error: reference to field 'Addrs' in object which has no fields or methods
  295 |   if m.Header.Addrs&(1<<i) == 0 {
      |              ^
../../../gcc-9.3.0/libgo/go/syscall/route_netbsd.go:11:95: error: reference to undefined name 'RTM_RESOLVE'
   11 |  case RTM_ADD, RTM_DELETE, RTM_CHANGE, RTM_GET, RTM_LOSING, RTM_REDIRECT, RTM_MISS, RTM_LOCK, RTM_RESOLVE:
      |                                                                                               ^
../../../gcc-9.3.0/libgo/go/syscall/route_netbsd.go:14:11: error: reference to field 'Addrs' in object which has no fields or methods
   14 |   p.Header.Addrs &= RTA_DST | RTA_GATEWAY | RTA_NETMASK | RTA_GENMASK | RTA_IFA | RTA_IFP | RTA_BRD | RTA_AUTHOR
      |           ^
../../../gcc-9.3.0/libgo/go/syscall/route_netbsd.go:15:50: error: reference to undefined name 'SizeofRtMsghdr'
   15 |   return &RouteMessage{Header: p.Header, Data: b[SizeofRtMsghdr:any.Msglen]}
      |                                                  ^
../../../gcc-9.3.0/libgo/go/syscall/route_netbsd.go:18:54: error: reference to undefined name 'SizeofIfMsghdr'
   18 |   return &InterfaceMessage{Header: p.Header, Data: b[SizeofIfMsghdr:any.Msglen]} 
      |                                                      ^
../../../gcc-9.3.0/libgo/go/syscall/route_netbsd.go:24:58: error: reference to undefined name 'SizeofIfaMsghdr'
   24 |   return &InterfaceAddrMessage{Header: p.Header, Data: b[SizeofIfaMsghdr:any.Msglen]} 
      |                                                          ^
../../../gcc-9.3.0/libgo/go/syscall/syscall_netbsd.go:10:46: error: reference to undefined field or method 'Fileno'
   10 |  return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno))
../../../gcc-9.3.0/libgo/go/syscall/syscall_netbsd.go:10:78: error: reference to undefined field or method 'Fileno'
   10 |  return readInt(buf, unsafe.Offsetof(Dirent{}.Fileno), unsafe.Sizeof(Dirent{}.Fileno))
      |                                                                              ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:16:28: error: use of undefined type 'BpfInsn'
   16 | func BpfStmt(code, k int) *BpfInsn {
      |                            ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:16:28: error: use of undefined type 'BpfInsn'
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:127:25: error: use of undefined type 'BpfStat'
  127 | func BpfStats(fd int) (*BpfStat, error) {
      |                         ^
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:127:25: error: use of undefined type 'BpfStat'
../../../gcc-9.3.0/libgo/go/syscall/bpf_bsd.go:16:28: error: use of undefined type 'BpfInsn'
   16 | func BpfStmt(code, k int) *BpfInsn {
      |                            ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:46:36: error: use of undefined type 'SockaddrDatalink'
   46 | func parseSockaddrLink(b []byte) (*SockaddrDatalink, error) { 
      |                                    ^
../../../gcc-9.3.0/libgo/go/syscall/route_netbsd.go:34:9: error: use of undefined type 'IfAnnounceMsghdr'
   34 |  Header IfAnnounceMsghdr
      |         ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:227:23: error: invalid context-determined non-integer type for left operand of shift
  227 |   if m.Header.Addrs&(1<<i) == 0 {
      |                       ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:295:23: error: invalid context-determined non-integer type for left operand of shift
  295 |   if m.Header.Addrs&(1<<i) == 0 {
      |                       ^
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:42:16: error: incompatible types in binary expression
   42 |  return (salen + salign - 1) & ^(salign - 1)
      |                ^ 
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:237:11: error: incompatible types in assignment (type has no methods)
  237 |    sas[i] = sa
      |           ^ 
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:277:16: error: incompatible types in assignment (type has no methods)
  277 |  sas[RTAX_IFP] = sa
      |                ^ 
../../../gcc-9.3.0/libgo/go/syscall/route_bsd.go:305:11: error: incompatible types in assignment (type has no methods)
  305 |    sas[i] = sa
      |           ^ 
gmake[4]: *** [Makefile:2838: syscall.lo] Error 1

As far as I can tell, there are no z* files per os in the syscall package. I would appreciate a hint about where these missing definitions are supposed to come from.

/cc @ianlancetaylor @tklauser

@gopherbot gopherbot added this to the Gccgo milestone Apr 20, 2020
@gopherbot
Copy link

Change https://golang.org/cl/228918 mentions this issue: gccgo: fix runtime compilation on NetBSD

@andybons andybons added the NeedsFix The path to resolution is known, but the work has not been done. label Apr 20, 2020
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue Apr 20, 2020
This fixes the build of the "runtime" package, now the compilation is
stuck in the "syscall" package instead.

Submitted upstream as https://go-review.googlesource.com/c/gofrontend/+/228918/.
Upstream bug report at golang/go#38538.
gopherbot pushed a commit to golang/gofrontend that referenced this issue Apr 21, 2020
si_code in siginfo_t is a macro on NetBSD, not a member of the
struct itself, so add a C trampoline for receiving its value.

Also replace references to mos.waitsemacount with the replacement and
add some helpers from os_netbsd.go in the GC repository.

Update golang/go#38538.

Change-Id: I818069de3eea8f3d33479542a798c729c9efd042
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/228918
Reviewed-by: Ian Lance Taylor <iant@golang.org>
kraj pushed a commit to kraj/gcc that referenced this issue Apr 21, 2020
si_code in siginfo_t is a macro on NetBSD, not a member of the
struct itself, so add a C trampoline for receiving its value.

Also replace references to mos.waitsemacount with the replacement and
add some helpers from os_netbsd.go in the GC repository.

Update golang/go#38538.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/228918
@ianlancetaylor
Copy link
Contributor

Sorry for the slow reply. The missing definitions are supposed to come from the mksysinfo.sh script. Make sure that sysinfo.c #include's any required header files, and that mksysinfo.sh exposes any constants or types that the Go code requires.

@benesch
Copy link
Contributor

benesch commented Oct 8, 2020

I'm going to look into this, as it seems like a useful step towards Darwin support.

@gopherbot
Copy link

Change https://golang.org/cl/261137 mentions this issue: libgo: fix compilation on netbsd

@gopherbot
Copy link

Change https://golang.org/cl/261739 mentions this issue: libgo: export NetBSD-specific types in mksysinfo.sh

gopherbot pushed a commit to golang/gofrontend that referenced this issue Oct 14, 2020
The syscall package depends on many NetBSD-specific types on NetBSD.
Teach 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.

Note that the IfMsgHdr type is recapitalized to IfMsghdr, which requires
changes in the AIX port. The new capitalization is what's used by
upstream in existing NetBSD-specific code and is more consistent with
the capitalization of other C structs with the "hdr" suffix.

Updates golang/go#38538.

Change-Id: I56d8d8d887b293d5a9195114cc7f7b44a5b738cb
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/261739
Reviewed-by: Benny Siegert <bsiegert@gmail.com>
Trust: Benny Siegert <bsiegert@gmail.com>
Trust: Than McIntosh <thanm@google.com>
kraj pushed a commit to kraj/gcc that referenced this issue Oct 14, 2020
The syscall package depends on many NetBSD-specific types on NetBSD.
Teach 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.

Note that the IfMsgHdr type is recapitalized to IfMsghdr, which requires
changes in the AIX port. The new capitalization is what's used by
upstream in existing NetBSD-specific code and is more consistent with
the capitalization of other C structs with the "hdr" suffix.

Updates golang/go#38538.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/261739
@bsiegert
Copy link
Contributor Author

@benesch Thanks for looking into this! I tried building gccgo from gcc HEAD just now on NetBSD-9, and I still see errors in the syscall package:

libtool: compile:  /home/bsiegert/src/gcc-bis/host-x86_64-unknown-netbsd9.0/gcc/gccgo -B/home/bsiegert/src/gcc-bis/host-x86_64-unknown-netbsd9.0/gcc/ -B/usr/local/x86_64-unknown-netbsd9.0/bin/ -B/usr/local/x86_64-unknown-netbsd9.0/lib/ -isystem /usr/local/x86_64-unknown-netbsd9.0/include -isystem /usr/local/x86_64-unknown-netbsd9.0/sys-include -fchecking=1 -minline-all-stringops -O2 -g -I . -c -fgo-pkgpath=syscall ../.././libgo/go/syscall/bpf_bsd.go ../.././libgo/go/syscall/dirent.go ../.././libgo/go/syscall/endian_little.go ../.././libgo/go/syscall/env_unix.go ../.././libgo/go/syscall/errstr.go ../.././libgo/go/syscall/exec_bsd.go ../.././libgo/go/syscall/exec_unix.go ../.././libgo/go/syscall/forkpipe2.go ../.././libgo/go/syscall/libcall_bsd.go ../.././libgo/go/syscall/libcall_bsd_regfile.go ../.././libgo/go/syscall/libcall_posix.go ../.././libgo/go/syscall/libcall_posix_nonhurd.go ../.././libgo/go/syscall/libcall_posix_regfile.go ../.././libgo/go/syscall/libcall_posix_utimesnano.go ../.././libgo/go/syscall/libcall_support.go ../.././libgo/go/syscall/libcall_uname.go ../.././libgo/go/syscall/libcall_wait4.go ../.././libgo/go/syscall/msan0.go ../.././libgo/go/syscall/net.go ../.././libgo/go/syscall/route_bsd.go ../.././libgo/go/syscall/route_netbsd.go ../.././libgo/go/syscall/sleep_select.go ../.././libgo/go/syscall/sockcmsg_unix.go ../.././libgo/go/syscall/sockcmsg_unix_other.go ../.././libgo/go/syscall/socket.go ../.././libgo/go/syscall/socket_bsd.go ../.././libgo/go/syscall/socket_posix.go ../.././libgo/go/syscall/str.go ../.././libgo/go/syscall/syscall.go ../.././libgo/go/syscall/syscall_errno.go ../.././libgo/go/syscall/syscall_funcs.go ../.././libgo/go/syscall/syscall_netbsd.go ../.././libgo/go/syscall/syscall_unix.go ../.././libgo/go/syscall/time_nofake.go ../.././libgo/go/syscall/timestruct.go libcalls.go sysinfo.go syscall_arch.go  -fPIC -o .libs/syscall.o
../.././libgo/go/syscall/route_bsd.go:46:36: error: use of undefined type ‘SockaddrDatalink’
   46 | func parseSockaddrLink(b []byte) (*SockaddrDatalink, error) {
      |                                    ^
../.././libgo/go/syscall/exec_bsd.go:96:24: error: reference to undefined name ‘raw_ptrace’
   96 |                 err1 = raw_ptrace(_PTRACE_TRACEME, 0, nil, nil)
      |                        ^
../.././libgo/go/syscall/forkpipe2.go:10:16: error: reference to undefined name ‘Pipe2’
   10 |         return Pipe2(p, O_CLOEXEC)
      |                ^
../.././libgo/go/syscall/route_bsd.go:40:24: error: incompatible type for return value 1 (cannot use type uintptr as type int)
   40 |                 return salign
      |                        ^
../.././libgo/go/syscall/route_bsd.go:54:18: error: reference to undefined name ‘RawSockaddrDatalink’
   54 |         rsa := (*RawSockaddrDatalink)(unsafe.Pointer(&b[0]))
      |                  ^
../.././libgo/go/syscall/route_bsd.go:54:17: error: expected pointer
   54 |         rsa := (*RawSockaddrDatalink)(unsafe.Pointer(&b[0]))
      |                 ^
../.././libgo/go/syscall/route_bsd.go:46:36: error: use of undefined type ‘SockaddrDatalink’
   46 | func parseSockaddrLink(b []byte) (*SockaddrDatalink, error) {
      |                                    ^
../.././libgo/go/syscall/route_bsd.go:55:11: error: reference to field ‘Len’ in object which has no fields or methods
   55 |         sa.Len = rsa.Len
      |           ^
../.././libgo/go/syscall/route_bsd.go:56:11: error: reference to field ‘Family’ in object which has no fields or methods
   56 |         sa.Family = rsa.Family
      |           ^
../.././libgo/go/syscall/route_bsd.go:57:11: error: reference to field ‘Index’ in object which has no fields or methods
   57 |         sa.Index = rsa.Index
      |           ^
../.././libgo/go/syscall/route_bsd.go:88:33: error: reference to undefined name ‘Type’
   88 |         sa := &SockaddrDatalink{Type: lla.Type, Nlen: lla.Nlen, Alen: lla.Alen, Slen: lla.Slen}
      |                                 ^
../.././libgo/go/syscall/route_bsd.go:88:49: error: reference to undefined name ‘Nlen’
   88 |         sa := &SockaddrDatalink{Type: lla.Type, Nlen: lla.Nlen, Alen: lla.Alen, Slen: lla.Slen}
      |                                                 ^
../.././libgo/go/syscall/route_bsd.go:88:65: error: reference to undefined name ‘Alen’
   88 |         sa := &SockaddrDatalink{Type: lla.Type, Nlen: lla.Nlen, Alen: lla.Alen, Slen: lla.Slen}
      |                                                                 ^
../.././libgo/go/syscall/route_bsd.go:88:81: error: reference to undefined name ‘Slen’
   88 |         sa := &SockaddrDatalink{Type: lla.Type, Nlen: lla.Nlen, Alen: lla.Alen, Slen: lla.Slen}
      |                                                                                 ^
../.././libgo/go/syscall/route_bsd.go:185:19: error: reference to undefined name ‘sysctl’
  185 |         if err := sysctl(mib, nil, &n, nil, 0); err != nil {
      |                   ^
../.././libgo/go/syscall/route_bsd.go:192:19: error: reference to undefined name ‘sysctl’
  192 |         if err := sysctl(mib, &tab[0], &n, nil, 0); err != nil {
      |                   ^
../.././libgo/go/syscall/route_netbsd.go:11:102: error: reference to undefined name ‘RTM_RESOLVE’
   11 |         case RTM_ADD, RTM_DELETE, RTM_CHANGE, RTM_GET, RTM_LOSING, RTM_REDIRECT, RTM_MISS, RTM_LOCK, RTM_RESOLVE:
      |                                                                                                      ^
../.././libgo/go/syscall/route_bsd.go:46:36: error: use of undefined type ‘SockaddrDatalink’
   46 | func parseSockaddrLink(b []byte) (*SockaddrDatalink, error) {
      |                                    ^
../.././libgo/go/syscall/route_bsd.go:42:23: error: incompatible types in binary expression
   42 |         return (salen + salign - 1) & ^(salign - 1)
      |                       ^
../.././libgo/go/syscall/route_bsd.go:237:32: error: incompatible types in assignment (type has no methods)
  237 |                         sas[i] = sa
      |                                ^
../.././libgo/go/syscall/route_bsd.go:277:23: error: incompatible types in assignment (type has no methods)
  277 |         sas[RTAX_IFP] = sa
      |                       ^
../.././libgo/go/syscall/route_bsd.go:305:32: error: incompatible types in assignment (type has no methods)
  305 |                         sas[i] = sa
      |                                ^
gmake[4]: *** [Makefile:2910: syscall.lo] Error 1

@benesch
Copy link
Contributor

benesch commented Oct 16, 2020 via email

gopherbot pushed a commit to golang/gofrontend that referenced this issue Oct 21, 2020
Import some missing upstream code for BSD sockets and sysctls and
adapt it for gccgo.

Updates golang/go#38538.

Change-Id: I3b08bf01b499b5be55ef79b4633f47ba266d0148
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/261137
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Benny Siegert <bsiegert@gmail.com>
jpf91 pushed a commit to D-Programming-GDC/gcc that referenced this issue Oct 22, 2020
Import some missing upstream code for BSD sockets and sysctls and
adapt it for gccgo.

Updates golang/go#38538.

Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/261137
@gopherbot
Copy link

Change https://golang.org/cl/265123 mentions this issue: syscall: import additional BSD-specific syscall wrappers

gopherbot pushed a commit to golang/gofrontend that referenced this issue Oct 26, 2020
Import additional code from upstream for handing system
calls on BSD systems. This makes the syscall package on
NetBSD complete enough to compile the standard library.

Updates golang/go#38538.

Change-Id: I15644dbbd78b1acebcaf45b49403f07c929d97ed
Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/265123
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Trust: Benny Siegert <bsiegert@gmail.com>
@benesch
Copy link
Contributor

benesch commented Oct 29, 2020

With a recent NetBSD-current and the latest tip of GCC, compilation on NetBSD succeeds! 🎉

The test suite mostly passes, too, with a few notable exceptions:

--- FAIL: TestLdexp (0.00s)
    all_test.go:2672: Ldexp(1.0000000000000002, -1075) = 0, want 5e-324
--- FAIL: TestPow (0.00s)
    all_test.go:2832: Pow(-0, -3.141592653589793) = -Inf, want +Inf
    all_test.go:2832: Pow(-0, -0.5) = -Inf, want +Inf
FAIL: math
--- FAIL: TestFormat (0.00s)
    format_test.go:127: ANSIC expected "Wed Feb  4 21:00:57 2009" got "Wed Feb  4 22:00:57 2009"
    format_test.go:127: UnixDate expected "Wed Feb  4 21:00:57 PST 2009" got "Wed Feb  4 22:00:57 PDT 2009"
    format_test.go:127: RubyDate expected "Wed Feb 04 21:00:57 -0800 2009" got "Wed Feb 04 22:00:57 -0700 2009"
    format_test.go:127: RFC822 expected "04 Feb 09 21:00 PST" got "04 Feb 09 22:00 PDT"
    format_test.go:127: RFC850 expected "Wednesday, 04-Feb-09 21:00:57 PST" got "Wednesday, 04-Feb-09 22:00:57 PDT"
    format_test.go:127: RFC1123 expected "Wed, 04 Feb 2009 21:00:57 PST" got "Wed, 04 Feb 2009 22:00:57 PDT"
    format_test.go:127: RFC1123Z expected "Wed, 04 Feb 2009 21:00:57 -0800" got "Wed, 04 Feb 2009 22:00:57 -0700"
    format_test.go:127: RFC3339 expected "2009-02-04T21:00:57-08:00" got "2009-02-04T22:00:57-07:00"
    format_test.go:127: RFC3339Nano expected "2009-02-04T21:00:57.0123456-08:00" got "2009-02-04T22:00:57.0123456-07:00"
    format_test.go:127: Kitchen expected "9:00PM" got "10:00PM"
    format_test.go:127: am/pm expected "9pm" got "10pm"
    format_test.go:127: AM/PM expected "9PM" got "10PM"
    format_test.go:127: Stamp expected "Feb  4 21:00:57" got "Feb  4 22:00:57"
    format_test.go:127: StampMilli expected "Feb  4 21:00:57.012" got "Feb  4 22:00:57.012"
    format_test.go:127: StampMicro expected "Feb  4 21:00:57.012345" got "Feb  4 22:00:57.012345"
    format_test.go:127: StampNano expected "Feb  4 21:00:57.012345600" got "Feb  4 22:00:57.012345600"
--- FAIL: TestParse (0.00s)
    format_test.go:417: UnixDate: bad hour: 22 not 21
    format_test.go:435: UnixDate: bad tz offset: PDT -25200 not -28800
    format_test.go:417: RFC850: bad hour: 22 not 21
    format_test.go:435: RFC850: bad tz offset: PDT -25200 not -28800
    format_test.go:417: RFC1123: bad hour: 22 not 21
    format_test.go:435: RFC1123: bad tz offset: PDT -25200 not -28800
    format_test.go:417: RFC1123: bad hour: 22 not 21
    format_test.go:435: RFC1123: bad tz offset: PDT -25200 not -28800
    format_test.go:417: UnixDate: bad hour: 22 not 21
    format_test.go:435: UnixDate: bad tz offset: PDT -25200 not -28800
    format_test.go:417: RFC850: bad hour: 22 not 21
    format_test.go:435: RFC850: bad tz offset: PDT -25200 not -28800
    format_test.go:417: RFC1123: bad hour: 22 not 21
    format_test.go:435: RFC1123: bad tz offset: PDT -25200 not -28800
--- FAIL: TestSecondsToLocalTime (0.00s)
    time_test.go:148: SecondsToLocalTime(2152173599):
    time_test.go:149:   want={Year:2038 Month:March Day:14 Hour:1 Minute:59 Second:59 Nanosecond:0 Weekday:Sunday ZoneOffset:-28800 Zone:PST}
    time_test.go:150:   have=2038-03-14T02:59:59-07:00 PDT
    time_test.go:148: SecondsToLocalTime(2172733200):
    time_test.go:149:   want={Year:2038 Month:November Day:7 Hour:1 Minute:0 Second:0 Nanosecond:0 Weekday:Sunday ZoneOffset:-28800 Zone:PST}
    time_test.go:150:   have=2038-11-07T02:00:00-07:00 PDT
    time_test.go:148: SecondsToLocalTime(2172733201):
    time_test.go:149:   want={Year:2038 Month:November Day:7 Hour:1 Minute:0 Second:1 Nanosecond:0 Weekday:Sunday ZoneOffset:-28800 Zone:PST}
    time_test.go:150:   have=2038-11-07T02:00:01-07:00 PDT
--- FAIL: TestDate (0.00s)
    time_test.go:622: Date(2011, 11, 6, 2, 0, 0, 0, Local) = 2011-11-06 02:00:00 -0700 PDT, want 2011-11-06 03:00:00 -0700 PDT
    time_test.go:622: Date(2011, 3, 13, 1, 0, 0, 0, Local) = 2011-03-13 01:00:00 -0700 PDT, want 2011-03-13 02:00:00 -0700 PDT
    time_test.go:622: Date(2011, 3, 13, 1, 59, 59, 0, Local) = 2011-03-13 01:59:59 -0700 PDT, want 2011-03-13 02:59:59 -0700 PDT
    time_test.go:622: Date(2012, 12, 24, 0, 0, 0, 0, Local) = 2012-12-24 00:00:00 -0700 PDT, want 2012-12-24 01:00:00 -0700 PDT
    time_test.go:622: Date(2011, 11, 18, 7, 56, 35, 0, Local) = 2011-11-18 07:56:35 -0700 PDT, want 2011-11-18 08:56:35 -0700 PDT
    time_test.go:622: Date(2011, 11, 19, -17, 56, 35, 0, Local) = 2011-11-18 07:56:35 -0700 PDT, want 2011-11-18 08:56:35 -0700 PDT
    time_test.go:622: Date(2011, 11, 17, 31, 56, 35, 0, Local) = 2011-11-18 07:56:35 -0700 PDT, want 2011-11-18 08:56:35 -0700 PDT
    time_test.go:622: Date(2011, 11, 18, 6, 116, 35, 0, Local) = 2011-11-18 07:56:35 -0700 PDT, want 2011-11-18 08:56:35 -0700 PDT
    time_test.go:622: Date(2011, 10, 49, 7, 56, 35, 0, Local) = 2011-11-18 07:56:35 -0700 PDT, want 2011-11-18 08:56:35 -0700 PDT
    time_test.go:622: Date(2011, 11, 18, 7, 55, 95, 0, Local) = 2011-11-18 07:56:35 -0700 PDT, want 2011-11-18 08:56:35 -0700 PDT
    time_test.go:622: Date(2011, 11, 18, 7, 56, 34, 1000000000, Local) = 2011-11-18 07:56:35 -0700 PDT, want 2011-11-18 08:56:35 -0700 PDT
    time_test.go:622: Date(2011, 12, -12, 7, 56, 35, 0, Local) = 2011-11-18 07:56:35 -0700 PDT, want 2011-11-18 08:56:35 -0700 PDT
    time_test.go:622: Date(2012, 1, -43, 7, 56, 35, 0, Local) = 2011-11-18 07:56:35 -0700 PDT, want 2011-11-18 08:56:35 -0700 PDT
    time_test.go:622: Date(2012, -1, 18, 7, 56, 35, 0, Local) = 2011-11-18 07:56:35 -0700 PDT, want 2011-11-18 08:56:35 -0700 PDT
    time_test.go:622: Date(2010, 23, 18, 7, 56, 35, 0, Local) = 2011-11-18 07:56:35 -0700 PDT, want 2011-11-18 08:56:35 -0700 PDT

The math failures are, I suspect, actual bugs in NetBSD's libc. See, for example, http://gnats.netbsd.org/45391.

The time failures are weirder. Everything seems to be off by an hour. I haven't had time to really look into why.

@bsiegert, if you're up for poking at this, would be much appreciated! I've done most of the work I plan to do on this.

@ianlancetaylor
Copy link
Contributor

Congrats on getting this working, and thanks for doing it.

Does your system have tzdata version 2020b or newer installed? If so, the time package problems are #42138 and #42216.

@benesch
Copy link
Contributor

benesch commented Oct 29, 2020

Does your system have tzdata version 2020b or newer installed? If so, the time package problems are #42138 and #42216.

Ah, indeed! NetBSD/src@c783255

Thanks. That saved me a lot of head scratching.

@benesch
Copy link
Contributor

benesch commented Dec 4, 2020

The timestamp failures have been resolved on NetBSD with the latest sources. The only remaining failures, as mentioned above, are:

--- FAIL: TestLdexp (0.00s)
    all_test.go:2672: Ldexp(1.0000000000000002, -1075) = 0, want 5e-324
--- FAIL: TestPow (0.00s)
    all_test.go:2832: Pow(-0, -3.141592653589793) = -Inf, want +Inf
    all_test.go:2832: Pow(-0, -0.5) = -Inf, want +Inf
FAIL
[2]   Terminated              (sleep $(...); echo >gotest-timeout; echo "tim...
FAIL: math

These appear to be bugs in NetBSD's libc, and at least the pow bug is tracked upstream as lib/45391. I think we can probably close this issue as resolved.

@ianlancetaylor
Copy link
Contributor

Thanks!

@golang golang locked and limited conversation to collaborators Dec 4, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants