public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/107597] New: LTO causes static inline variables to get a non-uniqued global symbol
@ 2022-11-09 19:09 cfsteefel at arista dot com
  2022-11-10  7:31 ` [Bug c++/107597] " rguenth at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: cfsteefel at arista dot com @ 2022-11-09 19:09 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107597

            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=gnu++17 -O2 -shared -fPIC -o libFoo.so -flto test.cpp
> nm ./libFoo.so | c++filt | grep NonTemplated
000000000020102c B NonTemplated::x


> g++ -std=gnu++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 variable
NonTemplated::X as an ODR violation, if the class is included into more than
one flto compiled shared library.

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2023-01-04 17:28 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-09 19:09 [Bug c++/107597] New: LTO causes static inline variables to get a non-uniqued global symbol cfsteefel at arista dot com
2022-11-10  7:31 ` [Bug c++/107597] " rguenth at gcc dot gnu.org
2022-11-11 17:42 ` hubicka at ucw dot cz
2022-11-14 17:38 ` cfsteefel at arista dot com
2022-11-21 10:12 ` marxin at gcc dot gnu.org
2022-12-28  9:37 ` marxin at gcc dot gnu.org
2022-12-28  9:39 ` marxin at gcc dot gnu.org
2023-01-04 17:28 ` hubicka at gcc dot gnu.org

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).