opensgx icon indicating copy to clipboard operation
opensgx copied to clipboard

Compiler Optimization breaks ASM

Open sam1013 opened this issue 8 years ago • 0 comments

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 all enclu calls in a single function and mark this function noinline and returns_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));

sam1013 avatar Mar 29 '16 14:03 sam1013