corda/sgx-jvm/linux-sgx/sdk/gperftools
Tommy Lillehagen f21f8e7142
ENT-1187 - Update Intel SGX SDK (#165)
* Remove diverged copy of 'linux-sgx'

* Squashed 'sgx-jvm/linux-sgx/' content from commit 3699ffd5e

git-subtree-dir: sgx-jvm/linux-sgx
git-subtree-split: 3699ffd5ebd8e79d599301fa2e5814e2386cad2d

* ENT-1194 - Executable heap

* ENT-1194 - Placeholder for passing of enclave context to create_thread
2017-12-14 12:33:15 +00:00
..
gperftools-2.5 ENT-1187 - Update Intel SGX SDK (#165) 2017-12-14 12:33:15 +00:00
Makefile ENT-1187 - Update Intel SGX SDK (#165) 2017-12-14 12:33:15 +00:00
README ENT-1187 - Update Intel SGX SDK (#165) 2017-12-14 12:33:15 +00:00

Please, download the latest gperftools code from: https://github.com/gperftools/gperftools
The Intel(R) Software Guard Extensions (Intel(R) SGX) tcmalloc is based on gperftools-2.5 (the latest version avaialble at the release date).

Do the following to enable tcmalloc in Intel(R) SGX:
1. Copy libsgx_tcmalloc.a to the Intel(R) SGX SDK installation directory.
2. Add "-Wl,--whole-archive -lsgx_tcmalloc -Wl,--no-whole-archive" into enclave linking options in the Makefile.
   For example:
   Enclave_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,--whole-archive -lsgx_tcmalloc -Wl,--no-whole-archive \
	-Wl,--start-group -lsgx_tstdc -lsgx_tstdcxx -l$(Crypto_Library_Name) -l$(Service_Library_Name) -Wl,--end-group \
	-Wl,-Bstatic -Wl,-Bsymbolic -Wl,--no-undefined \
	-Wl,-pie,-eenclave_entry -Wl,--export-dynamic  \
	-Wl,--defsym,__ImageBase=0 \
	-Wl,--version-script=Enclave/Enclave.lds

   NOTE: The flags "-Wl,--whole-archive -lsgx_tcmalloc -Wl,--no-whole-archive" must be inserted before "-Wl,--start-group -lsgx_tstdc -lsgx_tstdcxx -Wl,--end-group".
         Otherwise, the enclave build will fail.

3. Set the enclave HeapMaxSize equal or larger than 0x900000 in Enclave.config.xml. For example:
   <HeapMaxSize>0x900000</HeapMaxSize>
   
Intel(R) SGX SDK includes a C++ library based on STLPort (sgx_tstdcxx) and a modern one based on libcxx (sgx_tcxx).
By default, the trusted TCMalloc library uses sgx_tcxx. However, you may change that by editing "./gperftools-2.5/autogen-linux.sh".
From:
   CPPFLAGS="-I../../../common/inc -I../../../common/inc/tlibc -I../../../common/inc/internal/ -I../../../sdk/tlibcxx/include -I../../../sdk/trts/"
To:
   CPPFLAGS="-I../../../common/inc -I../../../common/inc/tlibc -I../../../common/inc/internal/ -I../../../sdk/tlibstdcxx/stlport -I../../../sdk/trts/"
Note that if your enclave links with sgx_tcmalloc, you must use the same C++ library you choose to build tcmalloc with. Otherwise, the target enclave build will fail.