Intel® Software Guard Extensions (Intel® SGX)
Discussion board focused on hardware-based isolation and memory encryption to provide extended code protection in solutions.

Using system libraries in simulation mode for debugging

SANJAY_S_
Beginner
978 Views

Hello,

While developing the enclave in simulation mode, it'd be productive to allow printf for debugging. I see that is isn't a part of libsgx_tstdc.a. Also, a part of my enclave code has been sourced from Torch which calls printf, exit etc to perform error handling. Performing error handling when SGX_MODE=SIM would also make the development productive. I have added appropriate fences to not include the error handling code when SGX_MODE=HW.

Please suggest include and link flags that would link the enclave to use the system libraries to enable these error handling routines.

Thanks,

Sanjay

0 Kudos
1 Solution
Haitao_H_Intel
Employee
978 Views

You can try this prototype I created on Linux (limited testing on Ubuntu 16.04): https://github.com/haitaohuang/linux-sgx/commit/a5605b7f42bf772baa8e1f0010dce8a488cb3e88

It modifies the Makefile in SampleEnclave that comes with SDK. Please be aware error handling is critical for security sensitive code. So this is only for prototyping and debugging purpose. You probably need replace error handling logic with trusted libs in real HW mode for production, not just compile them out. 

View solution in original post

0 Kudos
2 Replies
Haitao_H_Intel
Employee
979 Views

You can try this prototype I created on Linux (limited testing on Ubuntu 16.04): https://github.com/haitaohuang/linux-sgx/commit/a5605b7f42bf772baa8e1f0010dce8a488cb3e88

It modifies the Makefile in SampleEnclave that comes with SDK. Please be aware error handling is critical for security sensitive code. So this is only for prototyping and debugging purpose. You probably need replace error handling logic with trusted libs in real HW mode for production, not just compile them out. 

0 Kudos
SANJAY_S_
Beginner
978 Views

Hello Huang !

Thanks for the code !!

I've implemented printf inside the enclave by,

  1. Applying the formatting through the internally provided vsnprintf.
  2. Printing the resulting string by passing it to printf or puts through an OCALL.

​exit can be implemented through similar means.

0 Kudos
Reply