herumi / mcl

a portable and fast pairing-based cryptography library
BSD 3-Clause "New" or "Revised" License
450 stars 151 forks source link

Problems about cross-compile #185

Closed fitz0401 closed 11 months ago

fitz0401 commented 11 months ago

When I'm trying to build mcl for RespberryPi 4B (32-bit, arm) in Linux (x86_64), I use this command:

make -j12 CXX=arm-linux-gnueabihf-g++ ARCH=armv6l CFLAGS_USER="-I /usr/local/include" LDFLAGS="/usr/local/lib/libgmp.a /usr/local/lib/libgmpxx.a"

the tool chain I used is arm-linux-gnueabihf-g++. And I got the error bellow:

ar rv lib/libmcl.a obj/fp.o obj/base32.o obj/bint32.o
arm-linux-gnueabihf-g++ -o lib/libmcl.so obj/fp.o obj/base32.o obj/bint32.o -shared -g3 -Wall -Wextra -Wformat=2 -Wcast-qual -Wcast-align -Wwrite-strings -Wfloat-equal -Wpointer-arith -Wundef  -I include -I test -fomit-frame-pointer -DNDEBUG -fno-stack-protector -O3 -I /usr/local/include -fpic -DMCL_USE_LLVM=1 -DMCL_BINT_ASM=1 -DMCL_BINT_ASM_X64=0 
ar: building lib/libmcl.a
a - obj/fp.o
a - obj/base32.o
a - obj/bint32.o
obj/base32.o: file not recognized: File not recongnized
collect2: error: ld return 1
make: *** [Makefile:245:lib/libmcl.so] error 1

How can I fix this problem?

herumi commented 11 months ago

clang++ is necessary to build base32.o. How about appending BIT=32? Or, to build a library libmclbn384_256.a,

make -f Makefile.cross TARGET=armv6l BIT=32
fitz0401 commented 11 months ago

Thanks for your kind reply!

I've tried appending ABI=32, but it didn't work, and the error was the same.

Actually, I used the cross compiler CXX=arm-linux-gnueabihf-g++. Do you mean when compiling base32.o, clang++ is still be used? When I conduct clang++ -v:

clang version 10.0.0-4ubuntu1 
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/8
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/bin/../lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Candidate multilib: x32;@mx32
Selected multilib: .;@m64

So maybe it's resulted by the target of clang++?

herumi commented 11 months ago

Could you try not ABI but BIT=32 ?

fitz0401 commented 11 months ago

Thanks for your reply again.

This time I tried make -j12 CXX=arm-linux-gnueabihf-g++ ARCH=armv6l BIT=32, and the error was the same.

I carefully checked the compile log, and found the warning below:

clang: warning: argument unused during compilation: '-I include' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-I test' [-Wunused-command-line-argument]
warning: overriding the module target triple with x86_64-pc-linux-gnu [-Woverride-module]
clang: warning: argument unused during compilation: '-I include' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-I test' [-Wunused-command-line-argument]
warning: overriding the module target triple with x86_64-pc-linux-gnu [-Woverride-module]

