Hi, when doing compiler optimization with -O2 or -O3, gcc wrongly optimizes enclu. Especially calls to EENTER, ERESUME, EEXIT might get corrupted. This is because gcc does not know about semantics of SGX instructions, which change control flow. Hence, gcc does not save caller's registers, which might get reused in the new context. --> Data corruption
The solution I used is to unify allenclu calls in a single function and mark this function noinline and returns_twice in the header file; example shown below.
Hi, when doing compiler optimization with
-O2
or-O3
, gcc wrongly optimizesenclu
. Especially calls toEENTER
,ERESUME
,EEXIT
might get corrupted. This is because gcc does not know about semantics of SGX instructions, which change control flow. Hence, gcc does not save caller's registers, which might get reused in the new context. --> Data corruptionThe solution I used is to unify all
enclu
calls in a single function and mark this functionnoinline
andreturns_twice
in the header file; example shown below.sgx-user.h
:extern void enclu(enclu_cmd_t leaf, uword_t rbx, uword_t rcx, uword_t rdx, out_regs_t* out_regs) __attribute__((noinline, returns_twice));