Skip to content

Commit b0cc03a

Browse files
authored
Merge pull request #301 from deeglaze/frame_pointer_pragma
Localize -O0 to necessary functions Signed-off-by: Zhang Lili Z <[email protected]>
2 parents abb0d35 + 4495449 commit b0cc03a

File tree

5 files changed

+14
-11
lines changed

5 files changed

+14
-11
lines changed

sdk/simulation/assembly/lowlib.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,15 @@
4040

4141
#include <stdint.h>
4242

43+
#if defined(__GNUC__) && !defined(__clang__)
44+
#define LOAD_REGS_ATTRIBUTES \
45+
__attribute__((optimize("-O0,-fno-omit-frame-pointer")))
46+
#elif defined(__clang__)
47+
#define LOAD_REGS_ATTRIBUTES [[clang::optnone]]
48+
#else
49+
#pragma warning "Unsupported compiler for per-function deoptimization"
50+
#endif
51+
4352
#ifdef __cplusplus
4453
extern "C" {
4554
#endif

sdk/simulation/tinst/Makefile

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ all: $(LIBSESIMU_T)
5555
$(LIBSESIMU_T): $(OBJS)
5656
$(AR) rcs $@ $^
5757

58-
# Explicitly disable optimization for 't_instructions.cpp',
59-
# since the '_SE3' function has assumptions on stack layout.
60-
t_instructions.o: CXXFLAGS += -O0
61-
6258
.PHONY: clean
6359
clean:
6460
@$(RM) $(OBJS) $(LIBSESIMU_T)

sdk/simulation/tinst/t_instructions.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,8 @@ static void _EREPORT(const sgx_target_info_t* ti, const sgx_report_data_t* rd, s
286286
static void
287287
_EEXIT(uintptr_t dest, uintptr_t xcx, uintptr_t xdx, uintptr_t xsi, uintptr_t xdi) __attribute__((section(".nipx")));
288288

289+
// The call to load_regs assumes the existence of a frame pointer.
290+
LOAD_REGS_ATTRIBUTES
289291
static void
290292
_EEXIT(uintptr_t dest, uintptr_t xcx, uintptr_t xdx, uintptr_t xsi, uintptr_t xdi)
291293
{
@@ -323,9 +325,6 @@ _EEXIT(uintptr_t dest, uintptr_t xcx, uintptr_t xdx, uintptr_t xsi, uintptr_t xd
323325

324326
// Master entry functions
325327

326-
#pragma GCC push_options
327-
#pragma GCC optimize ("O0")
328-
329328
uintptr_t _SE3(uintptr_t xax, uintptr_t xbx, uintptr_t xcx,
330329
uintptr_t xdx, uintptr_t xsi, uintptr_t xdi)
331330
{
@@ -350,5 +349,3 @@ uintptr_t _SE3(uintptr_t xax, uintptr_t xbx, uintptr_t xcx,
350349
GP();
351350
return (uintptr_t)-1;
352351
}
353-
354-
#pragma GCC pop_options

sdk/simulation/uinst/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ enclave_mngr.o: enclave_mngr.cpp
6363
# since the '_SE3' function has assumptions on stack layout.
6464
#
6565
u_instructions.o: u_instructions.cpp
66-
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -O0 -Wno-error=cpp -c $< -o $@
66+
$(CXX) $(CXXFLAGS) $(CPPFLAGS) -Wno-error=cpp -c $< -o $@
6767

6868
$(LIBSESIMU_U): u_instructions.o enclave_mngr.o $(OBJ1)
6969
$(AR) rcs $@ $^

sdk/simulation/uinst/u_instructions.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,8 @@ uintptr_t _EREMOVE(const void *epc_lin_addr)
208208

209209
// Master entry functions
210210

211-
211+
// The call to load_regs assumes the existence of a frame pointer.
212+
LOAD_REGS_ATTRIBUTES
212213
void _SE3(uintptr_t xax, uintptr_t xbx,
213214
uintptr_t xcx, uintptr_t xdx,
214215
uintptr_t xsi, uintptr_t xdi)

0 commit comments

Comments
 (0)