From patchwork Tue Nov 1 04:12:13 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ian Lance Taylor X-Patchwork-Id: 123018 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 0EA56B6F93 for ; Tue, 1 Nov 2011 15:12:54 +1100 (EST) Received: (qmail 22055 invoked by alias); 1 Nov 2011 04:12:42 -0000 Received: (qmail 21947 invoked by uid 22791); 1 Nov 2011 04:12:39 -0000 X-SWARE-Spam-Status: No, hits=-1.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_LOW, RP_MATCHES_RCVD, TW_ZJ, T_TVD_MIME_NO_HEADERS, URIBL_BLACK X-Spam-Check-By: sourceware.org Received: from mail-yw0-f47.google.com (HELO mail-yw0-f47.google.com) (209.85.213.47) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 01 Nov 2011 04:12:19 +0000 Received: by ywf9 with SMTP id 9so7576695ywf.20 for ; Mon, 31 Oct 2011 21:12:18 -0700 (PDT) Received: by 10.68.12.105 with SMTP id x9mr28328251pbb.109.1320120737804; Mon, 31 Oct 2011 21:12:17 -0700 (PDT) Received: by 10.68.12.105 with SMTP id x9mr28328193pbb.109.1320120737449; Mon, 31 Oct 2011 21:12:17 -0700 (PDT) Received: from coign.google.com ([216.239.45.130]) by mx.google.com with ESMTPS id 3sm55905085pbx.14.2011.10.31.21.12.15 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 31 Oct 2011 21:12:16 -0700 (PDT) From: Ian Lance Taylor To: Uros Bizjak Cc: Rainer Orth , gcc-patches@gcc.gnu.org, gofrontend-dev@googlegroups.com Subject: Re: [go]: Port to ALPHA arch - epoll problems References: Date: Mon, 31 Oct 2011 21:12:13 -0700 In-Reply-To: (Uros Bizjak's message of "Thu, 7 Jul 2011 13:34:53 +0200") Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.1 (gnu/linux) MIME-Version: 1.0 X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Uros Bizjak writes: > It turned out that the EpollEvent definition in > libgo/syscalls/epoll/socket_epoll.go is non-portable (if not outright > dangerous...). The definition does have a FIXME comment, but does not > take into account the effects of __attribute__((__packed__)) from > system headers. Contrary to alpha header, x86 has > __attribute__((__packed__)) added to struct epoll_event definition in > sys/epoll.h header. I couldn't work out a way to handle this correctly in mksysinfo.sh or -fdump-go-spec, so I did it in configure instead. Bootstrapped and tested on x86_64-unknown-linux-gnu. Committed to mainline. Let me know if it seems to do the right sort of thing on Alpha GNU/Linux--see if the generated file TARGET/libgo/epoll.h looks OK. Ian Index: libgo/configure.ac =================================================================== --- libgo/configure.ac (revision 180345) +++ libgo/configure.ac (working copy) @@ -505,6 +505,28 @@ CFLAGS="$CFLAGS -D_LARGEFILE_SOURCE -D_L AC_CHECK_TYPES(off64_t) CFLAGS=$CFLAGS_hold +dnl Work out the size of the epoll_events struct on GNU/Linux. +AC_CACHE_CHECK([epoll_event size], +[libgo_cv_c_epoll_event_size], +[AC_COMPUTE_INT(libgo_cv_c_epoll_event_size, +[sizeof (struct epoll_event)], +[#include ], +[libgo_cv_c_epoll_event_size=0])]) +SIZEOF_STRUCT_EPOLL_EVENT=${libgo_cv_c_epoll_event_size} +AC_SUBST(SIZEOF_STRUCT_EPOLL_EVENT) + +dnl Work out the offset of the fd field in the epoll_events struct on +dnl GNU/Linux. +AC_CACHE_CHECK([epoll_event data.fd offset], +[libgo_cv_c_epoll_event_fd_offset], +[AC_COMPUTE_INT(libgo_cv_c_epoll_event_fd_offset, +[offsetof (struct epoll_event, data.fd)], +[#include +#include ], +[libgo_cv_c_epoll_event_fd_offset=0])]) +STRUCT_EPOLL_EVENT_FD_OFFSET=${libgo_cv_c_epoll_event_fd_offset} +AC_SUBST(STRUCT_EPOLL_EVENT_FD_OFFSET) + AC_CACHE_SAVE if test ${multilib} = yes; then Index: libgo/go/syscall/socket_linux.go =================================================================== --- libgo/go/syscall/socket_linux.go (revision 180552) +++ libgo/go/syscall/socket_linux.go (working copy) @@ -164,15 +164,6 @@ func anyToSockaddrOS(rsa *RawSockaddrAny return nil, EAFNOSUPPORT } -// We don't take this type directly from the header file because it -// uses a union. FIXME. - -type EpollEvent struct { - Events uint32 - Fd int32 - Pad int32 -} - //sysnb EpollCreate(size int) (fd int, errno int) //epoll_create(size int) int Index: libgo/Makefile.am =================================================================== --- libgo/Makefile.am (revision 180552) +++ libgo/Makefile.am (working copy) @@ -1498,7 +1498,7 @@ endif # !LIBGO_IS_LINUX # Define socket sizes and types. if LIBGO_IS_LINUX -syscall_socket_file = go/syscall/socket_linux.go +syscall_socket_file = go/syscall/socket_linux.go epoll.go else if LIBGO_IS_SOLARIS syscall_socket_file = go/syscall/socket_solaris.go @@ -1582,6 +1582,34 @@ s-sysinfo: $(srcdir)/mksysinfo.sh config $(SHELL) $(srcdir)/../move-if-change tmp-sysinfo.go sysinfo.go $(STAMP) $@ +# The epoll struct has an embedded union and is packed on x86_64, +# which is too complicated for mksysinfo.sh. We find the offset of +# the only field we care about in configure.ac, and generate the +# struct here. +epoll.go: s-epoll; @true +s-epoll: Makefile + rm -f epoll.go.tmp + echo 'package syscall' > epoll.go.tmp + echo 'type EpollEvent struct {' >> epoll.go.tmp + echo ' Events uint32' >> epoll.go.tmp + case "$(SIZEOF_STRUCT_EPOLL_EVENT),$(STRUCT_EPOLL_EVENT_FD_OFFSET)" in \ + 0,0) echo 1>&2 "*** struct epoll_event data.fd offset unknown"; \ + exit 1; ;; \ + 8,4) echo ' Fd int32' >> epoll.go.tmp; ;; \ + 12,4) echo ' Fd int32' >> epoll.go.tmp; \ + echo ' Pad [4]byte' >> epoll.go.tmp; ;; \ + 12,8) echo ' Pad [4]byte' >> epoll.go.tmp; \ + echo ' Fd int32' >> epoll.go.tmp; ;; \ + 16,8) echo ' Pad [4]byte' >> epoll.go.tmp; \ + echo ' Fd int32' >> epoll.go.tmp; \ + echo ' Pad2 [4]byte' >> epoll.go.tmp; ;; \ + *) echo 1>&2 "*** struct epoll_event unsupported"; \ + exit 1; ;; \ + esac + echo '}' >> epoll.go.tmp + $(SHELL) $(srcdir)/../move-if-change epoll.go.tmp epoll.go + $(STAMP) $@ + if LIBGO_IS_LINUX # os_lib_inotify_lo = os/inotify.lo os_lib_inotify_lo =