News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

Issue with ALIAS

Started by Vortex, April 04, 2024, 06:05:50 AM

Previous topic - Next topic

Vortex

Hello,

Poasm v12 can assemble the code below but ml.exe v6.14 and asmc v2.34.50 are reporting the following error message  :

Test.asm(9) : error A2005: symbol redefinition : OutputText
How to use correctly ALIAS?

.386
.model flat,stdcall
option casemap:none

ExitProcess PROTO :DWORD
printf PROTO C :DWORD,:VARARG
OutputText PROTO C :DWORD,:VARARG

ALIAS <OutputText>=<printf>

includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\msvcrt.lib

.data

msg db 'Test',0

.code

start:

    invoke  OutputText,ADDR msg

    invoke  ExitProcess,0

END start

Biterider

#1
Hi Vortex
Try something like
OutputText textequ <printf>
Biterider

Vortex

Hi Biterider,

Thanks but the effect of ALIAS shows itsels during the linker stage, from Pelles C manual :

QuoteThe ALIAS directive creates an alternate name for a procedure (function). This lets you create multiple names for the same procedure, or create libraries that allow the linker to map an old name to a new name. The alias argument specifies the new name, and the actual-name argument specifies the name of an existing procedure. The existing procedure does not have to be defined in the current source file.

Another source :

https://learn.microsoft.com/en-us/cpp/assembler/masm/alias-masm?view=msvc-170

sudoku

Why not simply invoke 'printf'?

I have tried a couple things including a wrapper procedure...

.386
.model flat,stdcall
option casemap:none

ExitProcess PROTO :DWORD
printf PROTO C :DWORD,:VARARG
OutputText PROTO C :DWORD,:VARARG



includelib  \masm32\lib\kernel32.lib
includelib  \masm32\lib\msvcrt.lib

.data

msg db 'Test',0

.code

start:

    invoke  OutputText, ADDR msg

    invoke  ExitProcess,0

OPTION PROLOGUE:NONE
OPTION EPILOGUE:NONE
OutputText proc C xx:DWORD, args:VARARG
    invoke printf, xx
    RET
OutputText endp
OPTION PROLOGUE:PrologueDef
OPTION EPILOGUE:EpilogueDef

END start

Why though, if printf works fine by itself?

Have you tried different versions of ml??? I too had no luck with the version in the masm32 Sdk...
:eusa_naughty:

Vortex

Hi sudoku

I am afraid we are not talking about the same thing. How about mapping an old symbol to a new one? Consider this Poasm example :

Test.asm :

.386
.model flat,stdcall
option casemap:none

TerminateApp PROTO :DWORD
OutputText PROTO C :DWORD,:VARARG

includelib  \PellesC\lib\Win\kernel32.lib
includelib  msvcrt.lib

.data

msg db 'Test',0

.code

start:

    invoke  OutputText,ADDR msg

    invoke  TerminateApp,0

END start

Alias.asm :

.386
.model flat,stdcall
option casemap:none

TerminateApp PROTO :DWORD
OutputText PROTO C :DWORD,:VARARG

ALIAS <OutputText>=<printf>
ALIAS <TerminateApp>=<ExitProcess@4>

END

Build.bat :

\PellesC\bin\polib /OUT:msvcrt.lib /MACHINE:x86 /DEF:msvcrt.def

\PellesC\bin\poasm/AIA32 Alias.asm
\PellesC\bin\poasm/AIA32 Test.asm
\PellesC\bin\polink /SUBSYSTEM:CONSOLE Test.obj Alias.obj

The list of weak externals :

\PellesC\bin\podump.exe /symbols Alias.obj

Dump of Alias.obj

File type: OBJ

SYMBOL TABLE
0000 00000001 ABS    notype      static       | @feat.00
0001 00000000 UNDEF  notype      external     | _printf
0002 00000000 UNDEF  notype      weak external | _OutputText
     alternate index 0001, search alias
0004 00000000 UNDEF  notype      external     | _ExitProcess@4
0005 00000000 UNDEF  notype      weak external | _TerminateApp@4
     alternate index 0004, search alias

One you have the list of aliases, no need of TEXTEQUs. This is an example of academic interest.

sudoku

Hi Vortex, it was just curiosity on my part. I have never used ALIAS and very seldom used textequ.
Have you tried a more recent version of ml?
:eusa_naughty:

Biterider

Hi Vortex
I wasn't aware of this feature.
I tried it with the latest version of UASM 

ALIAS <OutputText>=<ConvertNumber>
where ConvertNumber is a real procedure in my code. 
The assembler and linker did not complain  :cool:

Biterider


Vortex

Hi sudoku,

Testing with ml.exe v14.29.30152.0 :

Alias.asm(7) : error A2006:undefined symbol : printf
Hi Biterider,

No luck with Uasm :

UASM v2.56, Oct 27 2022, Masm-compatible assembler.
Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.

