Bug 68931 - gccgo fails to build using MUSL libc
Summary: gccgo fails to build using MUSL libc
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: go (show other bugs)
Version: 5.2.0
: P3 normal
Target Milestone: 12.0
Assignee: Ian Lance Taylor
URL:
Keywords: build
Depends on:
Blocks:
 
Reported: 2015-12-16 06:11 UTC by Daniel Dickinson
Modified: 2021-12-27 23:13 UTC (History)
2 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Patch for missing types when building go with MUSL (1.26 KB, patch)
2015-12-16 06:11 UTC, Daniel Dickinson
Details | Diff
Patch for musl compatibility (730 bytes, patch)
2020-10-17 15:51 UTC, Daniel Santos
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Dickinson 2015-12-16 06:11:46 UTC
Created attachment 37045 [details]
Patch for missing types when building go with MUSL

Using MUSL gccgo fails to build due to missing types.

The patch attached resolves the issue:
Comment 1 Ian Lance Taylor 2015-12-16 14:29:39 UTC
I don't understand your patch, because I don't understand where CONFIG_USE_MUSL gets set.

It also seems like the wrong approach.  The basic goal of configure tests is to test for features, not systems.  mksysinfo.sh already works that way.  What fails without this patch?
Comment 2 Daniel Dickinson 2015-12-16 15:35:27 UTC
Sorry, the patch wasn't intended for inclusion as is; it is a patch I made for OpenWrt (which has a configuration option CONFIG_USE_MUSL that is available to the top-level Makefile).

The error that occurs when using musl combined with gccgo is:

sysinfo.go:6308:15: error: use of undefined type '_off64_t'
 type Offset_t _off64_t
               ^
/home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/syscall/libcall_linux.go:360:11: error: reference to undefined name '_loff_t'
   lroff = _loff_t(*roff)
           ^
/home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/syscall/libcall_linux.go:366:11: error: reference to undefined name '_loff_t'
   lwoff = _loff_t(*woff)
           ^
/home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/syscall/libcall_linux.go:357:12: error: use of undefined type '_loff_t'
  var lroff _loff_t
            ^
/home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/syscall/libcall_linux.go:357:12: error: use of undefined type '_loff_t'
/home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/syscall/libcall_linux.go:357:12: error: use of undefined type '_loff_t'
/home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/syscall/libcall_linux.go:357:12: error: use of undefined type '_loff_t'
/home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/syscall/libcall_linux.go:357:12: error: use of undefined type '_loff_t'
/home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/syscall/libcall_linux.go:357:12: error: use of undefined type '_loff_t'
/home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/syscall/libcall_linux.go:357:12: error: use of undefined type '_loff_t'
/home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/syscall/libcall_linux.go:357:12: error: use of undefined type '_loff_t'
/home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/syscall/libcall_linux.go:357:12: error: use of undefined type '_loff_t'
libtool: compile:  /home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0-final/./gcc/gccgo -B/home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0-final/./gcc/ -B/home/daniel/Build/openwrt/trunk/openwrt/staging_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/mips-openwrt-linux-musl/bin/ -B/home/daniel/Build/openwrt/trunk/openwrt/staging_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/mips-openwrt-linux-musl/lib/ -isystem /home/daniel/Build/openwrt/trunk/openwrt/staging_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/mips-openwrt-linux-musl/include -isystem /home/daniel/Build/openwrt/trunk/openwrt/staging_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/mips-openwrt-linux-musl/sys-include -O2 -g -DCONFIG_USE_MUSL -I . -c -fgo-pkgpath=math/cmplx /home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/math/cmplx/abs.go /home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/math/cmplx/asin.go /home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/math/cmplx/conj.go /home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/math/cmplx/exp.go /home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/math/cmplx/isinf.go /home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/math/cmplx/isnan.go /home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/math/cmplx/log.go /home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/math/cmplx/phase.go /home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/math/cmplx/polar.go /home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/math/cmplx/pow.go /home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/math/cmplx/rect.go /home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/math/cmplx/sin.go /home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/math/cmplx/sqrt.go /home/daniel/Build/openwrt/trunk/openwrt/build_dir/toolchain-mips_34kc_gcc-5.2.0_musl-1.1.11/gcc-5.2.0/libgo/go/math/cmplx/tan.go -o math/cmplx.o >/dev/null 2>&1
Makefile:5786: recipe for target 'syscall.lo' failed
make[7]: *** [syscall.lo] Error 1
make[7]: *** Waiting for unfinished jobs....