Maybe that's the reason why the obj/base32.o and obj/bint32.o are in wrong format:

 file obj/*.o   

obj/base32.o:       ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
obj/bint32.o:       ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
obj/bn_c256.o:      ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), with debug_info, not stripped
obj/bn_c384_256.o:  ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), with debug_info, not stripped
obj/bn_c384.o:      ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), with debug_info, not stripped
obj/bn_c512.o:      ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), with debug_info, not stripped
obj/fp.o:           ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), with debug_info, not stripped
obj/she_c256.o:     ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), with debug_info, not stripped
obj/she_c384_256.o: ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), with debug_info, not stripped
obj/she_c384.o:     ELF 32-bit LSB relocatable, ARM, EABI5 version 1 (SYSV), with debug_info, not stripped

I wonder why the compiler will be overrode.

herumi commented 11 months ago

The current Makefile tries to make various binaries, so it will not run well for cross compile. I think that you need only mcl library, so type

make -f Makefile.cross TARGET=armv6l BIT=32

and get lib/libmclbn384_256.a, then you can build executable files in your own environment.

fitz0401 commented 11 months ago

Thanks! I got it. But I didn't find Makefile.cross. Do you mean Makefile?

I run make -f Makefile TARGET=armv6l BIT=32, but still got

file lib/*   

lib/libmcl.a:            current ar archive
lib/libmclbn256.a:       current ar archive
lib/libmclbn256.so:      ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=1313a55d73957214d5bff8d4ff29931efdca347d, with debug_info, not stripped
lib/libmclbn384_256.a:   current ar archive
lib/libmclbn384_256.so:  ELF 64-bit LSB shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=1694d2b06c5ea0927f1be588749f0b54b7de98f4, with debug_info, not stripped
......

Seems still being incorrect lib for arm-32.

herumi commented 11 months ago

I'm sorry to miss appending the file. Could you try dev branch? https://github.com/herumi/mcl/commit/8d284cd721a79ea810ee6cf12a533076e32bcd6e

% make -f Makefile.cross BIT=32 TARGET=armv7l
clang++ -c src/fp.cpp -o obj/fp.o -std=c++03 -I ./include -I ./src -fno-threadsafe-statics -fno-exceptions -fno-rtti -DMCL_MAX_BIT_SIZE=384 -DCYBOZU_DONT_USE_STRING -DCYBOZU_DONT_USE_EXCEPTION -DNDEBUG -target armv7l
clang: warning: unknown platform, assuming -mfloat-abi=soft
clang: warning: unknown platform, assuming -mfloat-abi=soft
clang: warning: unknown platform, assuming -mfloat-abi=soft
In file included from src/fp.cpp:5:
In file included from ./include/mcl/op.hpp:9:
In file included from ./include/mcl/gmp_util.hpp:15:
In file included from ./include/mcl/randgen.hpp:33:
./include/cybozu/random_generator.hpp:134:19: warning: using directive refers to implicitly-defined namespace 'std'
                using namespace std;
                                ^
1 warning generated.
clang++ -c src/bn_c384_256.cpp -o obj/bn_c384_256.o -std=c++03 -I ./include -I ./src -fno-threadsafe-statics -fno-exceptions -fno-rtti -DMCL_MAX_BIT_SIZE=384 -DCYBOZU_DONT_USE_STRING -DCYBOZU_DONT_USE_EXCEPTION -DNDEBUG -target armv7l
clang: warning: unknown platform, assuming -mfloat-abi=soft
clang: warning: unknown platform, assuming -mfloat-abi=soft
clang: warning: unknown platform, assuming -mfloat-abi=soft
clang++ -c src/bint32.ll -o obj/bint.o -std=c++03 -I ./include -I ./src -fno-threadsafe-statics -fno-exceptions -fno-rtti -DMCL_MAX_BIT_SIZE=384 -DCYBOZU_DONT_USE_STRING -DCYBOZU_DONT_USE_EXCEPTION -DNDEBUG -target armv7l
clang: warning: unknown platform, assuming -mfloat-abi=soft
clang: warning: unknown platform, assuming -mfloat-abi=soft
clang: warning: unknown platform, assuming -mfloat-abi=soft
clang: warning: argument unused during compilation: '-I ./include' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-I ./src' [-Wunused-command-line-argument]
warning: overriding the module target triple with armv7-unknown-unknown [-Woverride-module]
1 warning generated.
clang++ -c src/base32.ll -o obj/base.o -std=c++03 -I ./include -I ./src -fno-threadsafe-statics -fno-exceptions -fno-rtti -DMCL_MAX_BIT_SIZE=384 -DCYBOZU_DONT_USE_STRING -DCYBOZU_DONT_USE_EXCEPTION -DNDEBUG -target armv7l
clang: warning: unknown platform, assuming -mfloat-abi=soft
clang: warning: unknown platform, assuming -mfloat-abi=soft
clang: warning: unknown platform, assuming -mfloat-abi=soft
clang: warning: argument unused during compilation: '-I ./include' [-Wunused-command-line-argument]
clang: warning: argument unused during compilation: '-I ./src' [-Wunused-command-line-argument]
warning: overriding the module target triple with armv7-unknown-unknown [-Woverride-module]
1 warning generated.
ar rv lib/libmclbn384_256.a obj/fp.o obj/bn_c384_256.o obj/bint.o obj/base.o
ar: creating lib/libmclbn384_256.a
a - obj/fp.o
a - obj/bn_c384_256.o
a - obj/bint.o
a - obj/base.o
% arm-linux-gnueabi-g++ sample/pairing.cpp -O3 -DNDEBUG -I ./include/ lib/libmclbn384_256.a -DMCL_MAX_BIT_SIZE=384
mcl% env QEMU_LD_PREFIX=/usr/arm-linux-gnueabi/ qemu-arm ./a.out
BLS12_381
P = 06e2624214b9e8fc87ecc18c514b0560443c3389960638f80ecde2b904dfad08432735ee1f73142a5e749e4744903716
Q = 02d1b0371dae1fae1d79ec921a47d0f2ea9c2cb6ea025a819e85cf46490feead2b2110b837c3c2781fdef2ca2f7a9f006c019e7bd4b30fde636427b47fe3024d8f6eaade73add13cd7f4c9c56a6458ff5847c347dda0b7223851caf18f06bb15
a = 2d1500f261ff10b49c7a1796a36103b02322ae5dde404141eacf018fbf1678ba
a - b = 2d1500f261ff10b49c7a1796a36103b02322ae5dde404141eacf018fbf1676f2
pairing = 44893b6162fdfb3414306906074d9e22919a685fcef962255675eaf90664f9dfa2afe6a9643ad99b6289c6251a183ba 145bdbb15a5f3ff59e432bb6adef893f9624a8dc292684c409df46d6752d1f8f25f0eba550e180bd6757123dd15e56f 6c8f1917b86b5bfc29f8a90d6c9e965522a8447dfffede1c1c0130cf105880c7c26ca5b3d2e61e28ca5538aff02d695 63dcaee9d6dbda40daa2cf31d484f2efec33fbb40b101571a4acdf8a6e455a20ef04cd0bb94e1a075fa8727eb5b0caf 5987c1fef9c05b9ff0c654db7fca56ee45d1df8316738d07d4397794fb817246d4244d4d14cf960dc65558f114b0ae6 dad58102c1e5987be96a0f8f80bfde8cef102c8c08dd081e4154d1c9ebbf6c734446a0ef2bc2f889093ea4807925b12 12e4c91934c2dfdb97fafeaf796e0c26686250c9435de472162dc955680f84509430c6886459f5fff5a636eec881dec3 19760c94d039d1f34424aab0c3844e7adfbff5ce61f5e20eae7bb79829044c28c2ee8dca83fb889d6f6d1ad8faf30e01 138724131ce250ec0b35a10af06c6126fc908242edeacfb7aa0ff2d09d7ffc55ae6514960fa36576bffaae5ff0112566 5a1b1aae394050c8f45fa75f2cf29b614ebcf26223f930cc91dd402ace13a74fc40adcbe6fa5c5fc869f66e5c9611ee 14a33a8ecea5bb40a076741141bee8a164c7b2cccc434c5d58913380e9498983f6af68b33598ff27f003d6df9bb6f6ab 14dbeca0884afea7f197dc5e960525bbcf157afdfff512687e50fdede27cd4f6fd8fcae8104381c6536358cce1084925
ok
ok
ok
fitz0401 commented 11 months ago

Thanks a lot, it seems work.

But what if I need not only libmclbn384_256.a , but also libmcl.a ?

herumi commented 11 months ago

This libmclbn384_256.a contains all functions of libmcl.a.

fitz0401 commented 11 months ago

Thank you soooo much, I think this issue can be closed. :-)