Alias.asm(7) : Error A2143: Symbol redefinition: OutputText
Alias.asm: 9 lines, 1 passes, 5 ms, 0 warnings, 1 errors

Alias.asm

.386
.model flat,stdcall
option casemap:none

OutputText PROTO C :DWORD,:VARARG

ALIAS <OutputText>=<printf>

END

Biterider

Hi Vortex
it seems that using invoke directly doesn't work. 
The assember doesnt know how to handle AliasProc and even typecasting the call, it produces wrong code (1 indirection)

.code

MyProc proc dParam1:DWORD, dParam2:DWORD
  mov eax, dParam1
  mov ecx, dParam2
  ret
MyProc endp

MyProcType typedef proto :DWORD, :DWORD
ALIAS <AliasProc>=<MyProc>

start proc
  int 3
  invoke MyProc, 1, 2
  invoke MyProcType ptr AliasProc, 3, 4

  invoke ExitProcess, 0
start endp

end

What works is a simple (x64)

mov ecx, 3
mov edx, 4
call AliasProc

it jumps to the right location.

Biterider

Biterider

Hi Vortex

A workaround is

  lea xsi, AliasProc
  invoke MyProcType ptr xsi, 3, 4

Now it calls the correct procedure, but I think this is not the intended way it should work.  :dazzled:

Biterider

sinsi

I think an ALIAS is a way of letting the linker find a function in an obj file.
It wouldn't make sense to use it the way you are trying, you would just use TEXTEQU

.386
.model flat,stdcall
option casemap:none

ExitProcess PROTO :DWORD

ALIAS <entry_point>=<start>

includelib  \masm32\lib\kernel32.lib

.code

start proc public
    invoke  ExitProcess,0
start endp   

END start

Part of the output for dumpbin
COFF SYMBOL TABLE
000 00000000 DEBUG  notype       Filename     | .file
    Z:\asm\VORTEX.asm
002 001220FC ABS    notype       Static       | @comp.id
003 00000000 SECT1  notype       Static       | .text
    Section length    7, #relocs    1, #linenums    0, checksum        0
005 00000000 SECT2  notype       Static       | .data
    Section length    0, #relocs    0, #linenums    0, checksum        0
007 00000000 SECT3  notype       Static       | .drectve
    Section length   34, #relocs    0, #linenums    0, checksum        0
009 00000000 UNDEF  notype ()    External     | _ExitProcess@4
00A 00000000 UNDEF  notype ()    External     | _start@0
00B 00000000 UNDEF  notype       WeakExternal | _entry_point
    Default index        A Alias record
00D 00000000 SECT1  notype ()    External     | _start@0

mabdelouahab

Hi Vortex
There is an example, which might help: rdrand.asm

;; Fastcall calling conventions exports
ALIAS <@MASM_RDRAND_GenerateBlock@8> = <MASM_RDRAND_GenerateBlock>
ALIAS <@MASM_RDSEED_GenerateBlock@8> = <MASM_RDSEED_GenerateBlock>


Biterider

Hi
I got it working thanks to Sinsi's hint.  :thumbsup:

When building a library, you can use the ALIAS to tell the linker to store an additional (aliased) entry in the .obj file (.lib file).

When you then use your library, and provided you specify a proto for this aliased procedure, the assembler will resolve it correctly.

In the library procedure
ALIAS <AliasProc>=<udword2decA>
In the application
.code

AliasProc proto :POINTER, :DWORD

start proc
  local cBuffer[1024]:CHR

  invoke udword2decA, addr cBuffer, 123    ;<= original procedure
  invoke AliasProc, addr cBuffer, 123      ;<= alias procedure
  invoke ExitProcess, 0
start endp


Biterider

sudoku

Quote from: Biterider on April 04, 2024, 05:40:33 PMHi
I got it working thanks to Sinsi's hint.  :thumbsup:

When building a library, you can use the ALIAS to tell the linker to store an additional (aliased) entry in the .obj file (.lib file).

When you then use your library, and provided you specify a proto for this aliased procedure, the assembler will resolve it correctly.

...
Biterider


This is interesting indeed. Indeed this appears to be exactly what Vortex was after. I couldn't for the life of me, figure it out. Now I will have to experiment using this in my sudoku function library. :)
:eusa_naughty:

Vortex

Hello,

Thanks for the replies and the tests. Talking to Nidud (the author of Asmc) about the issue, I received the following reply in his GitHub account :

QuoteAsmc (and Masm) wont allow a direct redefinition of symbols like this. The syntax is:

ALIAS <alias> = <actual-name>
It's possible to use the UNDEF directive here thought:

Nidud's sample code :

.386
.model flat,stdcall
option casemap:none

printf      proto c :ptr, :vararg
OutputText  proto c :ptr, :vararg

undef OutputText
ALIAS <OutputText>=<printf>

.code
OutputText("%s(%d)\n", __FILE__, __LINE__)
end

Thanks Nidud. It looks like that only Poasm and Asmc can correctly handle my case.