[Bug c++/107597] LTO causes static inline variables to get a non-uniqued global symbol

2023-01-04 Thread hubicka at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107597

--- Comment #7 from Jan Hubicka  ---
So I guess it is asan being confused by our optimization.  We intentionaly
duplicate the symbol in order to reduce cost of dynamic linking in situations
where we know it does not change semantics, but asan looks for such duplicates
and consider them ODR violations.

I guess we want to disable the optimization with -fsanitize-address.  I will
try to cook up a patch.

[Bug c++/107597] LTO causes static inline variables to get a non-uniqued global symbol

2022-12-28 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107597

Martin Liška  changed:

   What|Removed |Added

   Assignee|marxin at gcc dot gnu.org  |unassigned at gcc dot 
gnu.org
 Status|ASSIGNED|NEW

--- Comment #6 from Martin Liška  ---
> So this is kind of feature.   How the ODR violations are detected?
> I wonder if keeping weak flag disturbs something.

ASAN emits so-called ODR indicators for all global symbols that survive the
following check: asan_needs_odr_indicator_p (tree decl)
in asan.cc:3216

And that's we see 2 of them:

marxin@marxinbox:~/Programming/testcases/PR107597> nm libTest1.so | grep odr
40c0 B __odr_asan._ZN12NonTemplated1xE
marxin@marxinbox:~/Programming/testcases/PR107597> nm libTest2.so | grep odr
40c0 B __odr_asan._ZN12NonTemplated1xE

which eventually ends up with the run-time error.

[Bug c++/107597] LTO causes static inline variables to get a non-uniqued global symbol

2022-12-28 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107597

--- Comment #5 from Martin Liška  ---
> 
> So this is kind of feature.   How the ODR violations are detected?

ASAN emits 

> I wonder if keeping weak flag disturbs something.

[Bug c++/107597] LTO causes static inline variables to get a non-uniqued global symbol

2022-11-21 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107597

Martin Liška  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |marxin at gcc dot 
gnu.org
 CC||marxin at gcc dot gnu.org
 Status|NEW |ASSIGNED

--- Comment #4 from Martin Liška  ---
I'll take a look at why it's not caught by ASAN.

[Bug c++/107597] LTO causes static inline variables to get a non-uniqued global symbol

2022-11-14 Thread cfsteefel at arista dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107597

--- Comment #3 from Christoph Steefel  ---
Address sanitizer is the one that flags it.
This is the code I used to reproduce the failure.

test.h:
class NonTemplated {
   static inline int x;
   public:
   void doFoo() {
  x++;
   }
};

int foo();
int bar();

test1.cpp:
#include "test.h"
int foo() {
   NonTemplated n;
   n.doFoo();
   return 1;
}

test2.cpp:
#include "test.h"
int bar() {
   NonTemplated n;
   n.doFoo();
   return 1;
}

main.cpp:
#include "test.h"
int main(){
   foo();
   bar();
   return 0;
}

>  g++ -shared -o libTest1.so -flto -fsemantic-interposition -fPIC test1.cpp 
> -fsanitize=address
> g++ -shared -o libTest2.so -flto -fsemantic-interposition -fPIC test2.cpp 
> -fsanitize=address
> g++ -shared -o libMain.so -flto -fsemantic-interposition -fPIC main.cpp 
> -fsanitize=address
> g++ libMain.so libTest1.so  libTest2.so -fsanitize=address

> LD_LIBRARY_PATH=. ./a.out
=
==9794==ERROR: AddressSanitizer: odr-violation (0x7f6340a3d0e0):
  [1] size=4 'x' test.h:2:22
  [2] size=4 'x' test.h:2:22
... (backtrace elided)

My general understanding is that address sanitizer doesn't instrument weak or
unique symbols, but will clearly instrument the non-weak symbol here.

[Bug c++/107597] LTO causes static inline variables to get a non-uniqued global symbol

2022-11-11 Thread hubicka at ucw dot cz via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107597

--- Comment #2 from Jan Hubicka  ---
Hi,
What happens is that we read the symbol as:
  Visibility: externally_visible semantic_interposition
prevailing_def_ironly_exp public weak comdat comdat_group:_ZN12NonTemplated1xE
one_only
While in visibility pass we promote it to:
  Visibility: externally_visible semantic_interposition
prevailing_def_ironly_exp public comdat
So we disolve comdat group and turn off weak. This leads to better code
generation and we know it does not affect dynamic linking since in
shared library all symbols are interposable.

So this is kind of feature.   How the ODR violations are detected?
I wonder if keeping weak flag disturbs something.

[Bug c++/107597] LTO causes static inline variables to get a non-uniqued global symbol

2022-11-09 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107597

Richard Biener  changed:

   What|Removed |Added

 CC||amodra at gcc dot gnu.org,
   ||hubicka at gcc dot gnu.org,
   ||jason at gcc dot gnu.org,
   ||rguenth at gcc dot gnu.org
 Ever confirmed|0   |1
   Last reconfirmed||2022-11-10
   Keywords||lto, wrong-code
 Status|UNCONFIRMED |NEW

--- Comment #1 from Richard Biener  ---
1
libFoo.so-t.o 2
192 c3d22ca2af7ab12c PREVAILING_DEF_IRONLY_EXP main
197 c3d22ca2af7ab12c PREVAILING_DEF_IRONLY_EXP _ZN12NonTemplated1xE

confirmed (binutils 2.37).  I think the above shows the linker doesn't
properly communicate the uniqueness but we might be able to recover from
the bits we have in the streamed IL?