Author Topic: macro for call-convention name mangling  (Read 264 times)

KradMoonRa

  • Regular Member
  • *
  • Posts: 23
macro for call-convention name mangling
« on: June 17, 2018, 09:07:23 AM »
 :biggrin:

After some research how exported symbols from uasm to call convention c or c++ works, I came with a macro to make the task easy to write asm code.

Currently I only have it done for __vectorcall exported c function. I want to know more about unix gcc or clang systemv call and the name mangling for it. Researching how c++ name mangling applies for the different compilers, conventions and  architecture.

Code: [Select]
#ifdef __cplusplus
extern "C" {
#endif
extern __m128i __vectorcall _uXm_mm_move_si128(__m128i Inxmm_A);
#ifdef __cplusplus
}
#endif

Code: [Select]
include uXmx86asm.inc

_uXm_func_start _uXm_mm_move_si128, xmmword, < >, 16 ;xmm_size ;InXmm_A:xmmword
movdqa xmm0, xmm0
ret
_uXm_func_end
.code


Code: [Select]
;; function proc macro start
;; name, return type, uses, parameter's size
_uXm_func_start macro functionName:REQ, retType:REQ, usesStr:REQ, parameterSize:REQ
ifdef WINDOWS
curfunctionName textequ <functionName>
  ifdef EXTERNC_VECCALL
curfunctionName catstr curfunctionName, <@@>, _uXm_StrValue(parameterSize)
  endif
_curfunctionName_ textequ <curfunctionName>
else
_curfunctionName_ textequ <functionName>
endif

fnexproto textequ <>
fnexproto catstr fnexproto, <&functionName&>
ifdef WINDOWS
  ifdef EXTERNC_VECCALL
fnexproto catstr fnexproto, <@@>, _uXm_StrValue(parameterSize)
  endif
else
endif
fnexproto catstr fnexproto, < proto __veccall >, <(&retType&)>
fnexproto

fnexproc textequ <>
fnexproc catstr fnexproc, <&functionName&>
ifdef WINDOWS
  ifdef EXTERNC_VECCALL
fnexproc catstr fnexproc, <@@>, _uXm_StrValue(parameterSize)
  endif
else
endif
fnexproc catstr fnexproc, < proc __veccall >, <(&retType&)>, < >, <frame>, < >, <&usesStr&>

fnexproc
endm

;; function proc macro end
_uXm_func_end macro
fnexfuncend textequ <>
fnexfuncend catstr fnexfuncend, _curfunctionName_
fnexfuncend catstr fnexfuncend, < endp>
fnexfuncend
endm

Some examples in the zip file
« Last Edit: June 17, 2018, 05:54:59 PM by KradMoonRa »

habran

  • Member
  • *****
  • Posts: 1168
    • uasm
Re: macro for call-convention name mangling
« Reply #1 on: June 17, 2018, 11:40:48 PM »
Hi KradMoonRa :biggrin:
Who am I to criticise your style of coding, however, you get me lost at second '_
It is painful for me to read expressions like: _uXm_func_start _uXm_mm_move_si128 _uXm_func_end
I believe you would get more people interested in your code if you simplify your expressions EG:
 UxmFuncStart or something similar.
Please, don't be offended, I appreciate your intentions and work 8)
Cod-Father

KradMoonRa

  • Regular Member
  • *
  • Posts: 23
Re: macro for call-convention name mangling
« Reply #2 on: June 18, 2018, 05:30:43 AM »
Hi habran  :biggrin:,

No problem, really appreciate Your comment.
Macro definitions (one of the thing's i mess around in macro world), but just for the sake of read and search, which conflicts with fast coding write, almost I do its a copy and paste with the rename.

I'll change my code.

habran

  • Member
  • *****
  • Posts: 1168
    • uasm
Re: macro for call-convention name mangling
« Reply #3 on: June 18, 2018, 08:10:10 AM »
I am glad you are not offended, that tells me more about your great personality:t
Keep up good work 8)
Cod-Father

KradMoonRa

  • Regular Member
  • *
  • Posts: 23
Re: macro for call-convention name mangling
« Reply #4 on: June 27, 2018, 04:26:34 AM »
 :biggrin:

  Coding is fun. Some dig-in the UASM code, I made some 2 small options changes in the code to use vectorcall globally uasm command option -Gv and names mangle exported symbols for vectorcall with a help of macro to emulate xmmword sizes.

  Unfortunately I have no idea to make the necessary changes in uasm mangler to recognize param sizes higher than the general register type sizes 8 for 64bits 4 for 32bits.

  I have played with ParseParams and parasize but no idea to make work correctly, CurrWordSize its a fixed value only applies to general registers and the code never checks for different registers types and sizes.

  Staying with macros if the reference parameter its never used in asm, this emulates the xmmword sizes with extra general register references parameters.

Example:
 
Code: [Select]
_uX_mm_shuffle_ps proc uXveccall (xmmword) xmmwordparam1(InxmmA), xmmwordparam2(InxmmB), _Imm8:dword
     ret
_uX_mm_shuffle_ps endp

prints correctly
_uX_mm_shuffle_ps@@40  (2*xmmword+gr)

Attached precompiled uasm requerid to test and my test examples.


« Last Edit: July 01, 2018, 10:37:14 PM by KradMoonRa »

jj2007

  • Member
  • *****
  • Posts: 8504
  • Assembler is fun ;-)
    • MasmBasic
Re: macro for call-convention name mangling
« Reply #5 on: June 27, 2018, 01:45:04 PM »
  Unfortunately I have no idea to make the necessary changes in uasm to recognize param sizes higher than the general register type sizes 8 for 64bits 4 for 32bits.

Have you tried something like this:
Code: [Select]
themac MACRO arg
Local is
  is INSTR <arg>, <xmm>
  if is
      ... 16 byte code ...
  else
    if TYPE(arg) eq XMMWORD
      ... 16 byte code ...
    elseif TYPE(arg) eq QWORD
      ... 8 byte code ...
    elseif TYPE(arg) eq DWORD
      ...
    else
  endif
ENDM

johnsa

  • Member
  • ****
  • Posts: 682
    • Uasm
Re: macro for call-convention name mangling
« Reply #6 on: June 27, 2018, 11:55:12 PM »
:XMMWORD If i recall should be a recognised type, as well as the new built in data types for __m128 etc.
UASM already supports vectorcall and uses those types on the arguments list.. Perhaps give that a try and just focus on name-mangling of the proc name itself ?

KradMoonRa

  • Regular Member
  • *
  • Posts: 23
Re: macro for call-convention name mangling
« Reply #7 on: June 28, 2018, 12:22:32 AM »
Hi  :biggrin: jj2007 and johnsa,

Quote
jj2007
  That will be a good solution to recognize the types in asm, and send the correct int. Macro its cool indeed.

Quote
johnsa
  Sorry I have not explained correctly myself.
  I has only trying to use the mangler edition already in uasm, but its only available for stdcall and or fastcall, one little add in uasm c++ code I almost do what I pretend, barely miss the essential to recognize the types reg's sizes (print) for xmmword ymmword zmmword, same results for __m128, __m256, __m512, wen its an reference param in protos or procs.

   I'm happy with the macros, but love to find new options already in uasm, but I never know if I dont read the uasm c++ code itself.

  :t