From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14330 invoked by alias); 21 Jul 2005 23:03:28 -0000 Mailing-List: contact gcc-help-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Archive: List-Post: List-Help: Sender: gcc-help-owner@gcc.gnu.org Received: (qmail 14281 invoked by uid 22791); 21 Jul 2005 23:03:19 -0000 Received: from amdext3.amd.com (HELO amdext3.amd.com) (139.95.251.6) by sourceware.org (qpsmtpd/0.30-dev) with ESMTP; Thu, 21 Jul 2005 23:03:19 +0000 Received: from SSVLGW01.amd.com (ssvlgw01.amd.com [139.95.250.169]) by amdext3.amd.com (8.12.11/8.12.11/AMD) with ESMTP id j6LN3HMa000457 for ; Thu, 21 Jul 2005 16:03:17 -0700 Received: from 139.95.250.1 by SSVLGW01.amd.com with ESMTP (AMD SMTP Relay (Email Firewall v6.1.0)); Thu, 21 Jul 2005 16:03:09 -0700 X-Server-Uuid: 89466532-923C-4A88-82C1-66ACAA0041DF Received: from SSVLEXBH2.amd.com (SSVLEXBH2.amd.com [139.95.53.183]) by amdint.amd.com (8.12.8/8.12.8/AMD) with ESMTP id j6LN37Vo000049; Thu, 21 Jul 2005 16:03:07 -0700 (PDT) Received: from sausexmb2.amd.com ([163.181.3.157]) by SSVLEXBH2.amd.com with Microsoft SMTPSVC(6.0.3790.0); Thu, 21 Jul 2005 16:03:07 -0700 Received: from SBOSEXMB1.amd.com ([165.204.61.40]) by sausexmb2.amd.com with Microsoft SMTPSVC(6.0.3790.0); Thu, 21 Jul 2005 18:03:06 -0500 Content-class: urn:content-classes:message MIME-Version: 1.0 Subject: RE: Constructing function calls Date: Thu, 21 Jul 2005 23:03:00 -0000 Message-ID: <6096959DEF5C9447A6BF80BDC7EB9EDC2E9F41@SBOSEXMB1.amd.com> From: "Meissner, Michael" To: "Jean-Sebastien Legare" , gcc-help@gcc.gnu.org X-WSS-ID: 6EFEF6262Q47437610-01-01 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: quoted-printable X-SW-Source: 2005-07/txt/msg00229.txt.bz2 I would say it is impossible. The calling sequence depends on the type of the arguments, and the declaration of the called function (ie, often times functions that use variable arguments have a different calling sequence than functions with a fixed number of arguments). For example, a 64 bit floating point value is often passed within a floating point register, but a 64 bit integer might be required to be passed in an even:odd register pair on a 32-bit system. One possible way of 'solving' the program is change the code to use variable argument function calling sequence, use va_start to create the va_list object and pass it to the child, much like is done with vprintf. -----Original Message----- From: gcc-help-owner@gcc.gnu.org [mailto:gcc-help-owner@gcc.gnu.org] On Behalf Of Jean-Sebastien Legare Sent: Thursday, July 21, 2005 6:51 PM To: gcc-help@gcc.gnu.org Subject: Constructing function calls Hi I have a special task I would like to accomplish regarding construction of function calls, without (preferably) using __asm__ sections. I would like to pass a block of data containing arguments to a function from which I don't know the type nor number of arguments. The only thing I know=20 is the address of the function pointer and the size of the argument block (number of 32bit words). That is, I would like to fill this function: void call_func( (void*)func(), void* args, int size) { 1. push the contents of args to the stack; 2. call func() with no args (func will recuperate them from the stack); 3. return } For instance, I would like to be able to call : void print3ints(int a, int b, int c) { printf(" %d %d %d\n",a,b,c); } by doing : { int* args =3D malloc( 3 *sizeof(int)); args[0] =3D 1; args[1] =3D 2; args[2] =3D 3; call_func(print3ints,args,3); } I looked at "__builtin_apply" but it requires calling "__builtin_apply_args" beforehand, which I cannot do. I successfully managed to do that without using __asm__ on a x86.=20 I filled a local int array in call_func with the passed argument block and then=20 I called the passed function (stack bashing). However, the method breaks when compiling in -O3 mode and it would certainly not work on other systems where some arguments are passed inside registers. What are my best options ?