libsodiumでenclave.soのビルドができない⑧
IC3のほうに切り替えてやってみたものの戻ってきてしまった。
code:sh
/usr/local/bin/ld: ../build/lib/liberc20enclave.a(libsodium_la-utils.o): in function `sodium_memzero':
/root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/src/libsodium/sodium/utils.c:127: undefined reference to `explicit_bzero'
/usr/local/bin/ld: ../build/lib/liberc20enclave.a(libsodium_la-randombytes_sysrandom.o): in function `safe_read':
/root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:135: undefined reference to `read'
/usr/local/bin/ld: ../build/lib/liberc20enclave.a(libsodium_la-randombytes_sysrandom.o): in function `randombytes_block_on_dev_random':
/root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:158: undefined reference to `open'
/usr/local/bin/ld: /root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:166: undefined reference to `poll'
/usr/local/bin/ld: /root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:169: undefined reference to `close'
/usr/local/bin/ld: /root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:173: undefined reference to `close'
/usr/local/bin/ld: ../build/lib/liberc20enclave.a(libsodium_la-randombytes_sysrandom.o): in function `randombytes_sysrandom_random_dev_open':
/root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:197: undefined reference to `open'
/usr/local/bin/ld: /root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:199: undefined reference to `fstat'
/usr/local/bin/ld: /root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:209: undefined reference to `fcntl'
/usr/local/bin/ld: /root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:209: undefined reference to `fcntl'
/usr/local/bin/ld: /root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:213: undefined reference to `close'
/usr/local/bin/ld: ../build/lib/liberc20enclave.a(libsodium_la-randombytes_sysrandom.o): in function `_randombytes_linux_getrandom':
/root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:233: undefined reference to `getrandom'
/usr/local/bin/ld: ../build/lib/liberc20enclave.a(libsodium_la-randombytes_sysrandom.o): in function `randombytes_sysrandom_close':
/root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:318: undefined reference to `close'
collect2: error: ld returned 1 exit status
Makefile:150: recipe for target '../build/erc20.enclave.so' failed
なんか全体的にlibc関連の関数っぽい気がする
g++でリンクするときにlibcを入れればよいのか?
code:Makefile
RustEnclave_Include_Paths := -I$(CUSTOM_COMMON_PATH)/inc -I$(CUSTOM_EDL_PATH) -I$(SGX_SDK)/include -I$(SGX_SDK)/include/tlibc -I$(SGX_SDK)/include/stlport -I$(SGX_SDK)/include/epid -I $(ANONIFY_ENCLAVE_DIR) -I./include
tlibcにcloseとか入ってない?
SGX_SDK ?= /opt/sgxsdk
export SODIUM_SHARED=1
code:sh
root@70d3f320d482:~/anonify/scripts# make DEBUG=1 ENCLAVE_DIR=example/erc20/enclave
Rust_Enclave_Name <= /root/anonify/scripts
The following warnings were emitted during compilation:
warning: SODIUM_SHARED has no effect for building libsodium from source
error: failed to run custom build command for libsodium-sys v0.2.6 (https://github.com/cipepser/sodiumoxide?branch=sodiumoxide-sgx#26f308d8)
Caused by:
process didn't exit successfully: /root/anonify/target/debug/build/libsodium-sys-06467beca0f3c86e/build-script-build (exit code: 101)
--- stdout
cargo:rerun-if-env-changed=SODIUM_LIB_DIR
cargo:rerun-if-env-changed=SODIUM_SHARED
cargo:rerun-if-env-changed=SODIUM_USE_PKG_CONFIG
cargo:rerun-if-env-changed=SODIUM_DISABLE_PIE
cargo:warning=SODIUM_SHARED has no effect for building libsodium from source
--- stderr
cp: cannot create regular file '/root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/./.git/objects/pack/pack-38bb64a87eab2637715dd6d123345137641b9234.pack': Operation not permitted
cp: cannot create regular file '/root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/./.git/objects/pack/pack-38bb64a87eab2637715dd6d123345137641b9234.idx': Operation not permitted
thread 'main' panicked at 'Failed to copy sources into build directory: exit code: 1', /root/.cargo/git/checkouts/sodiumoxide-0e0c40fa09157d5c/26f308d/libsodium-sys/build.rs:366:13
note: run with RUST_BACKTRACE=1 environment variable to display a backtrace
Makefile:144: recipe for target 'liberc20enclave.a' failed
↑unset
libcを追加
code:sh
RustEnclave_Link_Flags := -lc $(SGX_COMMON_CFLAGS) -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \
一つだけになった
code:sh
/usr/local/bin/ld: ../build/lib/liberc20enclave.a(libsodium_la-randombytes_sysrandom.o): in function `randombytes_sysrandom_random_dev_open':
/root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:199: undefined reference to `fstat'
collect2: error: ld returned 1 exit status
Makefile:150: recipe for target '../build/erc20.enclave.so' failed
追加する位置を変更
code:sh
-Wl,--start-group -lc -lsgx_tstdc -l$(Service_Library_Name) -l$(Crypto_Library_Name) $(RustEnclave_Link_Libs) -Wl,--end-group \
code:sh
LINK => ../build/erc20.enclave.so
mkdir -p ../.anonify
<!-- Please refer to User's Guide for the explanation of each field -->
<EnclaveConfiguration>
<ProdID>0</ProdID>
<ISVSVN>0</ISVSVN>
<StackMaxSize>0x40000</StackMaxSize>
<HeapMaxSize>0x100000</HeapMaxSize>
<TCSNum>6</TCSNum>
<TCSPolicy>0</TCSPolicy>
<DisableDebug>0</DisableDebug>
<MiscSelect>0</MiscSelect>
<MiscMask>0xFFFFFFFF</MiscMask>
</EnclaveConfiguration>
Symbol table incorrect
The input enclave file is not correct.
Error happened while signing the enclave.
Makefile:154: recipe for target '../.anonify/erc20.signed.so' failed
最後につけると違うsymbol
code:sh
-Wl,--start-group -lsgx_tstdc -l$(Service_Library_Name) -l$(Crypto_Library_Name) $(RustEnclave_Link_Libs) -lc -Wl,--end-group \
code:sh
Symbol table incorrect
The input enclave file is not correct.
怒られるパターン
-lsgx_tstdcxx
code:sh
/usr/local/bin/ld: cannot find -lsgx_tstdcxx
code:sh
root@70d3f320d482:/opt/sgxsdk/lib64# ls /opt/sgxsdk/include/tlibc/
assert.h endian.h float.h iso646.h math.h pthread.h stdarg.h stddef.h stdio.h string.h time.h wchar.h
ctype.h errno.h inttypes.h limits.h mbusafecrt.h setjmp.h stdbool.h stdint.h stdlib.h sys unistd.h wctype.h
libsgx_tstdc.a→-lsgx_tstdc
libc→-lc
code:sh
root@70d3f320d482:/opt/sgxsdk/lib64# ls
cve_2020_0551_cf libsgx_dcap_tvl.a libsgx_pcl.a libsgx_tcmalloc.a libsgx_trts_sim.a libsgx_uae_service_sim.so
cve_2020_0551_load libsgx_epid.so libsgx_pclsim.a libsgx_tcrypto.a libsgx_tservice.a libsgx_ukey_exchange.a
gdb-sgx-plugin libsgx_epid_sim.so libsgx_pthread.a libsgx_tcxx.a libsgx_tservice_sim.a libsgx_uprotected_fs.a
libc++_Changes_SGX.txt libsgx_launch.so libsgx_ptrace.so libsgx_tkey_exchange.a libsgx_tstdc.a *** libsgx_urts.so
libsgx_capable.a libsgx_launch_sim.so libsgx_quote_ex.so libsgx_tprotected_fs.a libsgx_tswitchless.a libsgx_urts_sim.so
libsgx_capable.so libsgx_omp.a libsgx_quote_ex_sim.so libsgx_trts.a libsgx_uae_service.so libsgx_uswitchless.a
teaclaveのcmakeを参考に進める。
以下を/opt/sgxsdk/lib64に追加
(展開する場所は要検討)
code:sh
set(MESAPY_VERSION 947fb3f598eede83ba0e33b5b5655b9a9597c2d8)
tar xzf ${MESAPY_VERSION}-mesapy-sgx.tar.gz
-lsgx_tlibc_extを追加したらいくつかのエラーは減った
code:sh
/usr/local/bin/ld: ../build/lib/liberc20enclave.a(libsodium_la-utils.o): in function `sodium_memzero':
/root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/src/libsodium/sodium/utils.c:127: undefined reference to `explicit_bzero'
/usr/local/bin/ld: ../build/lib/liberc20enclave.a(libsodium_la-randombytes_sysrandom.o): in function `randombytes_block_on_dev_random':
/root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:166: undefined reference to `poll'
/usr/local/bin/ld: ../build/lib/liberc20enclave.a(libsodium_la-randombytes_sysrandom.o): in function `_randombytes_linux_getrandom':
/root/anonify/target/debug/build/libsodium-sys-818ae33fdaea26d7/out/source/libsodium/src/libsodium/randombytes/sysrandom/randombytes_sysrandom.c:233: undefined reference to `getrandom'
ただし、weakシンボルになっている
code:sh
❯ nm libsgx_tlibc_ext.a
__ctype_b_loc.o:
0000000000000000 T __ctype_b_loc
0000000000000000 d ptable
0000000000000000 r table
__ctype_get_mb_cur_max.o:
0000000000000000 T __ctype_get_mb_cur_max
__ctype_tolower_loc.o:
0000000000000000 T __ctype_tolower_loc
0000000000000000 d ptable
0000000000000000 r table
__ctype_toupper_loc.o:
0000000000000000 T __ctype_toupper_loc
0000000000000000 d ptable
0000000000000000 r table
unused.o:
0000000000000000 R FD
U _GLOBAL_OFFSET_TABLE_
0000000000000290 W __assert_fail
0000000000000350 W __divmodti4
00000000000002a0 W __fprintf_chk
00000000000002d0 W __fxstat64
00000000000002b0 W __lxstat64
U __stack_chk_fail
U __udivmodti4
00000000000002c0 W __xstat64
0000000000000110 W _exit
U abort
0000000000000200 W accept
00000000000001a0 W access
0000000000000340 W c_close_file
0000000000000310 W c_create_output
0000000000000300 W c_open_input
0000000000000320 W c_read_file
0000000000000330 W c_write_file
00000000000001c0 W clock_getres
00000000000001b0 W clock_gettime
0000000000000170 W close
0000000000000010 W dlclose
0000000000000020 W dlerror
0000000000000000 W dlopen
0000000000000030 W dlsym
00000000000000b0 W execv
0000000000000130 W fclose
00000000000001e0 W fcntl
0000000000000140 W fdopen
00000000000000d0 W fork
0000000000000250 W fstat
0000000000000050 W ftruncate
0000000000000060 W ftruncate64
0000000000000260 W getcwd
00000000000000c0 W getenv
00000000000000e0 W getpid
00000000000002e0 W gettimeofday
0000000000000040 W isatty
00000000000000a0 W localeconv
0000000000000210 W lseek
0000000000000220 W lseek64
0000000000000230 W lstat64
0000000000000070 W madvise
0000000000000270 W mmap
0000000000000280 W mmap64
00000000000000f0 W mprotect
0000000000000090 W nl_langinfo
0000000000000150 W open
0000000000000160 W open64
0000000000000100 W prctl
00000000000001d0 W read
0000000000000190 W readlink
00000000000001f0 W select
0000000000000120 W setbuf
0000000000000080 W setlocale
0000000000000240 W stat
0000000000000000 V stderr
00000000000002f0 W time
0000000000000180 W unlink
非弱符号的(STB_WEAK)符号,那么就认为发现了一个未定义符号。