Terraspace / UASM

UASM - Macro Assembler
http://www.terraspace.co.uk/uasm.html
Other
221 stars 49 forks source link

Excessive stack alignment #156

Closed pfactum closed 2 years ago

pfactum commented 3 years ago

Hello.

While building 7-zip 21.03 with uasm 2.52 it was discovered that uasm generates extra sub $0x8,%rsp / add $0x8,%rsp pair for one of the functions, and the 7-zip developer thinks this may lead to the reported 7-zip crash.

The 7-zip source code contains the Asm/x86/LzFindOpt.asm file in question.

Could you please suggest why sub/add pair was added here and how to disable it?

Thanks.

pfactum commented 3 years ago

Adding this:

OPTION FRAMEPRESERVEFLAGS:ON
OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE

to the beginning of the file works around the issue.

teoberi commented 2 years ago

7-Zip 21.06 compiled with UASM v2.52 -> no longer appears segfaults on benchmark with or without -mmt1 / -mmt2

john-terraspace commented 2 years ago

The suggested way to disable the automatic prologue/epilogue generation is correct. I'm double checking if the sub/add rsp pair are still incorrectly generated regardless. Stack should always be aligned 16.

john-terraspace commented 2 years ago

I've tested a number of scenarios with argument counts and register preservations across calls with USES and it appears ok to me. I suspect this might have been a combination of the code in question doing it's own stack-ops at the same time as UASM trying to implement smart stack management. Will close unless an issue with Nix stack alignment comes up again.