From owner-freebsd-hackers@FreeBSD.ORG Wed Jun 1 01:19:22 2011 Return-Path: Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3601B1065672 for ; Wed, 1 Jun 2011 01:19:22 +0000 (UTC) (envelope-from nwhitehorn@freebsd.org) Received: from agogare.doit.wisc.edu (agogare.doit.wisc.edu [144.92.197.211]) by mx1.freebsd.org (Postfix) with ESMTP id 08A948FC1C for ; Wed, 1 Jun 2011 01:19:21 +0000 (UTC) MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; CHARSET=US-ASCII; format=flowed Received: from avs-daemon.smtpauth2.wiscmail.wisc.edu by smtpauth2.wiscmail.wisc.edu (Sun Java(tm) System Messaging Server 7u2-7.05 32bit (built Jul 30 2009)) id <0LM300J007O9UO00@smtpauth2.wiscmail.wisc.edu> for freebsd-hackers@freebsd.org; Tue, 31 May 2011 20:19:21 -0500 (CDT) Received: from comporellon.tachypleus.net (adsl-71-150-248-94.dsl.mdsnwi.sbcglobal.net [71.150.248.94]) by smtpauth2.wiscmail.wisc.edu (Sun Java(tm) System Messaging Server 7u2-7.05 32bit (built Jul 30 2009)) with ESMTPSA id <0LM300GHZ7O7HP00@smtpauth2.wiscmail.wisc.edu> for freebsd-hackers@freebsd.org; Tue, 31 May 2011 20:19:20 -0500 (CDT) Date: Tue, 31 May 2011 20:19:19 -0500 From: Nathan Whitehorn In-reply-to: <20110531200652.3fd6fcbe@kan.dnsalias.net> To: freebsd-hackers@freebsd.org Message-id: <4DE59397.8010205@freebsd.org> X-Spam-Report: AuthenticatedSender=yes, SenderIP=71.150.248.94 X-Spam-PmxInfo: Server=avs-12, Version=5.6.0.2009776, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2011.6.1.10920, SenderIP=71.150.248.94 References: <20110531200652.3fd6fcbe@kan.dnsalias.net> User-Agent: Mozilla/5.0 (X11; U; FreeBSD amd64; en-US; rv:1.9.2.17) Gecko/20110429 Thunderbird/3.1.10 Subject: Re: sizeof(function pointer) X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 01 Jun 2011 01:19:22 -0000 On 05/31/11 19:06, Alexander Kabaev wrote: > On Tue, 31 May 2011 17:18:16 -0600 > Warner Losh wrote: > >> On May 31, 2011, at 5:07 PM, mdf@freebsd.org wrote: >> >>> I am looking into potentially MFC'ing r212367 and related, that adds >>> drains to sbufs. The reason for MFC is that several pieces of new >>> code in CURRENT are using the drain functionality and it would make >>> MFCing those changes much easier. >>> >>> The problem is that r212367 added a pointer to a drain function in >>> the sbuf (it replaced a pointer to void). The C standard doesn't >>> guarantee that a void * and a function pointer have the same size, >>> though its true on amd64, i386 and I believe PPC. What I'm >>> wondering is, though not guaranteed by the standard, is it >>> *practically* true that sizeof(void *) == sizeof(int(*)(void)), >>> such that an MFC won't break binary compatibility for any supported >>> architecture? (The standard does guarantee, though not in words, >>> that all function pointers have the same size, since it guarantees >>> that pointers to functions can be cast to other pointers to >>> functions and back without changing the value). >>> >>> Another possibility is to malloc a blob that is sizeof(int(*)(void)) >>> and store that in a renamed s_unused; this is a bit messier but >>> guaranteed to work. I'd just rather the code be an MCF instead of a >>> partial re-write. >> It is the same on MIPS too for all three ABIs that we support (and >> all ABIs that I know about). It is true on ARM as well. >> >> Usually it is different only on segmented architectures like 16-bit >> x86. >> > Not so on ia64, where they have special function descriptor type. > As is also true on PPC64 and (I think) at least some MIPS. But on all of these, a function pointer is a regular data pointer to the function descriptor, which then points to the function, so they are still the same size as a void *. -Nathan