From 1d0cdc50f45ee6da25eedfa2f9d9cbc12b4914ed Mon Sep 17 00:00:00 2001 From: Jonghyun Park Date: Thu, 8 Dec 2016 16:10:02 +0900 Subject: [PATCH 1/3] [x86/Linux] Revise asmhelper.S using macro This commit revises asmhelper.S using macros that inserts CFI directives. --- src/pal/inc/unixasmmacrosx86.inc | 28 ++++++++++++++ src/vm/i386/asmhelpers.S | 66 ++++++++++++++++++++++---------- 2 files changed, 73 insertions(+), 21 deletions(-) diff --git a/src/pal/inc/unixasmmacrosx86.inc b/src/pal/inc/unixasmmacrosx86.inc index 2cff7d13bf44..919f2c64b150 100644 --- a/src/pal/inc/unixasmmacrosx86.inc +++ b/src/pal/inc/unixasmmacrosx86.inc @@ -35,3 +35,31 @@ C_FUNC(\Name\()_End): .global C_FUNC(\Name\()_End) LEAF_END \Name, \Section .endm + +.macro PROLOG_BEG + push ebp + mov ebp, esp + .cfi_def_cfa_offset 0 +.endm + +.macro PROLOG_PUSH Reg + push \Reg + .cfi_adjust_cfa_offset -4 + .cfi_rel_offset \Reg, 0 +.endm + +.macro PROLOG_END + .cfi_def_cfa_offset 4 + .cfi_def_cfa_register ebp +.endm + +.macro EPILOG_BEG +.endm + +.macro EPILOG_POP Reg + pop \Reg +.endm + +.macro EPILOG_END + pop ebp +.endm diff --git a/src/vm/i386/asmhelpers.S b/src/vm/i386/asmhelpers.S index 3ca95b674e4c..5dde3f02a402 100644 --- a/src/vm/i386/asmhelpers.S +++ b/src/vm/i386/asmhelpers.S @@ -11,32 +11,39 @@ // .macro STUB_PROLOG // push ebp-frame - push ebp - mov ebp, esp + PROLOG_BEG // save CalleeSavedRegisters - push ebx - push esi - push edi + PROLOG_PUSH ebx + PROLOG_PUSH esi + PROLOG_PUSH edi // push ArgumentRegisters - push ecx - push edx + PROLOG_PUSH ecx + PROLOG_PUSH edx + + // set frame pointer + PROLOG_END .endm // // FramedMethodFrame epilog // .macro STUB_EPILOG + // restore stack pointer + EPILOG_BEG + // pop ArgumentRegisters - pop edx - pop ecx + EPILOG_POP edx + EPILOG_POP ecx // pop CalleeSavedRegisters - pop edi - pop esi - pop ebx - pop ebp + EPILOG_POP edi + EPILOG_POP esi + EPILOG_POP ebx + + // pop ebp-frame + EPILOG_END .endm // @@ -392,8 +399,14 @@ LEAF_END ArrayOpStubTypeMismatchException, _TEXT // ------------------------------------------------------------------------------ // void STDCALL CallDescrWorkerInternal(CallDescrWorkerParams * pParams) NESTED_ENTRY CallDescrWorkerInternal, _TEXT, NoHandler + PROLOG_BEG + PROLOG_PUSH eax + PROLOG_PUSH ebx + PROLOG_PUSH ecx + PROLOG_PUSH edx + PROLOG_END - mov ebx, [esp + 4] // pParams = esp + 4 + mov ebx, [esp + ((2 + 4) * 4)] // copy the stack mov ecx, [ebx +CallDescrData__numStackSlots] @@ -445,6 +458,12 @@ LOCAL_LABEL(ReturnsInt): mov [ebx + CallDescrData__returnValue + 4], edx LOCAL_LABEL(Epilog): + EPILOG_BEG + EPILOG_POP edx + EPILOG_POP ecx + EPILOG_POP ebx + EPILOG_POP eax + EPILOG_END ret 4 LOCAL_LABEL(ReturnsFloat): @@ -944,23 +963,28 @@ NESTED_ENTRY VirtualMethodFixupStub, _TEXT, NoHandler sub eax, 5 // Push ebp frame to get good callstack under debugger - push ebp - mov ebp, esp + PROLOG_BEG // Preserve argument registers - push ecx - push edx + PROLOG_PUSH ecx + PROLOG_PUSH edx + + // Set frame pointer + PROLOG_END push eax // address of the thunk push ecx // this ptr call C_FUNC(VirtualMethodFixupWorker) + // Restore stack pointer + EPILOG_BEG + // Restore argument registers - pop edx - pop ecx + EPILOG_POP edx + EPILOG_POP ecx // Pop ebp frame - pop ebp + EPILOG_END PATCH_LABEL VirtualMethodFixupPatchLabel // Proceed to execute the actual method. From 9ebc50aa166f3226e91ea8ea3be6108712425e8c Mon Sep 17 00:00:00 2001 From: Jonghyun Park Date: Fri, 9 Dec 2016 07:42:06 +0900 Subject: [PATCH 2/3] Revise per feedback --- src/pal/inc/unixasmmacrosx86.inc | 27 ++++++++++++++++++--------- src/vm/i386/asmhelpers.S | 8 +------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/pal/inc/unixasmmacrosx86.inc b/src/pal/inc/unixasmmacrosx86.inc index 919f2c64b150..e0c7c236c41d 100644 --- a/src/pal/inc/unixasmmacrosx86.inc +++ b/src/pal/inc/unixasmmacrosx86.inc @@ -36,28 +36,37 @@ C_FUNC(\Name\()_End): LEAF_END \Name, \Section .endm +.macro push_nonvol_reg Reg + push \Reg + .cfi_adjust_cfa_offset 4 + .cfi_rel_offset \Reg, 0 +.endm + +.macro pop_nonvol_reg Reg + pop \Reg + .cfi_restore \Reg +.endm + .macro PROLOG_BEG - push ebp - mov ebp, esp - .cfi_def_cfa_offset 0 + .cfi_def_cfa_offset 4 + push_nonvol_reg ebp + mov ebp, esp .endm .macro PROLOG_PUSH Reg - push \Reg - .cfi_adjust_cfa_offset -4 - .cfi_rel_offset \Reg, 0 + push_nonvol_reg \Reg .endm .macro PROLOG_END - .cfi_def_cfa_offset 4 - .cfi_def_cfa_register ebp + .cfi_def_cfa_register ebp + .cfi_def_cfa_offset 8 .endm .macro EPILOG_BEG .endm .macro EPILOG_POP Reg - pop \Reg + pop_nonvol_reg \Reg .endm .macro EPILOG_END diff --git a/src/vm/i386/asmhelpers.S b/src/vm/i386/asmhelpers.S index 5dde3f02a402..4b08698297fb 100644 --- a/src/vm/i386/asmhelpers.S +++ b/src/vm/i386/asmhelpers.S @@ -400,13 +400,10 @@ LEAF_END ArrayOpStubTypeMismatchException, _TEXT // void STDCALL CallDescrWorkerInternal(CallDescrWorkerParams * pParams) NESTED_ENTRY CallDescrWorkerInternal, _TEXT, NoHandler PROLOG_BEG - PROLOG_PUSH eax PROLOG_PUSH ebx - PROLOG_PUSH ecx - PROLOG_PUSH edx PROLOG_END - mov ebx, [esp + ((2 + 4) * 4)] + mov ebx, [esp + ((2 + 1) * 4)] // copy the stack mov ecx, [ebx +CallDescrData__numStackSlots] @@ -459,10 +456,7 @@ LOCAL_LABEL(ReturnsInt): LOCAL_LABEL(Epilog): EPILOG_BEG - EPILOG_POP edx - EPILOG_POP ecx EPILOG_POP ebx - EPILOG_POP eax EPILOG_END ret 4 From d16baaa99712358d1d05a6caa9030d288b655e92 Mon Sep 17 00:00:00 2001 From: Jonghyun Park Date: Fri, 9 Dec 2016 08:10:55 +0900 Subject: [PATCH 3/3] Reduce CFI directives --- src/pal/inc/unixasmmacrosx86.inc | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/src/pal/inc/unixasmmacrosx86.inc b/src/pal/inc/unixasmmacrosx86.inc index e0c7c236c41d..d7d530434abc 100644 --- a/src/pal/inc/unixasmmacrosx86.inc +++ b/src/pal/inc/unixasmmacrosx86.inc @@ -36,25 +36,17 @@ C_FUNC(\Name\()_End): LEAF_END \Name, \Section .endm -.macro push_nonvol_reg Reg - push \Reg - .cfi_adjust_cfa_offset 4 - .cfi_rel_offset \Reg, 0 -.endm - -.macro pop_nonvol_reg Reg - pop \Reg - .cfi_restore \Reg -.endm - .macro PROLOG_BEG - .cfi_def_cfa_offset 4 - push_nonvol_reg ebp + push ebp + .cfi_def_cfa_offset 8 + .cfi_offset ebp, -8 mov ebp, esp .endm .macro PROLOG_PUSH Reg - push_nonvol_reg \Reg + push \Reg + .cfi_adjust_cfa_offset 4 + .cfi_rel_offset \Reg, 0 .endm .macro PROLOG_END @@ -66,7 +58,8 @@ C_FUNC(\Name\()_End): .endm .macro EPILOG_POP Reg - pop_nonvol_reg \Reg + pop \Reg + .cfi_restore \Reg .endm .macro EPILOG_END