Просмотр исходного кода

[Pal/Linux-SGX] Add missing CFI directives to .S files for debugging

GDB needs CFI directives to correctly unwind the stack. This is
useful for backtraces and stack frame info.
Dmitrii Kuvaiskii 6 лет назад
Родитель
Сommit
a08446f107

+ 2 - 0
LibOS/shim/src/syscallas.S

@@ -101,7 +101,9 @@ ret:
         popq %rdi
         popq %rbx
         popq %rbp
+        .cfi_def_cfa %rsp, 2 * 8  # +8 for ret_addr, +8 for saved_rflags
         popfq
+        .cfi_def_cfa_offset 8     # +8 for ret_addr
         retq
 
 isundef:

+ 13 - 0
Pal/src/host/Linux-SGX/enclave_entry.S

@@ -254,6 +254,10 @@ enclave_entry:
 	#     %rdi, %rsi: (optional) arguments to untrusted code.
 .Lclear_and_eexit:
 
+	# CFA is away from RBP by ret_addr + saved_rbp + GPR context except RAX
+	.cfi_def_cfa %rbp, SGX_CONTEXT_SIZE - 8 + 16
+	.cfi_offset %rbp, -16
+
 	# Clear "extended" state (FPU aka x87, SSE, AVX, ...).
 
 	leaq .Lxrstor_init_arg(%rip), %rcx
@@ -321,8 +325,12 @@ enclave_entry:
 	.type sgx_ocall, @function
 
 sgx_ocall:
+	.cfi_startproc
 	pushq %rbp
+	.cfi_adjust_cfa_offset 8
 	movq %rsp, %rbp
+	.cfi_offset %rbp, -16
+	.cfi_def_cfa_register %rbp
 
 	movq 8(%rbp), %rax
 	pushq %rax	# previous RIP
@@ -347,6 +355,10 @@ sgx_ocall:
 	# no RAX
 
 	movq %rsp, %rbp
+
+	# CFA shifted away from RBP=RSP by the size of GPR context except RAX
+	.cfi_adjust_cfa_offset SGX_CONTEXT_SIZE - 8
+
 	subq $XSAVE_SIZE,  %rsp
 	andq $XSAVE_ALIGN, %rsp
 	fxsave (%rsp)
@@ -366,6 +378,7 @@ sgx_ocall:
 
 	movq %gs:SGX_EXIT_TARGET, %rbx
 	jmp .Lclear_and_eexit
+	.cfi_endproc
 
 .Lreturn_from_ocall:
 	# PAL convention:

+ 6 - 0
Pal/src/host/Linux-SGX/sgx_entry.S

@@ -44,18 +44,23 @@ sgx_raise:
 sgx_entry:
 	# arguments: RDI - code, RSI - ms
 
+	.cfi_startproc
 	leaq ocall_table(%rip), %rbx
 	movq (%rbx,%rdi,8), %rbx
 	movq %rsi, %rdi
 
 	pushq %rbp
+	.cfi_adjust_cfa_offset 8
 	movq %rsp, %rbp
+	.cfi_offset %rbp, -16
+	.cfi_def_cfa_register %rbp
 	andq $~0xF, %rsp  # Required by System V AMD64 ABI.
 
 	callq *%rbx
 
 	movq %rbp, %rsp
 	popq %rbp
+	.cfi_def_cfa %rsp, 8
 
 	movq %rax, %rdi
 	# Not interrupted
@@ -69,6 +74,7 @@ sgx_entry_return:
 	# RDI - return value
 	# RSI - external event
 	jmp .Ldo_ecall
+	.cfi_endproc
 
 /*
  * rdfsbase: