From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x730.google.com (mail-qk1-x730.google.com [IPv6:2607:f8b0:4864:20::730]) by sourceware.org (Postfix) with ESMTPS id 0B6FF38582A2 for ; Tue, 11 Oct 2022 18:37:55 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 0B6FF38582A2 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-qk1-x730.google.com with SMTP id d13so2744330qko.5 for ; Tue, 11 Oct 2022 11:37:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=2DWX5XOYANYevI8HLa3R2jlCufyUSyy1kFsyl+0tBno=; b=ZqFuIJuB/bxGyYzti/OvKMcWhDfXVhsyUVnHeyXqt2lzSBynxTSme1c4RDCtdXbRBD d7wXYLQDyUh1Sh6IyGu1Y1w1dIPuHJYXZz21yXOdys0RVIGtSx4IuTgKo1BHnzEjNMrI CgKR8JNz9GF8fzgVE6mg2CpS9MH/6WLqtigT2pBq4i8kUxkMhfdmHUOBnM5eRFAsyWav Ni+Qvj8Zp6sfTTr1zIbwtJjey1x6Sm0cOBMRjVb9a4U306jaOc85GxwCTHYKctEttlAt IbWUFMnsmHhg2HaRC3nrnJdU31Y6mMKGVypw7tHz27ww67MFob7GvDQ5aVOZ225NDMnz PmAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=2DWX5XOYANYevI8HLa3R2jlCufyUSyy1kFsyl+0tBno=; b=sugl9DGC8B1xBZ9LnOlNEXQH5SrmH86TFjjv65jGLMnzN2h0YUoIYQsup7SU/0YsCu M4VcMbfSc4AfNyTxKG5hOIHwgHoLd2E2g+ltz95acezYtad/g0qo8S28gGUT0Bpn6I3y ThGc22WMTEWk3wEJzYdMddb59WwndxLYgjIi7L6iBJfmIbjj/J61YsUeWDCBVErO/kJY a/cb8MxgxsY9t8lAMlG2IWVR/Ut2Fu5SLfgyVIDBX2p37/ecUJemAvLu/2t5b10IUtfL fxmkpyGU/vvOUL908i4ne+FW9IuRnWCaagKw3Hkc1hUB0QFS/IzjAckRMyhddHnH0oeF Ue0g== X-Gm-Message-State: ACrzQf2n1qgjgKxkejte3gxKNkfqUcX5p9jniGVUV2Why/J0TL0gJ4Rp YwkCQRsFgQkljh03gO22nC/hbZoc4jM= X-Google-Smtp-Source: AMsMyM7dPFAd9Zyizq+zIGOLKGFQZeJGT274bNNW5Va9HsTnJfARSsDWgCG6pMAe1MYJDawwF9gZSQ== X-Received: by 2002:a37:60c7:0:b0:6ee:8f07:2681 with SMTP id u190-20020a3760c7000000b006ee8f072681mr1778698qkb.781.1665513474289; Tue, 11 Oct 2022 11:37:54 -0700 (PDT) Received: from lgmac-stevenwu.corp.netflix.com ([192.222.225.228]) by smtp.gmail.com with ESMTPSA id q6-20020a05620a0d8600b006bb82221013sm13620774qkl.0.2022.10.11.11.37.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 Oct 2022 11:37:53 -0700 (PDT) Message-ID: <6c5778d2edfaa8b5196ef142ad0339ac6233b641.camel@gmail.com> Subject: Re: Issue with dllexport/dllimport inline function From: xclaesse@gmail.com To: LIU Hao , gcc@gcc.gnu.org Date: Tue, 11 Oct 2022 14:37:53 -0400 In-Reply-To: <13cbf2ec-4027-3df7-aa76-3d680afc075b@126.com> References: <845fde640ac4cd51c8bb50373f146987b3d26893.camel@gmail.com> <874c106a-41bb-afe6-44a1-d725fdcd583b@126.com> <88c1e389-8d80-38bd-e1fa-e61d2653da8d@126.com> <0c24f08964acc66a402d94c1b6a389dee4efa163.camel@gmail.com> <13cbf2ec-4027-3df7-aa76-3d680afc075b@126.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.44.4-0ubuntu1 MIME-Version: 1.0 X-Spam-Status: No, score=0.3 required=5.0 tests=BAYES_00,BODY_8BITS,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP 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: Le mercredi 12 octobre 2022 =C3=A0 01:42 +0800, LIU Hao a =C3=A9crit=C2=A0: > =E5=9C=A8 2022-10-11 22:26, xclaesse@gmail.com=C2=A0=E5=86=99=E9=81=93: > > #ifdef GLIB_COMPILATION > > #=C2=A0 define _GLIB_API _GLIB_EXPORT > > #=C2=A0 define GLIB_INLINE __attribute__((__dllexport__)) > > __attribute__((__gnu_inline__)) extern inline >=20 > This is not correct. Typically, `dllexport` indicates that 'I want an > external definition' but=20 > `gnu_inline` indicates that 'I do not want an external definition', > so it's a contradiction: you get=20 > either multiple definitions, or none (which causes undefined > references). Sorry, that was a wrong copy/paste when writing the email (leftover of things I tried previously). I can confirm the multiple definition error I have is when that line is `# define GLIB_INLINE _GLIB_EXPORT extern inline`, which expands to `__declspec(dllexport) extern inline`. > To user code which imports such a function, it should be seen as >=20 > =C2=A0=C2=A0=C2=A0 ``` > =C2=A0=C2=A0=C2=A0 __attribute__((__gnu_inline__)) > =C2=A0=C2=A0=C2=A0 extern inline > =C2=A0=C2=A0=C2=A0 int g_strcmp0(const char*, const char*) > =C2=A0=C2=A0=C2=A0 ``` >=20 > This has the desired effect: The function can be inlined where > appropriate. And if not, a call to=20 > the external thunk is emitted; no weak definition is emitted in > either case. >=20 >=20 > To the library itself which exports it, it should be seen as >=20 > =C2=A0=C2=A0=C2=A0 ``` > =C2=A0=C2=A0=C2=A0 __attribute__((__dllexport__)) > =C2=A0=C2=A0=C2=A0 extern inline > =C2=A0=C2=A0=C2=A0 int g_strcmp0(const char*, const char*) > =C2=A0=C2=A0=C2=A0 ``` >=20 > There is no `gnu_inline` in this case. GCC always generates a > COMDAT/weak/linkonce definition, which=20 > will not cause multiple definition errors. Right, that's what I do and it fails. I made a simplified example: https://gitlab.gnome.org/xclaesse/inline-example Build it with: meson setup builddir --cross-file cross_file_mingw64.txt ninja -C builddir/ And it fails with: ``` x86_64-w64-mingw32-gcc -o libfoo.dll libfoo.dll.p/foo.c.obj libfoo.dll.p/bar.c.obj -Wl,--allow-shlib-undefined -shared -Wl,--start- group -Wl,--out-implib=3Dlibfoo.dll.a -fstack-protector -lkernel32 - luser32 -lgdi32 -lwinspool -lshell32 -lole32 -loleaut32 -luuid - lcomdlg32 -ladvapi32 -Wl,--end-group /usr/bin/x86_64-w64-mingw32-ld: libfoo.dll.p/bar.c.obj: in function `g_strcmp0': /home/xclaesse/programmation/inline-example/builddir/../foo.h:5: multiple definition of `g_strcmp0'; libfoo.dll.p/foo.c.obj:/home/xclaesse/programmation/inline- example/builddir/../foo.h:5: first defined here ``` Thanks for your help!