From nobody Mon Apr 25 22:39:48 2022 X-Original-To: freebsd-hackers@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id E55B71A9B800 for ; Mon, 25 Apr 2022 22:40:04 +0000 (UTC) (envelope-from marklmi@yahoo.com) Received: from sonic314-20.consmr.mail.gq1.yahoo.com (sonic314-20.consmr.mail.gq1.yahoo.com [98.137.69.83]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4KnKhg2TMWz3KLK for ; Mon, 25 Apr 2022 22:40:03 +0000 (UTC) (envelope-from marklmi@yahoo.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1650926396; bh=6spWwvjh45tedfuKsrdoNp0aE8LvYxubEiXloE5jxA0=; h=From:Subject:Date:Cc:To:References:From:Subject:Reply-To; b=gad3+/Z21UNoWJ8Ouc4MkYOypLQ5ujwEZ9T2KdCpoUJ7bbA3T+IbmXpEnMixfE02enWpSGqmgIMC6gTydfRgkL/ZSxS08cHVGgVJ8VjdHEjJn77UI5/QqfIFAQIySi9Y9miZxeXfRvT3xZ3o76UTmMQxTdcrzFaBZRqp5Q0B1j0/JB5TuiVZ/YXsptjbfXqHO5QWd4R3EHIisV4m4TUX8cmjjNeWHy74LGhYuuN1gNwysawV+K8LzBWS+8KOQqn4i8AYxWipPmAEA3oo9cvq+axNvBOdl8LR7qVwYM86/d1oNzLdRG1YWzcg/Qobn6Ft3cCtv8qERrWXxsRVkQ2cyg== X-SONIC-DKIM-SIGN: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1650926396; bh=kc9GAgfvM4Wp9pRLaWkEwfNeo70nyHqBBVDr2oKTr82=; h=X-Sonic-MF:From:Subject:Date:To:From:Subject; b=p8VmTT0/ykk/B+xfyv+Gy5qvp3C/T+lgYZO7dELs3WhgGqIhQN9CmQICAh4M+BeXwNc7Z/APyfxDhO2nwp0B5KEevAcWPRAFmio6C/Z73ConUOaKEeqrlMSGZDxsBDYZz8fR9zQX4BsrZ+cKARei29AAW1jiM1UoEchb2542dk/zb6qz2uHbCFn2LoHn0bzef93WQNgr1y3s2wsFjqb3pPszwsATewlZOt6+V8KOYT09wEOElTPax+EcOr15j0ApesdDgjo0+/LMgGBuWclT9VCFXoavy1hwgv3h221/ec5f7ZsIIs6nxql4rt2zi6iGvJIUnQ2FXCdInTYZyDCMbQ== X-YMail-OSG: gPUZB8oVM1nLmX.ERYtVbJpZ_itDazhp670ExdTQsKyrx8GKihSbisQ_ZTW8Toa 4bQ.laIw2.Yh.whvkAni9MrEGwyFrzR1UejEO6ZUdnO0F56NKXe481LjzPvqtuEsDRPV75y1FL8o x75FltChpbHRc3M4xS6baxLh1jznUZDZuOPi1hwPX505AMANZg0IZYwHEnjgHuxhOkp06DGOte7E u9x40_9engubYXkc25l9yCOwoB88T9GdJkGLVvg9YgGGGg8jrc277_eMammMsV_6fwqr1I.HC057 fjOts4QdldPrWAbN0CV1Yv0GWBdrwEElB5Ycpk2h_v4YRFUszBssrbUPoShUgECtNjWOeJExyxyQ YfqYDB2aBxzYWR1O4iBFBNn75a3Jjwahe48sbPy_w472JOPofdabjXv4u2PMODpAmPW4kj4pdH6i ccEjh_wSUp8H5yutgioTOvc69Cme9hhBJtII7HXD8nTukSuonV1X7902sNyxpBV0bIrh3pzKFgFm mIdoQR06AiJNU9dZk4RE4CSkkxtXDa6FX9sBBbJeQyV.JYQeAMOCOylZ7dJLlCFpi3gWSmZHOKki dJ1uUP7MaiMObHekTDrOCjAgmM3e6vMdn0DUqTQCC_3DzHKWoFbVPwwh_g.ONWmgzz38y9ZxanZL iprBO_yZGnowQAlNl8LaRknPxjjr.AZOrOIpOl7_ghawYJr7dTvk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FtX3XFc 3E2UwEO.O9fYLagJidofRlzBSJGuGVLHOsZclLEC6O.NuTY3_GjZhBH7qOx9IFs.KdivvYSNAR5e y0ZKHn4BLXXGFtelqdXdWopNCgGDpOgLlnYT.WM38NDBTeplgTn_X.EchavHZYVoVd7.C3wWrhMs 97P.cjfwaBPvFzpCE9wIQCHHn2dpWSChN50ie3pcb4scio01FthKXh8ITzW0.v5_pSf.qAR1YrUu S.veAFqjExTqsHWq2P2RDsxZq0m6pTJTumBtje6480XprdJb7g1GDIRw4h4H7UdEWy0T.hBLAu4t aAkDzKqeAgF91.RV2yZfVM2EBwl0IljvRSGL9huQLhdx.u.UtKOrCoenraR3bb3tkReaO0iMAyoA L8b31mjh5b1jNKyWHzBOvgLVIjUBKIdP09LGEN8Jwlo1wvsJyFXGMu2rrvMJuTzuzrE7oWYanGon 4iBgtL3gPVhy2n2SqyJX5._mUXm3sPYdCKFHC_VIMW_qckrSik.m.lfv7tYpkEVvme7X2v9P5CDU 8mau2wAfZjlu2hMxdefA- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic314.consmr.mail.gq1.yahoo.com with HTTP; Mon, 25 Apr 2022 22:39:56 +0000 Received: by hermes--canary-production-bf1-7cfdddd556-gh5b7 (Yahoo Inc. Hermes SMTP Server) with ESMTPA ID e69192b701c5c95921ac0ecf7a1c9e77; Mon, 25 Apr 2022 22:39:50 +0000 (UTC) From: Mark Millard Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable List-Id: Technical discussions relating to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-hackers List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-hackers@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: llvm & RTTI over shared libraries Message-Id: <079B1A26-DA8B-4158-8FD4-28EE1374CF1F@yahoo.com> Date: Mon, 25 Apr 2022 15:39:48 -0700 Cc: joerg@bec.de To: jbo@insane.engineer, FreeBSD Hackers X-Mailer: Apple Mail (2.3654.120.0.1.13) References: <079B1A26-DA8B-4158-8FD4-28EE1374CF1F.ref@yahoo.com> X-Rspamd-Queue-Id: 4KnKhg2TMWz3KLK X-Spamd-Bar: --- Authentication-Results: mx1.freebsd.org; dkim=pass header.d=yahoo.com header.s=s2048 header.b="gad3+/Z2"; dmarc=pass (policy=reject) header.from=yahoo.com; spf=pass (mx1.freebsd.org: domain of marklmi@yahoo.com designates 98.137.69.83 as permitted sender) smtp.mailfrom=marklmi@yahoo.com X-Spamd-Result: default: False [-3.46 / 15.00]; RCVD_TLS_LAST(0.00)[]; ARC_NA(0.00)[]; R_DKIM_ALLOW(-0.20)[yahoo.com:s=s2048]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FREEMAIL_FROM(0.00)[yahoo.com]; MV_CASE(0.50)[]; MIME_GOOD(-0.10)[text/plain]; R_SPF_ALLOW(-0.20)[+ptr:yahoo.com]; NEURAL_HAM_LONG(-1.00)[-1.000]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; DKIM_TRACE(0.00)[yahoo.com:+]; DMARC_POLICY_ALLOW(-0.50)[yahoo.com,reject]; RCVD_IN_DNSWL_NONE(0.00)[98.137.69.83:from]; NEURAL_HAM_SHORT(-0.96)[-0.958]; MLMMJ_DEST(0.00)[freebsd-hackers]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[yahoo.com]; ASN(0.00)[asn:36647, ipnet:98.137.64.0/20, country:US]; RCVD_COUNT_TWO(0.00)[2]; MID_RHS_MATCH_FROM(0.00)[]; DWL_DNSWL_NONE(0.00)[yahoo.com:dkim] X-ThisMailContainsUnwantedMimeParts: N =E2=80=A2 wrote on =E2=80=A2 Date: Mon, 25 Apr 2022 13:01:48 UTC : > I've created a small minimal test case which reproduces the problem = (attached). > The key points here are: > - CMake based project consisting of: > - The header-only interface for the plugin and the types = (test-interface). > - The main executable that loads the plugin (test-core). > - A plugin implementation (plugin-one). > - Compiles out-of-the-box on FreeBSD 13/stable with both lang/gcc11 = and devel/llvm14. > - It uses the exact mechanism I use to load the plugins in my actual = application. >=20 > stdout output when compiling with lang/gcc11: >=20 > t is type int > t is type string > done. >=20 >=20 > stdout output when compiling with lang/llvm14: >=20 > could not cast t > could not cast t > done. >=20 >=20 > Unfortunately, I could not yet figure out which compiler/linker flags = llvm requires to implement the same behavior as GCC does. I understand = that eventually I'd be better of rewriting the necessary parts to = eliminate that problem but this is not a quick job. >=20 > Could somebody lend me a hand in figuring out which compiler/linker = flags are necessary to get this to work with llvm? The GCC default behavior is technically wrong. GCC allows being = configured to do the correct thing --at the cost of ABI mismatches vs. what they = originally did. (At least that is how I understand what I read in the code.) To my knowledge LLVM does not allow clang++ being configured to do the = wrong thing: it never had the ABI messed up and so did not face the = self-compatibility question. (Bug-for-bug clang++ vs. g++ compatibility has not been the = major goal.) I have a nearly-minimalist change to your example that makes it result = in: # ./test-core t is type_int t is type_string done. under clang. I pasted a diff -ruN in the message later below but that = may lead to white space not being fully preserved. (I could send it to you = in another form if it proved needed.) Basically I avoid inline definitions of: virtual ~type_base(); virtual ~type_int(); virtual ~type_string(); Also, these are deliberately(!) the first non-inline virtual member functions in the 3 types. Where the implementations are placed controls were the type_info is put for the 3 types. (Not a language definition issue but a fairly common implementation technique.) I also make the place with the implementation be a tiny .so that both test-core and libplugin-one.so are bound to. This makes them use the same type_info definitions instead of having multiple competing ones around, sort of a form of single-definition-rule (unique addresses in the process). With the single definition rule followed, RTTI works just fine. I do warn that this is the first direct adjustment of cmake material that I've ever done. So if anything looks odd for how I did the cmake aspects, do not be surprised. I'm not cmake literate. For reference: # find clang_test_dist_m_m/ -print clang_test_dist_m_m/ clang_test_dist_m_m/plugins clang_test_dist_m_m/plugins/CMakeLists.txt clang_test_dist_m_m/plugins/plugin_one clang_test_dist_m_m/plugins/plugin_one/CMakeLists.txt clang_test_dist_m_m/plugins/plugin_one/plugin.cpp clang_test_dist_m_m/shared_types_impl clang_test_dist_m_m/shared_types_impl/CMakeLists.txt clang_test_dist_m_m/shared_types_impl/types_impl.cpp clang_test_dist_m_m/core clang_test_dist_m_m/core/dlclass.hpp clang_test_dist_m_m/core/CMakeLists.txt clang_test_dist_m_m/core/main.cpp clang_test_dist_m_m/CMakeLists.txt clang_test_dist_m_m/interface clang_test_dist_m_m/interface/plugin.hpp clang_test_dist_m_m/interface/types.hpp clang_test_dist_m_m/interface/CMakeLists.txt where the diff -ruN is . . . diff -ruN clang_test_dist/ clang_test_dist_m_m/ | more diff -ruN clang_test_dist/CMakeLists.txt = clang_test_dist_m_m/CMakeLists.txt --- clang_test_dist/CMakeLists.txt 2022-04-19 13:38:59.000000000 = -0700 +++ clang_test_dist_m_m/CMakeLists.txt 2022-04-25 12:51:03.448582000 = -0700 @@ -5,4 +5,5 @@ =20 add_subdirectory(core) add_subdirectory(interface) +add_subdirectory(shared_types_impl) add_subdirectory(plugins) diff -ruN clang_test_dist/core/CMakeLists.txt = clang_test_dist_m_m/core/CMakeLists.txt --- clang_test_dist/core/CMakeLists.txt 2022-04-19 13:38:59.000000000 = -0700 +++ clang_test_dist_m_m/core/CMakeLists.txt 2022-04-25 = 13:18:52.539921000 -0700 @@ -19,9 +19,12 @@ PRIVATE test-interface dl + PUBLIC + shared-types-impl ) =20 add_dependencies( ${TARGET} + shared-types-impl plugin-one ) diff -ruN clang_test_dist/interface/types.hpp = clang_test_dist_m_m/interface/types.hpp --- clang_test_dist/interface/types.hpp 2022-04-19 13:38:59.000000000 = -0700 +++ clang_test_dist_m_m/interface/types.hpp 2022-04-25 = 14:48:52.534159000 -0700 @@ -7,18 +7,20 @@ =20 struct type_base { - virtual ~type_base() =3D default; + virtual ~type_base(); }; =20 struct type_int : type_base { + virtual ~type_int(); int data; }; =20 struct type_string : type_base { + virtual ~type_string(); std::string data; }; =20 diff -ruN clang_test_dist/plugins/plugin_one/CMakeLists.txt = clang_test_dist_m_m/plugins/plugin_one/CMakeLists.txt --- clang_test_dist/plugins/plugin_one/CMakeLists.txt 2022-04-19 = 13:38:59.000000000 -0700 +++ clang_test_dist_m_m/plugins/plugin_one/CMakeLists.txt = 2022-04-25 13:19:20.188778000 -0700 @@ -12,3 +12,14 @@ PRIVATE plugin.cpp ) + +target_link_libraries( + ${TARGET} + PUBLIC + shared-types-impl +) + +add_dependencies( + ${TARGET} + shared-types-impl +) diff -ruN clang_test_dist/shared_types_impl/CMakeLists.txt = clang_test_dist_m_m/shared_types_impl/CMakeLists.txt --- clang_test_dist/shared_types_impl/CMakeLists.txt 1969-12-31 = 16:00:00.000000000 -0800 +++ clang_test_dist_m_m/shared_types_impl/CMakeLists.txt = 2022-04-25 12:55:29.760985000 -0700 @@ -0,0 +1,15 @@ +set(TARGET shared-types-impl) +add_library(${TARGET} SHARED) + +target_compile_features( + ${TARGET} + PRIVATE + cxx_std_20 +) + +target_sources( + ${TARGET} + PRIVATE + types_impl.cpp +) + diff -ruN clang_test_dist/shared_types_impl/types_impl.cpp = clang_test_dist_m_m/shared_types_impl/types_impl.cpp --- clang_test_dist/shared_types_impl/types_impl.cpp 1969-12-31 = 16:00:00.000000000 -0800 +++ clang_test_dist_m_m/shared_types_impl/types_impl.cpp = 2022-04-25 14:49:23.599440000 -0700 @@ -0,0 +1,5 @@ +#include "../interface/types.hpp" + +interface::type_base::~type_base() {} +interface::type_int::~type_int() {} +interface::type_string::~type_string() {} That is all there is to the changes. =3D=3D=3D Mark Millard marklmi at yahoo.com