Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler Optimization breaks ASM #36

Open
sam1013 opened this issue Mar 29, 2016 · 0 comments
Open

Compiler Optimization breaks ASM #36

sam1013 opened this issue Mar 29, 2016 · 0 comments

Comments

@sam1013
Copy link
Contributor

sam1013 commented Mar 29, 2016

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));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant