libsodiumでenclave.soのビルドができない④
code:sh
code:sh
❯ rg 'crypto_scalarmult_curve25519\(' -g '*.c'
src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c
15:crypto_scalarmult_curve25519(unsigned char *q, const unsigned char *n,
以下を追加
code:Makefile
@$(CC) $(RustEnclave_Compile_Flags) -c /root/libsodium-stable/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c -o $(ANONIFY_BUILD_DIR)/scalarmult_curve25519.o
..
@$(CXX) $(ANONIFY_BUILD_DIR)/crypto_scalarmult.o $(ANONIFY_BUILD_DIR)/scalarmult_curve25519.o $(ANONIFY_BUILD_DIR)/$(T_O_FILE) -o $@ $(RustEnclave_Link_Flags)
code:Anonify_common.edl
include "crypto_scalarmult_curve25519.h"
code:sh
/usr/local/bin/ld: ../build/scalarmult_curve25519.o: warning: relocation against crypto_scalarmult_curve25519_ref10_implementation' in read-only section .text'
/usr/local/bin/ld: ../build/scalarmult_curve25519.o: in function `crypto_scalarmult_curve25519_base':
/root/libsodium-stable/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c:34: undefined reference to `crypto_scalarmult_curve25519_ref10_implementation'
/usr/local/bin/ld: ../build/scalarmult_curve25519.o: in function `_crypto_scalarmult_curve25519_pick_best_implementation':
/root/libsodium-stable/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c:52: undefined reference to `crypto_scalarmult_curve25519_ref10_implementation'
/usr/local/bin/ld: ../build/scalarmult_curve25519.o:/root/libsodium-stable/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c:11: undefined reference to `crypto_scalarmult_curve25519_ref10_implementation'
/usr/local/bin/ld: warning: creating DT_TEXTREL in a PIE
collect2: error: ld returned 1 exit status
Makefile:146: recipe for target '../build/enclave.so' failed
むー。めんどいな。
crypto_scalarmult_curve25519_ref10_implementationも必要?
code:sh
❯ nm libsodium_la-crypto_scalarmult.o | grep crypto_scalarmult_curve25519
U _crypto_scalarmult_curve25519
U _crypto_scalarmult_curve25519_base
❯ cd curve25519
❯ ls
libsodium_la-scalarmult_curve25519.lo ref10 scalarmult_curve25519.c
libsodium_la-scalarmult_curve25519.o sandy2x scalarmult_curve25519.h
❯ nm libsodium_la-scalarmult_curve25519.o | grep crypto_scalarmult_curve25519
00000000000000b0 T __crypto_scalarmult_curve25519_pick_best_implementation
0000000000000000 T _crypto_scalarmult_curve25519
0000000000000070 T _crypto_scalarmult_curve25519_base
0000000000000090 T _crypto_scalarmult_curve25519_bytes
U _crypto_scalarmult_curve25519_ref10_implementation
U _crypto_scalarmult_curve25519_sandy2x_implementation
00000000000000a0 T _crypto_scalarmult_curve25519_scalarbytes
この辺のファイルが動的にリンクされるんだけど、ref10のほうは見つからないはずなので、わからんでもない。これら自分でコンパイルしないといけないのかな。
-staticを付与する
code:sh
@$(CC) $(RustEnclave_Compile_Flags) -static -c /root/libsodium-stable/src/libsodium/crypto_scalarmult/curve25519/scalarmult_curve25519.c -o $(ANONIFY_BUILD_DIR)/scalarmult_curve25519.o
→エラー変わらず
自分でコンパイルしないでやってみる。
code:sh
@$(CXX) /root/libsodium-stable/src/libsodium/crypto_scalarmult/libsodium_la-crypto_scalarmult.o $(ANONIFY_BUILD_DIR)/$(T_O_FILE) -o $@ $(RustEnclave_Link_Flags)
code:sh
Symbol table incorrect
想定のエラーが返ってきた。ここでオブジェクト足していけばよさそう。
こんな感じで変数にして、追加していく。
code:Makefile
LibSodium_Link_Libs := /root/libsodium-stable/src/libsodium/crypto_scalarmult/libsodium_la-crypto_scalarmult.o
@$(CXX) $(LibSodium_Link_Libs) $(ANONIFY_BUILD_DIR)/$(T_O_FILE) -o $@ $(RustEnclave_Link_Flags)
code:sh
-L/root/libsodium-stable/src/libsodium/crypto_scalarmult/curve25519/ref10/libsodium_la-x25519_ref10.o \
-L/root/libsodium-stable/src/libsodium/crypto_scalarmult/curve25519/sandy2x/
code:sh
include "ed25519_ref10.h"
code:sh
# $(SODIUM_ROOT)/crypto_core/ed25519/libsodium_la-core_ed25519.o \
ed25519あたりはこれで通った
code:sh
LibSodium_Link_Libs := $(SODIUM_ROOT)/crypto_scalarmult/libsodium_la-crypto_scalarmult.o \
$(SODIUM_ROOT)/crypto_core/ed25519/ref10/libsodium_la-ed25519_ref10.o \
$(SODIUM_ROOT)/crypto_scalarmult/curve25519/libsodium_la-scalarmult_curve25519.o \
$(SODIUM_ROOT)/crypto_scalarmult/curve25519/sandy2x/libsodium_la-curve25519_sandy2x.o \
$(SODIUM_ROOT)/crypto_scalarmult/curve25519/sandy2x/libsodium_la-fe_frombytes_sandy2x.o \
$(SODIUM_ROOT)/crypto_scalarmult/curve25519/sandy2x/libsodium_la-fe51_invert.o \
$(SODIUM_ROOT)/crypto_scalarmult/curve25519/sandy2x/libsodium_la-sandy2x.o \
$(SODIUM_ROOT)/crypto_scalarmult/curve25519/ref10/libsodium_la-x25519_ref10.o
次
code:sh
Symbol table incorrect
code:sh
❯ rg sodium_is_zero
sodium/utils.c
248:sodium_is_zero(const unsigned char *n, const size_t nlen)
code:sh
root@d693341101b2:~/anonify/scripts# ls /root/libsodium-stable/src/libsodium/sodium/
.deps/ .libs/ core.c libsodium_la-codecs.o libsodium_la-core.o libsodium_la-runtime.o libsodium_la-utils.o libsodium_la-version.o utils.c
.dirstamp codecs.c libsodium_la-codecs.lo libsodium_la-core.lo libsodium_la-runtime.lo libsodium_la-utils.lo libsodium_la-version.lo runtime.c version.c
code:sh
$(SODIUM_ROOT)/sodium/libsodium_la-utils.o
むー
code:sh
/usr/local/bin/ld: /root/libsodium-stable/src/libsodium/sodium/libsodium_la-utils.o: undefined reference to symbol 'raise@@GLIBC_2.2.5'
/usr/local/bin/ld: /lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
-lpthread追加
code:sh
RustEnclave_Link_Libs := -L$(CUSTOM_LIBRARY_PATH) -lenclave -L/usr/local/lib -lsodium -lpthread
→変わらず?
でもutilsにsodium_is_zeroが入ってる
code:sh
root@d693341101b2:~/anonify/scripts# nm /root/libsodium-stable/src/libsodium/sodium/libsodium_la-utils.o | grep sodium_is_zero
00000000000001f0 T sodium_is_zero
-pthreadはここでいれる
code:sh
@$(CXX) $(LibSodium_Link_Libs) $(ANONIFY_BUILD_DIR)/$(T_O_FILE) -o $@ $(RustEnclave_Link_Flags) -pthread
→エラー同じ
-Wlで渡す
code:sh
-Wl,--version-script=$(CONFIG_DIR)/Enclave.lds -Wl,-lpthread
code:sh
/usr/local/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libpthread.a(pt-raise.o): undefined reference to symbol 'errno@@GLIBC_PRIVATE'
/usr/local/bin/ld: /lib/x86_64-linux-gnu/libc.so.6: error adding symbols: DSO missing from command line
collect2: error: ld returned 1 exit status
raiseからerrnoに変わったが...
-Wl,-lc追加
code:sh
-Wl,--version-script=$(CONFIG_DIR)/Enclave.lds -Wl,-lpthread -Wl,-lc
code:sh
/usr/local/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(abort.o): in function `abort':
(.text+0x0): multiple definition of `abort'; /opt/sgxsdk/lib64/libsgx_trts.a(trts_pic.o):trts_pic.S:(.nipx+0x36a): first defined here
/usr/local/bin/ld: /opt/sgxsdk/lib64/libsgx_tstdc.a(strerror_r.o): in function `strerror_r':
strerror_r.c:(.text.strerror_r+0x11e): warning: sys_errlist' is deprecated; use strerror' or `strerror_r' instead
/usr/local/bin/ld: strerror_r.c:(.text.strerror_r+0x18): warning: sys_nerr' is deprecated; use strerror' or `strerror_r' instead
/usr/local/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(libc-cancellation.o): warning: relocation against __pthread_unwind@@GLIBC_PRIVATE' in read-only section .text'
/usr/local/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.a(libc-cancellation.o): relocation R_X86_64_PC32 against symbol `__pthread_unwind@@GLIBC_PRIVATE' can not be used when making a PIE object; recompile with -fPIE
/usr/local/bin/ld: final link failed: bad value
collect2: error: ld returned 1 exit status
Makefile:156: recipe for target '../build/enclave.so' failed
code:sh
/usr/local/bin/ld: /root/libsodium-stable/src/libsodium/sodium/libsodium_la-utils.o: undefined reference to symbol 'raise@@GLIBC_2.2.5'
/usr/local/bin/ld: /lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
libpthread側が悪い?
code:sh
root@d693341101b2:~/anonify/scripts# nm /lib/x86_64-linux-gnu/libpthread.so.0 | grep raise
0000000000012750 T raise
edlに追記不要だった
code:sh
include "sodium.h"
include "crypto_scalarmult.h"
include "crypto_scalarmult_curve25519.h"
include "ladder_namespace.h"
続き