-
-
Notifications
You must be signed in to change notification settings - Fork 133
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Segmentation fault occurs when mclBnG1 instance is created during static initialization phase #98
Comments
If you want to call mclBnG1_clear for a static variable, then it is not necessary because mclBnG1 is an array of uint64_t and it will be filled with zero. |
That sample does not call mclBnG1_clear, so the problem does not reproduce. #include "./mcl_wrapper.h"
struct Init {
Init()
{
int ret = blsInit(MCL_BLS12_381, MCLBN_COMPILED_TIME_VAR);
printf("ret=%d\n", ret);
}
} s_init; // the constructor will be called at first before the other static variables.
mclBnG1 MclWrapper::m_p; |
The problem is that even if we don't call any Mcl function, if mclBnG1 variable is declared as a static variable, mcl::FpT<mcl::bn::local::FpTag, 384ul>::clear is called while static variables are instantiated. |
Thanks. We have actually tried the idea in our actual codebase, and that solved the problem. But for some reason that caused memory leaks and made address sanitizer checks fail. I will try to reproduce the situation using the minimum example. |
It seems strange. I tested your code, but it does not show any error. diff --git a/src/main.cpp b/src/main.cpp
index 03e4e60..ed87c57 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,6 +1,8 @@
#include "./mcl_wrapper.h"
+#include <stdio.h>
int main() {
MclWrapper x;
+ puts("ok");
return 0; g++ -g -O2 -Wall -I/usr/local/include -Isrc/bls/include -Isrc/bls/mcl/include -I/usr/local/lib -I/usr/local/include -I/usr/local/include -c main.cpp -o main.o
main.cpp: In function 'int main()':
main.cpp:5:16: warning: unused variable 'x' [-Wunused-variable]
5 | MclWrapper x;
| ^
mcl-bls-sample% ./test
ok Ubuntu 22.04.2 LTS + g++-11.3.0 + Intel CPU with -O0 and -O2 option. |
Could you try libbls384_256.a in https://github.com/herumi/bls-eth-go-binary/tree/master/bls/lib/linux/amd64 ? |
Thank you. I tried but I'm still seeing the seg fault. My environment is Ubuntu 20.04 LTS + g++-9.4.0 + AMD Ryzen 9 with -O0 option. Do you have any idea? g++ main.o mcl_wrapper.o herumi/libbls384_256.a src/bls/mcl/lib/libmcl.a -lpthread -o test
ryzen (gogoex: main): ~/repos/mcl-bls-sample
$ make run
./test
make: *** [Makefile:38: run] Segmentation fault (core dumped)
ryzen (gogoex: main): ~/repos/mcl-bls-sample
$ g++ --version
g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0 |
Can you make the binary by |
Sorry. I realized that my Following your first comment, I will try to remove |
I could confirm that not calling But for some reason, I observe that the initial values change when we try with our codebase. I will create a minimum code to confirm it and if needed, I will create a issue. |
When
mclBnG1
instance is created as (or under) a static variable,mcl::FpT<mcl::bn::local::FpTag, 384ul>::clear
is called during the static initialization phase the main function is called. Then that results in a segmentation fault.From experiments, I found in non-static context, calling
blsInit
before instantiatingmclBnG1
instance solves the problem. But I haven't been able to find a way to do it in static context.To build the library, I'm using:
and the library is used this way:
GDB back trace:
The environment:
I prepared a minimum example that can reproduce the problem:
https://github.com/gogoex/mcl-bls-sample
The text was updated successfully, but these errors were encountered: