libsodiumでenclave.soのビルドができない⑤
sodium_is_zeroがないというので、以下をリンクに追加するとエラーが出る。
code:sh
$(SODIUM_ROOT)/sodium/libsodium_la-utils.o
pthreadなし
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
pthreadを先頭
code:sh
RustEnclave_Link_Flags := -lpthread $(SGX_COMMON_CFLAGS) -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \
code:sh
/usr/local/bin/ld: /root/libsodium-stable/src/libsodium/sodium/libsodium_la-utils.o: undefined reference to symbol 'munlock@@GLIBC_2.2.5'
/usr/local/bin/ld: /lib/x86_64-linux-gnu/libc.so.6: error adding symbols: DSO missing from command line
pthreadを最後
code:sh
RustEnclave_Link_Flags := $(SGX_COMMON_CFLAGS) -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \
-Wl,--whole-archive -l$(Trts_Library_Name) -Wl,--no-whole-archive \
-Wl,--start-group -lsgx_tstdc -l$(Service_Library_Name) -l$(Crypto_Library_Name) $(RustEnclave_Link_Libs) -Wl,--end-group \
-Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \
-Wl,-pie,-eenclave_entry -Wl,--export-dynamic \
-Wl,--defsym,__ImageBase=0 \
-Wl,--gc-sections \
-Wl,--version-script=$(CONFIG_DIR)/Enclave.lds -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
この辺はcosの例だけど、libmをリンクしようとしている。
raiseが足りないので、libcをリンクするようにする?
code:sh
RustEnclave_Link_Flags := -lc $(SGX_COMMON_CFLAGS) -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \
なんか先に進んだっぽい
code:sh
CC <= TEMP_EDL_CONST
RustEnclave_Link_Flags => -lc -m64 -O0 -g -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L/opt/sgxsdk/lib64 -Wl,--whole-archive -lsgx_trts -Wl,--no-whole-archive -Wl,--start-group -lsgx_tstdc -lsgx_tservice -lsgx_tcrypto -L../build/lib -lenclave -L/usr/local/lib -lsodium -Wl,--end-group -Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined -Wl,-pie,-eenclave_entry -Wl,--export-dynamic -Wl,--defsym,__ImageBase=0 -Wl,--gc-sections -Wl,--version-script=../config/Enclave.lds
LINK => ../build/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>1</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:165: recipe for target '../.anonify/enclave.signed.so' failed
code:sh
root@d693341101b2:~/anonify/scripts# nm /usr/lib/x86_64-linux-gnu/libc.a | grep msync
nm: sysdep.o: no symbols
nm: sigvec.o: no symbols
nm: sigsetops.o: no symbols
nm: old_atexit.o: no symbols
nm: strtoll.o: no symbols
nm: strtoull.o: no symbols
nm: strtoll_l.o: no symbols
nm: strtoull_l.o: no symbols
nm: udiv_qrnnd.o: no symbols
nm: mp_clz_tab.o: no symbols
nm: _itowa.o: no symbols
nm: tmpfile64.o: no symbols
nm: iofgetpos64.o: no symbols
nm: iofopen64.o: no symbols
nm: iofsetpos64.o: no symbols
nm: fseeko64.o: no symbols
nm: ftello64.o: no symbols
nm: oldfmemopen.o: no symbols
nm: bzero.o: no symbols
nm: wordcopy.o: no symbols
nm: string-inlines.o: no symbols
nm: wcstoll.o: no symbols
nm: wcstoull.o: no symbols
nm: wcstoll_l.o: no symbols
nm: wcstoull_l.o: no symbols
nm: getdents64.o: no symbols
nm: readdir64.o: no symbols
nm: readdir64_r.o: no symbols
nm: scandir64.o: no symbols
nm: alphasort64.o: no symbols
nm: versionsort64.o: no symbols
nm: scandirat64.o: no symbols
nm: scandir64-tail.o: no symbols
nm: getdirentries64.o: no symbols
nm: glob64.o: no symbols
nm: globfree64.o: no symbols
nm: glob64-lstat-compat.o: no symbols
nm: pread.o: no symbols
nm: pwrite.o: no symbols
nm: init-posix.o: no symbols
nm: oldglob.o: no symbols
nm: xstat64.o: no symbols
nm: fxstat64.o: no symbols
nm: lxstat64.o: no symbols
nm: fxstatat64.o: no symbols
nm: statfs64.o: no symbols
nm: fstatfs64.o: no symbols
nm: statvfs64.o: no symbols
nm: fstatvfs64.o: no symbols
nm: open.o: no symbols
nm: openat.o: no symbols
nm: lseek.o: no symbols
nm: lockf64.o: no symbols
nm: creat.o: no symbols
nm: ftw64.o: no symbols
nm: fts64.o: no symbols
nm: posix_fadvise.o: no symbols
nm: sendfile64.o: no symbols
nm: xstatconv.o: no symbols
nm: internal_statvfs64.o: no symbols
nm: fallocate.o: no symbols
nm: getrlimit.o: no symbols
nm: setrlimit.o: no symbols
nm: preadv.o: no symbols
nm: pwritev.o: no symbols
nm: preadv2.o: no symbols
nm: pwritev2.o: no symbols
nm: mkstemp64.o: no symbols
nm: mkostemp64.o: no symbols
nm: mkstemps64.o: no symbols
nm: mkostemps64.o: no symbols
nm: truncate.o: no symbols
nm: ftruncate.o: no symbols
nm: mmap.o: no symbols
msync.o:
0000000000000000 T msync // ありそう
nm: regexp.o: no symbols
nm: memcpy_chk.o: no symbols
nm: memmove_chk.o: no symbols
nm: mempcpy_chk.o: no symbols
nm: memset_chk.o: no symbols
nm: wmemset_chk.o: no symbols
nm: compat-lookup.o: no symbols
nm: getutmpx.o: no symbols
nm: tls_get_addr.o: no symbols
code:sh
root@d693341101b2:~/anonify/scripts# ls -la /usr/lib/x86_64-linux-gnu/ | grep libc
-rw-r--r-- 1 root root 5479894 Sep 2 09:18 libc.a
-rw-r--r-- 1 root root 298 Sep 2 09:18 libc.so
code:sh
RustEnclave_Link_Flags := -Wl,-lc $(SGX_COMMON_CFLAGS) -Wl,--no-undefined -nostdlib -nodefaultlibs -nostartfiles -L$(SGX_LIBRARY_PATH) \
でもmsyncが見つからなかった
ほむ
code:sh
❯ nm enclave.so | grep msync
U msync@@GLIBC_2.2.5
00000000002e4d00 t msync_validate
000000000006fd9f t u_msync_ocall
???
code:sh
❯ nm enclave.so | grep raise
U raise@@GLIBC_2.2.5
RustEnclave_Link_Flagsからlibcを消して、以下にする
code:sh
LibSodium_Link_Libs := $(SODIUM_ROOT)/crypto_scalarmult/libsodium_la-crypto_scalarmult.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 \
$(SODIUM_ROOT)/crypto_core/ed25519/ref10/libsodium_la-ed25519_ref10.o \
$(SODIUM_ROOT)/sodium/libsodium_la-utils.o \
/usr/lib/x86_64-linux-gnu/libc.a
code:sh
/usr/local/bin/ld: /opt/sgxsdk/lib64/libsgx_trts.a(trts_pic.o): in function `abort':
trts_pic.S:(.nipx+0x36a): multiple definition of `abort'; /usr/lib/x86_64-linux-gnu/libc.a(abort.o):(.text+0x0): first defined here
/usr/local/bin/ld: ../build/lib/libenclave.a(sgx_tstd-a8936b1efc71c6af.sgx_tstd.eyka1gfz-cgu.1.rcgu.o): in function `__assert_fail':
/root/.cargo/git/checkouts/teaclave-sgx-sdk-be25c2ad2f03718d/de34d4d/sgx_tstd/src/debug.rs:21: multiple definition of `__assert_fail'; /usr/lib/x86_64-linux-gnu/libc.a(assert.o):(.text+0x160): first defined here
/usr/local/bin/ld: /opt/sgxsdk/lib64/libsgx_tstdc.a(memset.o): in function `memset':
memset.c:(.text.memset+0x0): multiple definition of `memset'; /usr/lib/x86_64-linux-gnu/libc.a(memset.o):(.text+0x0): first defined here
/usr/local/bin/ld: /usr/lib/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: warning: GNU indirect functions with DT_TEXTREL may result in a segfault at runtime; recompile with -fPIE
/usr/local/bin/ld: /usr/lib/x86_64-linux-gnu/libc.a(iofclose.o):(.data.rel.local.DW.ref.__gcc_personality_v0DW.ref.__gcc_personality_v0+0x0): undefined reference to `__gcc_personality_v0' /usr/local/bin/ld: /usr/lib/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:158: recipe for target '../build/enclave.so' failed
sgx_tstdの実装とダブってしまう
code:sh
❯ rg raise
sodium/utils.c
505: raise(SIGSEGV);
507: raise(SIGKILL);
❯ rg msync
msyncなんて使ってないのになー