Basically the problem is that musl defines some of the required types as #defines, however the gccgo magic that turns C types into Go types requires that they be typedefs.  (the CONFIG_USE_MUSL is just there so that make can set -DCONFIG_USE_MUSL for use in mksysinfo.sh;  it is in mksysinfo.sh that we must, for musl, undefine the #define'd types and replace them with typedefs).

The patch was more for informational purposes, only I forgot to explain the full story.
Comment 3 Daniel Santos 2019-04-25 03:39:05 UTC
Confirmed.  Also present with gcc 7.3.0 and musl 1.1.19 (in addition to some multiply defined structs)
Comment 4 Daniel Santos 2020-10-17 14:01:40 UTC
Hello.  This is still a problem in 10.2 and I'm definitely going to need to solve this.  As near as I can tell, the underlying issue is libgo/config.h incorrectly being populated with HAVE_OFF64_T.

configure:11206: checking for off64_t
configure:11206: /home/daniel/proj/embedded/openwrt/head/build_dir/toolchain-mipsel_24kc_gcc-10.2.0_musl/gcc-10.2.0-final/./gcc/xgcc -B/home/daniel/proj/embedded/openwrt/head/build_dir/toolchain-mipsel_24kc_gcc-10.2.0_musl/gcc-10.2.0-final/./gcc/ -B/home/daniel/proj/embedded/openwrt/head/staging_dir/toolchain-mipsel_24kc_gcc-10.2.0_musl/mipsel-openwrt-linux-musl/bin/ -B/home/daniel/proj/embedded/openwrt/head/staging_dir/toolchain-mipsel_24kc_gcc-10.2.0_musl/mipsel-openwrt-linux-musl/lib/ -isystem /home/daniel/proj/embedded/openwrt/head/staging_dir/toolchain-mipsel_24kc_gcc-10.2.0_musl/mipsel-openwrt-linux-musl/include -isystem /home/daniel/proj/embedded/openwrt/head/staging_dir/toolchain-mipsel_24kc_gcc-10.2.0_musl/mipsel-openwrt-linux-musl/sys-include    -c -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -g3 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -Wformat -Werror=format-security -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE  conftest.c >&5
configure:11206: $? = 0
configure:11206: /home/daniel/proj/embedded/openwrt/head/build_dir/toolchain-mipsel_24kc_gcc-10.2.0_musl/gcc-10.2.0-final/./gcc/xgcc -B/home/daniel/proj/embedded/openwrt/head/build_dir/toolchain-mipsel_24kc_gcc-10.2.0_musl/gcc-10.2.0-final/./gcc/ -B/home/daniel/proj/embedded/openwrt/head/staging_dir/toolchain-mipsel_24kc_gcc-10.2.0_musl/mipsel-openwrt-linux-musl/bin/ -B/home/daniel/proj/embedded/openwrt/head/staging_dir/toolchain-mipsel_24kc_gcc-10.2.0_musl/mipsel-openwrt-linux-musl/lib/ -isystem /home/daniel/proj/embedded/openwrt/head/staging_dir/toolchain-mipsel_24kc_gcc-10.2.0_musl/mipsel-openwrt-linux-musl/include -isystem /home/daniel/proj/embedded/openwrt/head/staging_dir/toolchain-mipsel_24kc_gcc-10.2.0_musl/mipsel-openwrt-linux-musl/sys-include    -c -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kc -g3 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -Wformat -Werror=format-security -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE  conftest.c >&5
conftest.c: In function 'main':
conftest.c:146:22: error: expected expression before ')' token
  146 | if (sizeof ((off64_t)))
      |                      ^
