From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id DDAA63858D33; Wed, 9 Nov 2022 19:09:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DDAA63858D33 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668020974; bh=Gt5sTYRKw8e/zVzU1iVZ/HZMECyrE/LrdamLH2f0dac=; h=From:To:Subject:Date:From; b=gYVISWopzvYA+XQr8vYqFUAY5gYaeniO4TmcyavW2eK/UZiVKIPkovMvc6iGBQkct DJSbDUsMPRuQ4G/wkrCxml6rQOzyGw773jDoz8lD0ymKp5xNt/4KHd6rn5OT0tABjy 6kTAc4V8subqrYdsvOht2hKXwd5TESgjra42xlyE= From: "cfsteefel at arista dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/107597] New: LTO causes static inline variables to get a non-uniqued global symbol Date: Wed, 09 Nov 2022 19:09:34 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c++ X-Bugzilla-Version: 8.4.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: cfsteefel at arista dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: 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 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D107597 Bug ID: 107597 Summary: LTO causes static inline variables to get a non-uniqued global symbol Product: gcc Version: 8.4.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: cfsteefel at arista dot com Target Milestone: --- The following was seen with gcc 11.3.1 (centos7 based) and gcc 8.4 (also centos7 based). The following code produces a GNU extension unique symbol for NonTemplated:= :x when flto is not used ('u' in nm), but a global non-unique symbol when flto= is used, even when building a shared library ('B' in nm). class NonTemplated { static inline int x; public: void doFoo() { x++; } }; int main() { NonTemplated n; n.doFoo(); return 0; } > g++ -std=3Dgnu++17 -O2 -shared -fPIC -o libFoo.so -flto test.cpp > nm ./libFoo.so | c++filt | grep NonTemplated 000000000020102c B NonTemplated::x > g++ -std=3Dgnu++17 -O2 -shared -fPIC -o libFoo.so test.cpp > nm ./libFoo.so | c++filt | grep NonTemplated 000000000020102c u NonTemplated::x When compiled under clang++, the symbol is `V` (weak) regardless of flto is used or not. The resulting symptom of this is that Address Sanitizer will flag the varia= ble NonTemplated::X as an ODR violation, if the class is included into more than one flto compiled shared library.=