public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "max.sagebaum at scicomp dot uni-kl.de" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c++/104631] New: Visibility of static member s yields duplicate symbols. Date: Tue, 22 Feb 2022 08:12:55 +0000 [thread overview] Message-ID: <bug-104631-4@http.gcc.gnu.org/bugzilla/> (raw) https://gcc.gnu.org/bugzilla/show_bug.cgi?id=104631 Bug ID: 104631 Summary: Visibility of static member s yields duplicate symbols. Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: max.sagebaum at scicomp dot uni-kl.de Target Milestone: --- Created attachment 52488 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=52488&action=edit Small case for showing the bug. We develop a header only library where we have a static structure member inside of a class. We require that this static member is seen by all operations on this class. If our library is included with '-fvisibility=hidden' then we get multiple symbols of the same static member. We tried to fix this by declaring the static member with '__attribute__((visibility("default")))' but for members which are structs this does not seem to work. We created a simple example, that can reproduce the behavior. If the static member is an 'int' then everything works. If this static member is a structure, then there is a duplication of the symbols. You can run the example with 'make T=2'. 'T=1' sets no hidden flag and 'T=3' removes the hidden flag for the library. The output should always be: func: Pointer A<int>::counter: 0x404194 func: Pointer A<Inc>::counter.counter: 0x404198 main: Pointer A<int>::counter: 0x404194 main: Pointer A<Inc>::counter.counter: 0x404198 Counter value 'int': 1 Counter value 'Inc': 1 But with T=2 the output on our machines is: func: Pointer A<int>::counter: 0x404194 func: Pointer A<Inc>::counter.counter: 0x7f9f69625050 main: Pointer A<int>::counter: 0x404194 main: Pointer A<Inc>::counter.counter: 0x404198 Counter value 'int': 1 Counter value 'Inc': 0 In the real world case the struct 'Inc' is very involved and uses nearly every other structure in our library. We would be fine by changing the visibility of our library to default but we could not detect any preprocessor variables, that hint that the library is included with the hidden visibility. (That is '-fvisibility=hidden -E -dM func.cpp' and '-E -dM func.cpp' yielded the same results.) I hope this is the correct place to submit this bug and ask the question about the preprocessor macro. System: Fedora 5.16.9-200.fc35.x86_64 g++: g++ (GCC) 11.2.1 20220127 (Red Hat 11.2.1-9) ld: GNU ld version 2.37-10.fc35
next reply other threads:[~2022-02-22 8:12 UTC|newest] Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-02-22 8:12 max.sagebaum at scicomp dot uni-kl.de [this message] 2022-02-22 8:46 ` [Bug c++/104631] " pinskia at gcc dot gnu.org 2022-02-22 9:10 ` max.sagebaum at scicomp dot uni-kl.de 2022-04-22 14:58 ` amonakov at gcc dot gnu.org
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=bug-104631-4@http.gcc.gnu.org/bugzilla/ \ --to=gcc-bugzilla@gcc.gnu.org \ --cc=gcc-bugs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).