cryptobiu / libscapi

Comprehensive Open Source Library for Secure Multiparty Computation
MIT License
180 stars 66 forks source link

Static linking build problems [solved] #52

Closed holycleugh closed 5 years ago

holycleugh commented 5 years ago

Hi, I want to run the GMW protocol in the MPC-Benchmark repository. But when I make, it says that libjsoncpp is not available in ~/libscapi/install/lib. Looking at makefile_libs, it seems there should be a folder for JsonCpp in libscapi/lib, but it's not present in the repository.

Should I download it myself and place it in that directory? Or should I do something else? When I do clone JsonCpp and make it, it continues but I get many errors like

/usr/bin/ld: /home/me/libscapi/install/lib/libsimpleot.a(ge25519_lookup_niels.o): relocation R_X86_64_32S against symbol `CONST_2P0' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/me/libscapi/install/lib/libsimpleot.a(gfe4x_square.o): relocation R_X86_64_32S against symbol `scale19' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/me/libscapi/install/lib/libsimpleot.a(gfe4x_mul.o): relocation R_X86_64_32S against symbol `scale19' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/me/libscapi/install/lib/libsimpleot.a(ge4x_double_p1p1.o): relocation R_X86_64_32S against symbol `scale19' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/me/libscapi/install/lib/libsimpleot.a(ge4x_add_p1p1.o): relocation R_X86_64_32S against symbol `Gk' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/me/libscapi/install/lib/libsimpleot.a(ge4x_niels_add_p1p1.o): relocation R_X86_64_32S against symbol `scale19' can not be used when making a PIE object; recompile with -fPIC
/usr/bin/ld: /home/me/libscapi/install/lib/libsimpleot.a(ge4x_lookup_niels.o): relocation R_X86_64_32S against symbol `_allone' can not be used when making a PIE object; recompile with -fPIC
...
/usr/bin/ld: final link failed: nonrepresentable section on output
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/GMW.dir/build.make:132: GMW] Error 1
make[1]: *** [CMakeFiles/Makefile2:73: CMakeFiles/GMW.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

I got similar errors while trying to make the samples in libscapi. Is there something different about the build process now? I think something needs to be compiled statically that isn't? As far as I can tell, lib/OTExtensionBristol/SimpleOT/Makefile is building with -fPIC.

Additionally, is there any more documentation about libscapi and using it to build protocols like GMW other than readthedocs? I'm not certain but I believe the readthedocs information is pretty out of date. I'd be interested in improving the documentation once I can get libscapi working. Thanks.

holycleugh commented 5 years ago

Update - I got it to work after a bit of messing around. in MPC-Benchmark/GMW/CMakeLists.txt

-set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++11 -maes -mpclmul -fPIC")
+set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -std=c++11 -maes -mpclmul -fPIC -no-pie")

Then the README says the command is

./GMW -partyID [party_id] -circuitFileName [circuit_file_name] -partiesFileName [parties_file_name] -inputFileName [input_file_name] -numThreads [num_threads] -internalIterationsNumber [num_iterations]

But after inspecting the source, it should be

./GMW -partyID [party_id] -circuitFile [circuit_file_name] -partiesFile [parties_file_name] -inputFile [input_file_name] -numThreads [num_threads] -internalIterationsNumber [num_iterations]

instead. Additionally, Parties has been renamed to parties.conf. I was able to run it successfully and get a circuit output.

I also had to compile libgmp myself with staticlibs and put it in link_directories, but I believe that's just because I'm on Arch where main packages don't provide staticlibs.

This issue is resolved but I'm still wondering if there are more up to date docs or examples anywhere?