From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 4081E3858C27; Fri, 10 Dec 2021 13:11:10 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4081E3858C27 From: "mathieu.malaterre at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/103629] Possible miscompilation triggered by -fvisibility=hidden Date: Fri, 10 Dec 2021 13:11:10 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 11.2.0 X-Bugzilla-Keywords: wrong-code X-Bugzilla-Severity: normal X-Bugzilla-Who: mathieu.malaterre at gmail dot com X-Bugzilla-Status: RESOLVED X-Bugzilla-Resolution: INVALID X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Dec 2021 13:11:10 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D103629 --- Comment #8 from Mathieu Malaterre = --- % more CMakeLists.txt main.cc Module.cc openvdb.cc Tree.h :::::::::::::: CMakeLists.txt :::::::::::::: cmake_minimum_required(VERSION 3.13) project(p) # only export limited set of symbols set(CMAKE_C_VISIBILITY_PRESET hidden) set(CMAKE_CXX_VISIBILITY_PRESET hidden) set(CMAKE_VISIBILITY_INLINES_HIDDEN 1) # important to have pthread at runtime: set(CMAKE_THREAD_PREFER_PTHREAD TRUE) set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads REQUIRED) # important to use SHARED: add_library(openvdb SHARED openvdb.cc) target_include_directories(openvdb PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) add_executable(vdb_view main.cc Module.cc) target_link_libraries(vdb_view openvdb Threads::Threads) target_include_directories(vdb_view PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) :::::::::::::: main.cc :::::::::::::: void initialize(); int main(int , char *[]) { initialize(); return 0; } :::::::::::::: Module.cc :::::::::::::: #include "Tree.h" class Module { void init(); }; void Module::init() // no-inline { Tree::treeType(); } :::::::::::::: openvdb.cc :::::::::::::: #include "Tree.h" static std::string do_segfault() { return Tree::treeType(); } __attribute__((visibility("default"))) void initialize() { do_segfault(); } :::::::::::::: Tree.h :::::::::::::: #pragma once #include #include class Tree { public: static const std::string treeType() { static std::once_flag once; std::call_once(once, []() { sTreeTypeName.reset(new std::string()); }); return *sTreeTypeName; } private: static std::unique_ptr sTreeTypeName; }; std::unique_ptr Tree::sTreeTypeName;=