RcppParallel icon indicating copy to clipboard operation
RcppParallel copied to clipboard

ODR issue for gcc san with CRAN version

Open mattfidler opened this issue 4 years ago • 5 comments

I am getting the following ODR violation; CRAN asked me to fix ODR violations in my package, and this one came up:

==136164==ERROR: AddressSanitizer: odr-violation (0x7efd2f2f1240):
  [1] size=168 '__itt__ittapi_global' ../../src/tbb/tools_api/ittnotify_static.c:231:14
  [2] size=168 '__itt__ittapi_global' ../../src/tbb/tools_api/ittnotify_static.c:231:14
These globals were registered at these points:
  [1]:
    #0 0x7efd3c896b78  (/usr/lib/x86_64-linux-gnu/libasan.so.6+0x37b78)
    #1 0x7efd2f24ab91 in _sub_I_00099_1 (/usr/local/RDsan/lib/R/site-library/RcppParallel/lib/libtbbmalloc.so.2+0xd6b91)
    #2 0x7efd3d244dbd  (/lib64/ld-linux-x86-64.so.2+0x11dbd)

  [2]:
    #0 0x7efd3c896b78  (/usr/lib/x86_64-linux-gnu/libasan.so.6+0x37b78)
    #1 0x7efd2f5dec70 in _sub_I_00099_1 (/usr/local/RDsan/lib/R/site-library/RcppParallel/lib/libtbb.so.2+0x240c70)
    #2 0x7efd3d244dbd  (/lib64/ld-linux-x86-64.so.2+0x11dbd)

mattfidler avatar Feb 01 '21 20:02 mattfidler

This is because both tbb and tbbmalloc define the (identical) object here:

https://github.com/RcppCore/RcppParallel/blob/20d6042a7215c53ec5da9dbdadb76cc9d34f8d8b/src/tbb/src/tbb/tools_api/ittnotify_static.c#L226-L243

I tried playing around to see if there was a simple way to avoid that collision, but I couldn't find anything on first glance.

kevinushey avatar Apr 15 '21 19:04 kevinushey

For some reason, some compiled optimized versions do not see this ODR violation; I think it doesn't (yet) occur with CRAN.

mattfidler avatar Apr 15 '21 21:04 mattfidler

It does; the CRAN team has notified me already. And it's apparent because that same symbol is defined in both libraries:

$ nm libtbb.dylib | grep ittapi_global
00000000000268e0 d ___itt__ittapi_global
$ nm libtbbmalloc.dylib | grep ittapi_global
0000000000015c30 d ___itt__ittapi_global

I'm not sure what the right fix is on TBB's side, though. Should they be sharing a single definition? Should the name of the version in tbbmalloc be different?

kevinushey avatar Apr 15 '21 22:04 kevinushey

I am unsure too. We simply redefined for each binary that we produced. If you follow that approach you would pick one and change any name that refers to it. This could probably by some build script.

mattfidler avatar Apr 15 '21 23:04 mattfidler

Note to self, the solution here is probably to try defining INTEL_ITTNOTIFY_PREFIX differently for tbb + tbbmalloc:

https://github.com/RcppCore/RcppParallel/blob/ad65ac4d782d40f94bf07bed8f61a9d6738d0dd4/src/tbb/src/tbb/tools_api/ittnotify.h#L239-L244

kevinushey avatar Dec 22 '21 05:12 kevinushey