From nobody Sun Aug 6 21:40:00 2023 X-Original-To: toolchain@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 4RJtCT2XS1z4mSmc for ; Sun, 6 Aug 2023 21:40:05 +0000 (UTC) (envelope-from cmt@burggraben.net) Received: from smtp.burggraben.net (smtp.burggraben.net [88.198.69.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "smtp.burggraben.net", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4RJtCS3WJ2z3DSY for ; Sun, 6 Aug 2023 21:40:04 +0000 (UTC) (envelope-from cmt@burggraben.net) Authentication-Results: mx1.freebsd.org; dkim=none; spf=pass (mx1.freebsd.org: domain of cmt@burggraben.net designates 88.198.69.140 as permitted sender) smtp.mailfrom=cmt@burggraben.net; dmarc=none Received: from elch.exwg.net (elch.exwg.net [IPv6:2001:470:7120:1:127b:44ff:fe4f:148d]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "elch.exwg.net", Issuer "R3" (not verified)) by smtp.burggraben.net (Postfix) with ESMTPS id DD6AAC0031C for ; Sun, 6 Aug 2023 23:40:01 +0200 (CEST) Received: by elch.exwg.net (Postfix, from userid 1000) id C2CB33AB04; Sun, 6 Aug 2023 23:40:00 +0200 (CEST) Date: Sun, 6 Aug 2023 23:40:00 +0200 From: Christoph Moench-Tegeder To: toolchain@freebsd.org Subject: c++: dynamic_cast woes Message-ID: List-Id: Maintenance of FreeBSD s integrated toolchain List-Archive: https://lists.freebsd.org/archives/freebsd-toolchain List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-toolchain@freebsd.org X-BeenThere: freebsd-toolchain@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline User-Agent: Mutt/2.2.10 (2023-03-25) X-Spamd-Result: default: False [-1.99 / 15.00]; NEURAL_HAM_LONG(-0.98)[-0.980]; NEURAL_HAM_SHORT(-0.38)[-0.382]; RCVD_IN_DNSWL_MED(-0.20)[88.198.69.140:from]; R_SPF_ALLOW(-0.20)[+ip4:88.198.69.140]; NEURAL_HAM_MEDIUM(-0.13)[-0.128]; MIME_GOOD(-0.10)[text/plain]; MIME_TRACE(0.00)[0:+]; FROM_EQ_ENVFROM(0.00)[]; MLMMJ_DEST(0.00)[toolchain@freebsd.org]; R_DKIM_NA(0.00)[]; DMARC_NA(0.00)[burggraben.net]; RCVD_TLS_LAST(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; FREEFALL_USER(0.00)[cmt]; ARC_NA(0.00)[]; ASN(0.00)[asn:24940, ipnet:88.198.0.0/16, country:DE]; FROM_HAS_DN(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[toolchain@freebsd.org]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; RCVD_COUNT_TWO(0.00)[2] X-Spamd-Bar: - X-Rspamd-Queue-Id: 4RJtCS3WJ2z3DSY Hi, while updating our kicad port I'm facing major problems with dynamic_cast on FreeBSD 13.2/amd64 - issues are seen with both base clang and devel/llvm15, and I guess we're rather talking libc++ here. Specifically, dynamic_cast fails when casting from a base to a derived type ("downcast" as in C++ lingo?). I already know about "--export-dynamic" but that does not help here - and as far as I read other platform's build scripts, no other platform requires any kind of "special handling" for dynamic_cast to work - what am I holding wrong here, or what's missing from the picture? But for the gory details: here's exhibit A, the code in question: https://gitlab.com/kicad/code/kicad/-/blob/7.0/include/settings/settings_manager.h?ref_type=heads#L110 That m_settings is declared as std::vector> m_settings; and contains objects of types derived from JSON_SETTINGS (there's the intermediate type APP_SETTINGS_BASE, and specific types like KICAD_SETTINGS etc.) The function GetAppSettings() is called, so that the find_if() in there should return that one KICAD_SETTINGS object from m_settings as only that should satisfy dynamic_cast - but in fact, no object is found. That also happens if I unwind the find_if() and build a simple for-loop (as one did, back in the last millenium). If I point gdb at that m_settings (with "set print object on" and "set print vtbl on"), I do find my KICAD_SETTINGS object smack in the middle of m_settings: (gdb) print *(m_settings[5]) $18 = (KICAD_SETTINGS) { = { = { _vptr$JSON_SETTINGS = 0xed1578 , so the type info isn't totally lost here. When testing this, CXXFLAGS passed via cmake are rather minimal, like "-std=c++17 -O0 -fstack-protector-strong -fno-strict-aliasing -Wl,--export-dynamic" (and cmake sprinkles some "-g" and a few other standard flags into the mix), LDFLAGS ("CMAKE_...LINKER_FLAGS") are set up similarly) (I have some inkling that these cmakefiles in this project are not always very strict on compiling vs linking). I had similar issues with dynamic_cast before, as witnessed here: https://cgit.freebsd.org/ports/tree/cad/kicad/files/patch-job_use_dynamic_cast_for_updating but now that I'm facing the current problem, I have a strong feeling that my diagnosis back than was rather bullshit. Help? Thanks, Christoph -- Spare Space