configure:11206: $? = 1
configure: failed program was:
| /* confdefs.h */
| #define PACKAGE_NAME "package-unused"
| #define PACKAGE_TARNAME "libgo"
| #define PACKAGE_VERSION "version-unused"
| #define PACKAGE_STRING "package-unused version-unused"
| #define PACKAGE_BUGREPORT ""
| #define PACKAGE_URL ""
| #define STDC_HEADERS 1
| #define HAVE_SYS_TYPES_H 1
| #define HAVE_SYS_STAT_H 1
| #define HAVE_STDLIB_H 1
| #define HAVE_STRING_H 1
| #define HAVE_MEMORY_H 1
| #define HAVE_STRINGS_H 1
| #define HAVE_INTTYPES_H 1
| #define HAVE_STDINT_H 1
| #define HAVE_UNISTD_H 1
| #define HAVE_DLFCN_H 1
| #define LT_OBJDIR ".libs/"
| #define USE_LIBFFI 1
| #define HAVE_GETIPINFO 1
| #define HAVE_SCHED_H 1
| #define HAVE_SEMAPHORE_H 1
| #define HAVE_SYS_FILE_H 1
| #define HAVE_SYS_MMAN_H 1
| #define HAVE_SYSCALL_H 1
| #define HAVE_SYS_EPOLL_H 1
| #define HAVE_SYS_INOTIFY_H 1
| #define HAVE_SYS_PTRACE_H 1
| #define HAVE_SYS_SYSCALL_H 1
| #define HAVE_SYS_USER_H 1
| #define HAVE_SYS_UTSNAME_H 1
| #define HAVE_SYS_SELECT_H 1
| #define HAVE_SYS_SOCKET_H 1
| #define HAVE_NET_IF_H 1
| #define HAVE_NET_IF_ARP_H 1
| #define HAVE_NET_ROUTE_H 1
| #define HAVE_NETPACKET_PACKET_H 1
| #define HAVE_SYS_PRCTL_H 1
| #define HAVE_SYS_MOUNT_H 1
| #define HAVE_SYS_VFS_H 1
| #define HAVE_SYS_STATFS_H 1
| #define HAVE_SYS_TIMEX_H 1
| #define HAVE_SYS_SYSINFO_H 1
| #define HAVE_UTIME_H 1
| #define HAVE_LINUX_FS_H 1
| #define HAVE_LINUX_PTRACE_H 1
| #define HAVE_LINUX_REBOOT_H 1
| #define HAVE_NETINET_IP_H 1
| #define HAVE_NETINET_IF_ETHER_H 1
| #define HAVE_NETINET_ICMP6_H 1
| #define HAVE_LINUX_FILTER_H 1
| #define HAVE_LINUX_IF_ADDR_H 1
| #define HAVE_LINUX_IF_ETHER_H 1
| #define HAVE_LINUX_IF_TUN_H 1
| #define HAVE_LINUX_NETLINK_H 1
| #define HAVE_LINUX_RTNETLINK_H 1
| #define HAVE_STRERROR_R 1
| #define HAVE_STRSIGNAL 1
| #define HAVE_WAIT4 1
| #define HAVE_MINCORE 1
| #define HAVE_SETENV 1
| #define HAVE_UNSETENV 1
| #define HAVE_DL_ITERATE_PHDR 1
| #define HAVE_MEMMEM 1
| #define HAVE_ACCEPT4 1
| #define HAVE_DUP3 1
| #define HAVE_EPOLL_CREATE1 1
| #define HAVE_FACCESSAT 1
| #define HAVE_FALLOCATE 1
| #define HAVE_FCHMODAT 1
| #define HAVE_FCHOWNAT 1
| #define HAVE_FUTIMESAT 1
| #define HAVE_GETXATTR 1
| #define HAVE_INOTIFY_ADD_WATCH 1
| #define HAVE_INOTIFY_INIT 1
| #define HAVE_INOTIFY_INIT1 1
| #define HAVE_INOTIFY_RM_WATCH 1
| #define HAVE_LISTXATTR 1
| #define HAVE_MKDIRAT 1
| #define HAVE_MKNODAT 1
| #define HAVE_OPEN64 1
| #define HAVE_OPENAT 1
| #define HAVE_PIPE2 1
| #define HAVE_REMOVEXATTR 1
| #define HAVE_RENAMEAT 1
| #define HAVE_SETXATTR 1
| #define HAVE_SYNC_FILE_RANGE 1
| #define HAVE_SPLICE 1
| #define HAVE_SYSCALL 1
| #define HAVE_TEE 1
| #define HAVE_UNLINKAT 1
| #define HAVE_UNSHARE 1
| #define HAVE_UTIMENSAT 1
| #define HAVE_COSL 1
| #define HAVE_EXPL 1
| #define HAVE_LOGL 1
| #define HAVE_SINL 1
| #define HAVE_TANL 1
| #define HAVE_ACOSL 1
| #define HAVE_ASINL 1
| #define HAVE_ATANL 1
| #define HAVE_ATAN2L 1
| #define HAVE_EXPM1L 1
| #define HAVE_LDEXPL 1
| #define HAVE_LOG10L 1
| #define HAVE_LOG1PL 1
| #define HAVE_SEM_TIMEDWAIT 1
| /* end confdefs.h.  */
| #include <stdio.h>
| #ifdef HAVE_SYS_TYPES_H
| # include <sys/types.h>
| #endif
| #ifdef HAVE_SYS_STAT_H
| # include <sys/stat.h>
| #endif
| #ifdef STDC_HEADERS
| # include <stdlib.h>
| # include <stddef.h>
| #else
| # ifdef HAVE_STDLIB_H
| #  include <stdlib.h>
| # endif
| #endif
| #ifdef HAVE_STRING_H
| # if !defined STDC_HEADERS && defined HAVE_MEMORY_H
| #  include <memory.h>
| # endif
| # include <string.h>
| #endif
| #ifdef HAVE_STRINGS_H
| # include <strings.h>
| #endif
| #ifdef HAVE_INTTYPES_H
| # include <inttypes.h>
| #endif
| #ifdef HAVE_STDINT_H
| # include <stdint.h>
| #endif
| #ifdef HAVE_UNISTD_H
| # include <unistd.h>
| #endif
| int
| main ()
| {
| if (sizeof ((off64_t)))
| 	    return 0;
|   ;
|   return 0;
| }
configure:11206: result: yes



Incidentally, here's musl's note on off64_t: https://wiki.musl-libc.org/faq.html#Q:-Do-I-need-to-define-%3Ccode%3E_LARGEFILE64_SOURCE%3C/code%3E-to-get-64bit-%3Ccode%3Eoff_t%3C/code%3E?
Comment 5 Daniel Santos 2020-10-17 15:51:53 UTC
Created attachment 49393 [details]
Patch for musl compatibility

The root problem is that musl defines off64_t and loff_t as preprocessor macros.  These end up in gen-sysinfo.go as "// undefinedmacro" entries.  Perhaps the real solution would be for -fdump-go-spec to attempt to determine when a macro is for a type?

There is also a problem currently with struct sysinfo being defined multiple times due to musl defining it in sys/sysinfo.h instead of including linux/sysinfo.h -- I've just altered the musl header for now.
Comment 6 Andrew Pinski 2021-12-27 23:13:55 UTC
I think this is all fixed on the trunk after r12-5979 so closing as fixed.