UkoeHB / monero

Monero: the secure, private, untraceable cryptocurrency
https://getmonero.org
Other
7 stars 4 forks source link

mx25519: linking breaks ODR rule when compiled with AddressSanitizer #50

Closed jeffro256 closed 4 weeks ago

jeffro256 commented 4 weeks ago

When compiling seraphis_lib with -fsanitize=address, I get the following error on startup when running unit_tests:

=================================================================
==23872==ERROR: AddressSanitizer: odr-violation (0x55ce5781e360):
  [1] size=32 'mx25519_sc8_mont' /home/jeff/monero/external/mx25519/src/scalar.c:21:26
  [2] size=32 'mx25519_sc8_mont' /home/jeff/monero/external/mx25519/src/scalar.c:21:26
These globals were registered at these points:
  [1]:
    #0 0x7f7229037928 in __asan_register_globals ../../../../src/libsanitizer/asan/asan_globals.cpp:341
    #1 0x55ce570c1eb9 in _sub_I_00099_1 (/home/jeff/monero/build/Linux/seraphis_lib/debug/tests/unit_tests/unit_tests+0x2c3beb9)
    #2 0x7f721dc29eba in call_init ../csu/libc-start.c:145
    #3 0x7f721dc29eba in __libc_start_main_impl ../csu/libc-start.c:379

  [2]:
    #0 0x7f7229037928 in __asan_register_globals ../../../../src/libsanitizer/asan/asan_globals.cpp:341
    #1 0x7f72201bd359 in _sub_I_00099_1 (/home/jeff/monero/build/Linux/seraphis_lib/debug/src/crypto/libcncrypto.so+0xfa359)
    #2 0x7f7229bdb47d in call_init elf/dl-init.c:70

==23872==HINT: if you don't care about these errors you may set ASAN_OPTIONS=detect_odr_violation=0
SUMMARY: AddressSanitizer: odr-violation: global 'mx25519_sc8_mont' at /home/jeff/monero/external/mx25519/src/scalar.c:21:26
==23872==ABORTING

I double-checked this against master, and no ODR rule violations were detected by ASAN. I also compiled the mx25519 binaries by themselves with -fsanitize=address, and this error didn't come up. This was encountered on Linux Mint 21.3 Cinnamon, with Linux Kernel version 6.8.0-40-generic, and GCC version 11.4.0.

There is likely an error with mx25519's build configuration in seraphis_lib, which somehow doesn't get caught by the linker.

How to Reproduce: Compile with CMake option SANITIZE=ON. You can modify the option in the file build/Linux/seraphis_lib/<release/debug>/CMakeCache.txt

UkoeHB commented 4 weeks ago

I tried reproducing on Mac but got nothing. In any case, should be fixed by #51