From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd36.google.com (mail-io1-xd36.google.com [IPv6:2607:f8b0:4864:20::d36]) by sourceware.org (Postfix) with ESMTPS id 3DE623858D33 for ; Sat, 20 Mar 2021 22:40:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 3DE623858D33 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=moxielogic.com Authentication-Results: sourceware.org; spf=none smtp.mailfrom=green@moxielogic.com Received: by mail-io1-xd36.google.com with SMTP id v26so9998335iox.11 for ; Sat, 20 Mar 2021 15:40:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=moxielogic-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=OniDg/B9lkV/WpvN3SgDw0umww3XU28PmA7ZEnaKGsI=; b=zMaq0vYlFJighk+sBjYS8GOLJnChKfNyol/QmP549wvo2mDXT455EC6babGmjwKLoK GDmVcK4sb11mOkPs+ujywhtJ2BYntostbQZJEDhZAjZ39UNyLtatEKZvRGgoLPFEiIP6 oViffrq2w2+9Px4vRn5fQHJVNzidNnKNWbboSRkSI1zHt1H0PwvXJKjj+PuSnxUhOwhg Qga1BKlDx2XAqeB3E47PRfF/8tQlYoOrj7mrOgvFJLVaZ0Yt4W1auu0tfsCNlJJCh02R J3lzHr/f1XT3/Xqj3ecPkm1qbt0GF53qbJFXX8Is5hSNYXXST+AUe4b6eVfvwkMQGQq7 TtLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=OniDg/B9lkV/WpvN3SgDw0umww3XU28PmA7ZEnaKGsI=; b=PwOaf8uTmOssLVARXpeaKih8bKiJBTKZrtow3JXbZDUwcyGHlnzzonIXEUduPhwCJc ymTGKa4JEbhkiXzYZz3VffX/j5awX+2Nzmc9b5hqQQ5ax+pGMbzg5OzUJXJlBe8ipFlN aTeflD3o+lEyUKqBXbdXQkiQShh0Gdjg6Z6hQXV5IDbK5Xs2gpg+bNF5RQH7RJLlPmrD xF2Dn+lhwlpU7JModcj/C7OZ3NZXPrzWxh47VmzHpUgNQe+j23LCRvPvShua1LaFvctR 2g9YgJ0FB18HzC9QkJjDMD+8E5f5Wazf07YYxCUicR4cXm9FQ4u4fH0qObaK5HHKmpb7 zj+Q== X-Gm-Message-State: AOAM533HYVO6f8wActUOhVV6QgXXbLBT+gkkW8viNk+wrqjpJc480JbS 9Jc/qKWj0USodGF88INKgc3GNjV2FVr6e4O2X7jwog== X-Google-Smtp-Source: ABdhPJy7alESosmLr+831QLHVi7bEJNg7wx55yLJMguU9UJo1kVVespOlFuQPOSBGbAQIxXzEgH+Fx6RfeMP8VZw37k= X-Received: by 2002:a05:6638:3ba:: with SMTP id z26mr6289730jap.40.1616280016802; Sat, 20 Mar 2021 15:40:16 -0700 (PDT) MIME-Version: 1.0 References: <00aed94e-6f76-f6d7-9878-a3eb50dce543@163.com> <7c8729d8-d10e-cdb8-5518-e2f82ccbe141@redhat.com> <71f0c5ea-e3b7-176e-a0a1-29dceeff69b9@redhat.com> In-Reply-To: <71f0c5ea-e3b7-176e-a0a1-29dceeff69b9@redhat.com> From: Anthony Green Date: Sat, 20 Mar 2021 18:40:06 -0400 Message-ID: Subject: Re: How to call 'printf' using libffi? To: Andrew Haley Cc: libffi-discuss X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, HTML_MESSAGE, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: libffi-discuss@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libffi-discuss mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Mar 2021 22:40:18 -0000 It turns out there are problems with ffi_prep_cif_var(). One issue is that libffi doesn't promote floats to doubles for varargs, like most C hackers expect. There was a bug filed against that recently: https://github.com/libffi/libffi/issues/608 Should libffi do the promotion, or leave it as an exercise to the developer? Right now I'm thinking that it should simply abort in ffi_prep_cif_var() if passed any of ffi_type_float, ffi_type_*short, or ffi_type_*char and require that the caller handle promotions and only pass pointers, structs, doubles, ints or larger, as it seems that we're not promoting short integer values either. If I pass a very long list of varargs that end in a sequence of ffi_type_schar, for instance, the callee doesn't find the right values in the right stack locations. So maybe we shouldn't allow that in the first place. I'm interested in opinions. Thanks, AG On Fri, Mar 19, 2021 at 7:43 AM Andrew Haley wrote: > On 3/19/21 11:01 AM, Anthony Green wrote: > >>> ffi_prep_cif_var(&cif, FFI_DEFAULT_ABI, 1, 3, &ffi_type_sint, > >> arg_types); > >> > >> Surely that only works if a varargs call uses the same ABI as a normal > >> call. They don't always, > >> > > I'm using the '_var' variant of ffi_prep_cif that takes this into > account. > > Aha! Missed it. > > -- > Andrew Haley (he/him) > Java Platform Lead Engineer > Red Hat UK Ltd. > https://keybase.io/andrewhaley > EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671 > >