Skip to content

Build failure on FreeBSD 32-bit architectures due to type mismatch

Description

When I upgraded modernc.org/libc version in my project, I encountered multiple build errors. I'm not fully familiar with modernc.org/libc's multi-platform support, so I apologize if I'm missing something on my end, but I wanted to report these errors in case they indicate an upstream issue.

Build errors encountered in my project:

  Error: ../../../go/pkg/mod/modernc.org/libc@v1.65.10/libc_freebsd.go:247:25: cannot use int64(off) (value of type int64) as int32 
  value in assignment
  Error: ../../../go/pkg/mod/modernc.org/libc@v1.65.10/libc_freebsd.go:269:50: cannot use int64(off) (value of type int64) as int32
  value in assignment
  Error: ../../../go/pkg/mod/modernc.org/libc@v1.65.10/libc_freebsd.go:1622:17: invalid operation: Uint64(Uint64FromInt32(-1)) / 
  uint64(255) * size_t(c) (mismatched types uint64 and size_t)
  Error: ../../../go/pkg/mod/modernc.org/libc@v1.65.10/libc_freebsd.go:1623:192: invalid operation: *(*uint64)(unsafe.Pointer(w)) ^ k
  (mismatched types uint64 and size_t)
  Error: ../../../go/pkg/mod/modernc.org/libc@v1.65.10/libc_freebsd.go:1642:42: cannot use &l1 (value of type *size_t) as *uint64
  value in argument to AssignUint64
  Error: ../../../go/pkg/mod/modernc.org/libc@v1.65.10/libc_freebsd.go:1642:47: cannot use size_t((int64(X__strchrnul(tls, var1, '='))
   - int64(var1)) / 1) (value of uint32 type size_t) as uint64 value in argument to AssignUint64
  Error: ../../../go/pkg/mod/modernc.org/libc@v1.65.10/libc_freebsd.go:1651:19: invalid operation: l1 + l2 + uint64(2) (mismatched 
  types size_t and uint64)
  Error: ../../../go/pkg/mod/modernc.org/libc@v1.65.10/libc_freebsd.go:1657:48: invalid operation: l2 + uint64(1) (mismatched types 
  size_t and uint64)
  Error: ../../../go/pkg/mod/modernc.org/libc@v1.65.10/libc_freebsd.go:1670:6: cannot use uint64(0) (constant 0 of type uint64) as 
  size_t value in assignment
  Error: ../../../go/pkg/mod/modernc.org/libc@v1.65.10/libc_freebsd.go:1680:57: invalid operation: l + uint64(1) (mismatched types 
  size_t and uint64)
  Error: ../../../go/pkg/mod/modernc.org/libc@v1.65.10/libc_freebsd.go:1680:57: too many errors

Analysis

Looking at the code, I noticed several type mismatches. For example, in https://gitlab.com/cznic/libc/-/blob/4f7086b9ce24b5bbab56b6e44db871067c84263c/libc_freebsd.go#L247, the code assigns int64(off) to Ftm_gmtoff, but this field is defined as int32 on 32-bit architectures (https://gitlab.com/cznic/libc/-/blob/4f7086b9ce24b5bbab56b6e44db871067c84263c/time/time_freebsd_386.go#L889).

These changes seem to have been introduced in commit 04484ec9.

Environment

I think this affects FreeBSD 32-bit architectures (386, arm), although I'm not certain about the exact build configuration that triggers these errors.

If there's something I need to configure differently or if I'm missing some build tags, please let me know. I'd be happy to provide more information if needed.