How to generate an enclave image with the symbols that allow sgx_emmt to report memory usage data
- Debugged an Intel® Software Guard Extensions (Intel® SGX) application with sgx-gdb and used sgx_emmt to view memory usage
- The stack usage is shown, but the peak heap and committed reserved memory are not shown:
[Peak stack used]: 7 KB
[Can't get peak heap used]: You may use version script to control symbol export. Please export 'g_peak_heap_used' in your version script.
[Can't get peak committed reserved memory]: You may use version script to control symbol export. Please export 'g_peak_rsrv_mem_committed' in your version script.
According to the Enclave Memory Measurement Tool section of the Intel® Software Guard Extensions (Intel® SGX) Developer Reference Guide for Linux*, export the symbols g_peak_heap_used and g_peak_rsrv_mem_committed in the version script of the enclave, and link the enclave image with the version script as described below.
Refer to the SampleEnclave in the Intel SGX SDK to reuse its Makefile and version script, SampleEnclave/Enclave/Enclave.lds.
- Create a file with the content of the enclave version script:
enclave.so
{
global:
g_global_data_sim;
g_global_data;
enclave_entry;
g_peak_heap_used;
g_peak_rsrv_mem_committed;
local:
*;
};
- Save the script in the enclave's source directory as Enclave.lds.
- Link the enclave with the version script and define the symbol __ImageBase in the Makefile, similarly to:
$ ld -o enclave.so file1.o file2.o \
-pie -eenclave_entry -nostdlib -nodefaultlibs –nostartfiles --no-undefined \
--whole-archive –lsgx_trts --no-whole-archive \
--start-group –lsgx_tstdc ––lsgx_tservice -lsgx_crypto -
-end-group \
-Bstatic -Bsymbolic --defsym=__ImageBase=0 --exportdynamic \
--version-script=enclave.lds
The most recent Intel® Software Guard Extensions Developer Reference Guide for Linux* is in the Documentation section of the latest release in Intel® Software Guard Extensions SDK for Linux*.