From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 176F03858D35 for ; Fri, 16 Jun 2023 17:27:29 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 176F03858D35 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1686936448; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=WJM1a1OPEjpvHhJqsoaYsm4PcRH/sZKPcsadlmt3AZI=; b=RmsCZJmkHVofWe1JvXancqKaQeRpafafTtDT1oZ05BduPAh51fSUCP3cIi27ZTqFCSIngf TB7nP0wHleWaQZJ76ZbGE2qQdpwRvIX9IWJzjWzx7KFMUFgspADbDfJCI9yhoLyFjC3DFU fTxgrXbHaY+4wvEAMwiID1qtvWgsG4k= Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-231-ZiuyCnJDPzyMIVaIfodNAA-1; Fri, 16 Jun 2023 13:27:27 -0400 X-MC-Unique: ZiuyCnJDPzyMIVaIfodNAA-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-62fe7c97262so9260766d6.0 for ; Fri, 16 Jun 2023 10:27:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686936446; x=1689528446; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=WJM1a1OPEjpvHhJqsoaYsm4PcRH/sZKPcsadlmt3AZI=; b=ebi1Yrg8jX1APf+GOMZ4Li3QOfFFDM0XoBIn4lfbu9akF4UXxzC+shMZSQJdDqM5CV i+iQ7vqahmbXIVvS5TZoN2lBd2i72EgccHKClikqZEl3OHZZLaCSTJ+oSQmsJwOJinf1 f9UrE9ERDT9cNpODD7iAKahRpUWzkTzkVi4nSIc6QoNBtrbH3zmleYbA77PV6gVyLO08 AhCP5Qr7ilQAJGYsSOj/tHFCs48QXbgTR+D4C3VCUxWQRrgF0gx39yK84x5M0vcu8+qI TEAqR/fKxnCmaXSiJLeN28BMI2lKoKLRxUd/tao90Y/3YeFYPETJ0ct6or3fAPKG8DnN 7POQ== X-Gm-Message-State: AC+VfDxhyIgktTOQbXFy8VaHSc/IXVzXePphFFu1C3HMqvSMWVndWHPl XBX2tK6i4+xrx6iqX7+S+nHAHvhdROICoPhkQLrKj7VRmD5Ta9lxWXGe2xORbF7o00/G2KxZClL uO8/JnLyyUfAQlZE= X-Received: by 2002:a05:6214:29e1:b0:62d:f04b:b51 with SMTP id jv1-20020a05621429e100b0062df04b0b51mr2202385qvb.29.1686936446157; Fri, 16 Jun 2023 10:27:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4US3r2h4ked3ADuJhRHYlxN75wfdNffMj8f64Z1txUGL9exb5Xrvyh8XjgRndqIuLIbNrruw== X-Received: by 2002:a05:6214:29e1:b0:62d:f04b:b51 with SMTP id jv1-20020a05621429e100b0062df04b0b51mr2202353qvb.29.1686936445513; Fri, 16 Jun 2023 10:27:25 -0700 (PDT) Received: from t14s.localdomain (c-76-28-97-5.hsd1.ma.comcast.net. [76.28.97.5]) by smtp.gmail.com with ESMTPSA id e21-20020a0caa55000000b0062608763edcsm7253455qvb.121.2023.06.16.10.27.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 16 Jun 2023 10:27:24 -0700 (PDT) Message-ID: Subject: Re: Interfacing with external code using libgccjit From: David Malcolm To: Anselm =?ISO-8859-1?Q?Sch=FCler?= , jit@gcc.gnu.org Date: Fri, 16 Jun 2023 13:27:24 -0400 In-Reply-To: References: User-Agent: Evolution 3.44.4 (3.44.4-2.fc36) MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-5.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Thu, 2023-06-15 at 21:59 +0200, Anselm Sch=C3=BCler wrote: > Hi, I=E2=80=99m very new to libgccjit and was hoping to use it to impleme= nt a > DSL that abstracts over some high-precision mathematics. Hi! > However, to do that, I need to interface with a high-precision > library=20 > such as GMP or MPFR. > I=E2=80=99m wondering if that=E2=80=99s possible.=C2=A0 It ought to be possible, but you need some way to express the declarations from the library's headers via the ligccjit API; we don't yet have a convenient way to take a header and express it in libgccjit form. As you note, doing it "by hand" is laborious; sorry that we=20 don't yet have an automated way of doing this. Possible approaches would be to use a library that can parse C headers, such as: https://github.com/vnmakarov/mir or perhaps using libabigail to work with the ABI representation: https://sourceware.org/libabigail/ (which would be parsing the debug data) > Can I use=20 > gcc_jit_context_new_function with GCC_JIT_FUNCTION_IMPORTED to define > such functions from e.g. MPFR?=C2=A0 Yes. > If so, is the function retrieved from=20 > the binary itself or does it need to be installed on the target=20 > machine?=C2=A0 It's equivalent to parsing a declaration from a header file; it doesn't bring in the definition of the function. > Do I need to pass -lmpfr to libgccjit or does it suffice to=20 > use it during the compilation of the host program? I believe you'd need to pass "-lmpfr" to gcc_jit_context_add_driver_option. > Additionally, it seems to be necessary to redefine all the types=20 > defined by the library in order to be able to pass and receive them. > Is=20 > there some facility for automating this? It seems rather laborious. >=20 Yes, as noted above, this is currently a major drawback, and an automated way of doing this would be very helpful. Hope this is helpful Dave