Terraspace / UASM

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

Why is stack probe disabled? #104

Open vid512 opened 5 years ago

vid512 commented 5 years ago

From https://github.com/Terraspace/UASM/blob/master/procJWasm.c:

/* STACKPROBE: emit a conditional "call __chkstk" inside the prologue

  • if stack space that is to be allocated exceeds 1000h bytes.
  • this is currently implemented for 64-bit only,
  • if OPTION FRAME:AUTO is set and the procedure has the FRAME attribute.
  • it's not active by default because, in a few cases, the listing might get messed. */

    define STACKPROBE 0

  1. Is there a more detailed info what gets wrong with listing, when stack probe enabled?

  2. When STACKPROBE is disabled, I think there should be an error if function declares more than 4KB of local variables.

  3. When enabled, the STACKPROBE feature uses the __chkstk from Microsoft's C runtime library:

if STACKPROBE

   if ( info->localsize + resstack > 0x1000 ) {
       AddLineQueueX( *(ppfmt+2), T_RAX, NUMQUAL info->localsize, sym_ReservedStack->name );
       AddLineQueue(  "externdef __chkstk:PROC" );
       AddLineQueue(  "call __chkstk" );
       AddLineQueueX( "mov %r, %r", T_RSP, T_RAX );
   } else

endif

Is it really necessary to make UASM code dependant on Microsoft C runtime? I think the feature could be implemented with custom code touching each page. That's just 1 extra instruction per page when there are few pages, or very small loop otherwise. UASM already has all the information needed to generate such code, probably with less runtime overhead than __chkstk involves.

john-terraspace commented 5 years ago

It definitely should if re-implemented not use any external lib. I will look into this.