Closed aguycalled closed 1 year ago
Thank you for the report. I'll investigate the error. I already found two false positive errors of STL during the problem isolation. https://github.com/herumi/misc/tree/main/sanitize
thanks! :)
I found another false positive of memory sanitizer. https://github.com/herumi/misc/blob/main/sanitize/strlen_err.cpp
#include <string>
#include <stdio.h>
#include <string.h>
int main()
{
std::string s = "ABC";
printf("len=%zd\n", strlen(s.c_str()));
}
These trivial three false positives are used in mcl. They interfere with the investigation. valgrind does not anything errors.
I found that the memory sanitizer reports the following code, which is the same reason reported by https://github.com/herumi/mcl/issues/167#issue-1465448040
// test/t.cpp
include <mcl/bint.hpp>
int main()
{
using namespace mcl;
const size_t N = 2;
const Unit x[N] = { 1, 2 };
Unit buf[N * 2];
bint::mulT<N>(buf, x, x);
for (size_t i = 0; i < N * 2; i++) {
printf("buf[%zd]=%lx\n", i, buf[i]);
if (buf[i]) printf("!!\n"); // MSAN error
}
}
% make lib/libmcl.a -j DEBUG=2 bin/t.exe CXX=clang++-14 && bin/t.exe
buf[0]=1
==2718937==WARNING: MemorySanitizer: use-of-uninitialized-value
#0 0x55abdbe26e91 in main mcl/test/t.cpp:12:7
#1 0x7f3ea7a4bd8f in __libc_start_call_main csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#2 0x7f3ea7a4be3f in __libc_start_main csu/../csu/libc-start.c:392:3
#3 0x55abdbd9e904 in _start (mcl/bin/t.exe+0x23904) (BuildId: 9408e7ff3de3ab88a19d433a513ea791c2b74903)
Uninitialized value was created by an allocation of 'buf' in the stack frame of function 'main'
#0 0x55abdbe26a00 in main mcl/test/t.cpp:4
mulT<N>(z, x, y)
takes x[N]
and y[N]
and outputs z[N * 2]
as the result of x[N] * y[N]
.
But the function is written by the assembler, so the memory sanitizer does not know it and reports a false positive.
If MCL_BINT_ASM=0
then mcl does not use the asm functions, and
% make lib/libmcl.a -j bin/t.exe CXX=clang++-14 DEBUG=2 MCL_BINT_ASM=0 && bin/t.exe
does not show the error.
The correctness of the asm code is confirmed by test/bint_test.cpp
.
Related to #163
We are seeing the following error when building with
-fsanitize=memory
:Compiling with the following flags:
Adding
-DMCL_MAX_BIT_SIZE=384
does not fix the issue.mcl_initializer.cpp:
mcl_initializer.h: