The MASM Forum

64 bit assembler => UASM Assembler Development => Topic started by: johnsa on August 11, 2024, 07:51:42 AM

Title: UASM 2.57
Post by: johnsa on August 11, 2024, 07:51:42 AM
Finally after a long hiatus.. UASM 2.57 is up!
Latest code in v2.57 branch on GitHub + Releases as well as binary packages on the web, https://www.terraspace.co.uk/uasm.html

Changes:
1. Added aam/aad imm8 missing instruction variant.
2. Added corrections for constant too large warnings and included >64bit size immediate errors.
3. Corrected a conflict between local and struct having the same name.
4. Updated the encoding of xchg eax,eax to not just be a NOP in 64bit code as a side effect is clearing the top half of RAX.
5. Reduced unnecessary REX prefixes in PROC prologue.
6. Cleaned up makefile names
7. Fixed a general failure on empty unions.
8. Applied typedef ptr fix in legacy codeview symbolic debugging info.
9. Noted string literal usage in manual.
10. Fixed a stack balancing regression leading to an umatched add/sub rsp,8 pair for Linux 64bit.
11. Prevented vmovd/vmovq from accepting ymm or zmm registes.
12. Prevent OR rax,64bit immediate and other instructions that aren't MOV.
13. Based on a patch to original Jwasm which may have entered an infinite loop if a structured variable wasn't
    defined (yet), but a member name matched a local name.
14. Included Vortex Def2Lib utility in the distribution with Import Definitions kindly supplied from MASM32.
    Can be run via MakeLib.bat or   
    def2lib *.def
    def2lib ntvdm.def -e
Title: Re: UASM 2.57
Post by: fearless on August 11, 2024, 11:11:58 AM
Thank you johnsa
Title: Re: UASM 2.57
Post by: Biterider on August 11, 2024, 02:57:17 PM
Hi Johnsa
Thank you very much for this update  :thumbsup:
I'm testing it now, but to get this version from the UASM site, I had to download the x64, x86 and Linux64 versions directly using:

https://www.terraspace.co.uk/uasm257_x64.zip (https://www.terraspace.co.uk/uasm257_x64.zip)
https://www.terraspace.co.uk/uasm257_x86.zip (https://www.terraspace.co.uk/uasm257_x86.zip)
https://www.terraspace.co.uk/uasm257_linux64.zip (https://www.terraspace.co.uk/uasm257_linux64.zip)

I'm unsure if the github main is merged with the 257 branch
QuoteThis branch is 66 commits ahead of, 15 commits behind master.

Regards, Biterider
 
Title: Re: UASM 2.57
Post by: jj2007 on August 11, 2024, 05:42:45 PM
Thanks a lot, John :thumbsup:
Title: Re: UASM 2.57
Post by: johnsa on August 11, 2024, 06:25:50 PM
master branch isn't merged yet, the source is in the v2.57 release branch still.

Strange that you had do d/l directly, releases should be on the GitHub page as well as via the website?
Title: Re: UASM 2.57
Post by: Biterider on August 11, 2024, 06:31:29 PM
Hi John
Checking the UASM webpage again and now is is shown correctly with version 2.57. 
Maybe a cache issue...

Biterider
Title: Re: UASM 2.57
Post by: Vortex on August 11, 2024, 06:40:32 PM
Hi John,

Many thanks :thumbsup:
Title: Re: UASM 2.57
Post by: mabdelouahab on August 11, 2024, 07:34:47 PM
Thank you, Johnsa. The problem has been resolved  :thumbsup:
But the floating-point bug that I mentioned in this topic Floating point arguments (https://masm32.com/board/index.php?topic=8005.0) still remains. I hope you can fix it in future updates. Thanks anyway.
Title: Re: UASM 2.57
Post by: mabdelouahab on August 11, 2024, 09:39:02 PM
Hello Johnsa

I've noticed that the '-Fo' option, which is documented to set object file name, does not seem to be working as expected. When I try to use this option, the assembler doesn't produce the desired output, and the functionality appears to be broken or unsupported on Linux.

Could you please investigate this issue and provide a fix or guidance on how to use this option correctly in a Linux environment?

Best regards
Title: Re: UASM 2.57
Post by: johnsa on August 12, 2024, 02:18:06 AM
Quote from: mabdelouahab on August 11, 2024, 07:34:47 PMThank you, Johnsa. The problem has been resolved  :thumbsup:
But the floating-point bug that I mentioned in this topic Floating point arguments (https://masm32.com/board/index.php?topic=8005.0) still remains. I hope you can fix it in future updates. Thanks anyway.
I've logged this one to have a look at!
Title: Re: UASM 2.57
Post by: daydreamer on August 12, 2024, 03:29:53 AM
Thanks johnsa 
Title: Re: UASM 2.57
Post by: rsala on August 17, 2024, 06:37:00 PM
Hi Johnsa,

UASM64 is the compiler used to build Easy Code v2 64-bit and I must say that the IDE works perfectly well with that last version of UASM. Congratulations and thanks for your good work!
Title: Re: UASM 2.57
Post by: Biterider on August 17, 2024, 07:40:24 PM
Hi John
I just wanted to give you a quick heads-up on the latest UASM version 2.57. 

I've been using it since it was released and haven't had any issues.  :thumbsup:

I've also recompiled about 70 projects on Windows and 2 on Linux, and everything's gone smoothly. 
On Linux, I came across the -Fo issue that mabdelouahab mentioned, but it's not a big deal since it can be handled in a compilation script.

Many thanks, John, for this fantastic job!  :thup:

Biterider


Title: Re: UASM 2.57
Post by: mabdelouahab on August 17, 2024, 09:30:47 PM
Hi John
I encountered an issue with the latest version of uasm (2.57). Instead of generating 'add rsp, 0x10', it generated 'add rsp, 0x8'. This issue appears to be specific to this updated version and causes the program to stop. Could you please look into this?

    mysql_real_connect(r11,r12,r13,r14,r15, 0, 0, 0)

    0x00402cc4      mov     rdi, r11
    0x00402cc7      mov     rsi, r12
    0x00402cca      mov     rdx, r13
    0x00402ccd      mov     rcx, r14
    0x00402cd0      mov     r8, r15
    0x00402cd3      xor     r9, r9
    0x00402cd6      push    0        <---------
    0x00402cd8      push    0        <---------
    0x00402cda      xor     eax, eax
    0x00402cdc      call    mysql_real_connect ; sym.imp.mysql_real_connect
    0x00402ce1      add     rsp, 8


As a temporary workaround to keep the program running correctly, I manually added the line 'add rsp, 8' after the function:

    mysql_real_connect(r11,r12,r13,r14,r15, 0, 0, 0)
    add     rsp, 8

 :biggrin:

Title: Re: UASM 2.57
Post by: mineiro on August 19, 2024, 12:03:56 PM
Thank you sir johnsa;

Please can you investigate this?
I was not able to create shared library that have inside a call to external functions.
So I changed in elf.c file line bellow:
;//            elftype = R_X86_64_PC32;
;              elftype = R_X86_64_PLT32;
Compile module.asm with uasm not modified, compile plugin.asm with modified uasm.

module.asm
;uasm -elf64 module.asm
;gcc -o module module.o -fno-pie -no-pie `pkg-config --cflags --libs glib-2.0 gmodule-2.0`

.X64
option casemap:none
option literals:on
option language:systemv

gtk_init proto :vararg
g_module_supported proto :vararg
g_module_build_path proto :vararg
g_module_open proto :vararg
g_module_make_resident proto :vararg
g_module_symbol proto :vararg
g_module_close proto :vararg
g_free proto :vararg

dlsym proto :vararg
printf proto :vararg

G_MODULE_BIND_LAZY equ 1
RTLD_DEFAULT equ 0

.data
align 16
public version
version db "version 0.0.0",0


.code
align 16
main PROC argc:dword, pargv:ptr

local asm_argc:dword
local asm_argv:qword

local module:qword
local module_path:qword
local function_addr:qword

mov  asm_argc,argc
mov  asm_argv,pargv

.if g_module_supported()
mov module_path,g_module_build_path("./","libplugin")
.if g_module_open(module_path,G_MODULE_BIND_LAZY)
mov module,rax
; g_module_make_resident(module) ;-fPIC option used in command line? uncomment this line
.if g_module_symbol(module,"asm_plugin",&function_addr)
call function_addr
.endif
g_module_close(module)
.endif
g_free(module_path)
.endif

xor eax,eax
ret
main ENDP


align 16
public asm_get_address
asm_get_address proc (pointer) uses r12 r13 r14 r15 rbx _var_name:ptr
local var_name:qword

mov var_name,_var_name
dlsym(RTLD_DEFAULT,var_name)
ret
asm_get_address endp


align 16
public show_this
show_this proc uses r12 r13 r14 r15 rbx _var_name1:ptr
local var_name:qword

mov var_name,_var_name1
printf(CStr("%s",10),var_name)
ret
show_this endp


end main


plugin.asm
;uasm elf.c changed, commented and changed to (only one occurrence):
;//            elftype = R_X86_64_PC32;
;              elftype = R_X86_64_PLT32;

;uasm -elf64 plugin.asm

;gcc -shared -o libplugin.so plugin.o
;or
;gcc -shared -fPIC -o libplugin.so plugin.o

.X64
option casemap:none
option literals:on

printf proto :vararg
asm_get_address proto :ptr
;show_this proto :ptr

.data
version db "version 0.0.1",0

.code
align 16
public asm_plugin
asm_plugin proc uses r12 r13 r14 r15 rbx _GtkBuilder_:qword

asm_get_address("version")
.if rax
printf(CStr("%s",10),rax)
.endif

asm_get_address("show_this")
.if rax
lea rdi,version
call rax
.endif

ret
asm_plugin endp

align 16
g_module_check_init proc
printf(CStr("g_module_check_init",10))
xor eax,eax
ret
g_module_check_init endp

align 16
g_module_unload proc
printf(CStr("g_module_unload",10))
xor eax,eax
ret
g_module_unload endp

end

again, thank you for your efforts.
Title: Re: UASM 2.57
Post by: johnsa on August 20, 2024, 10:26:35 PM
I think shared libraries depend on PLT and GOT - much like PIE executables, neither of which are supported - and for years there has been no clear or logical way to support them.

Without a HLL language/compiler to infer the plt/got stuff I've not seen any assembler actually solve this.
YASM had something - but it's dead and never worked right, I don't know the state of NASM in this regard, there was a whole bunch of awful filth about using ..wrt operator.

I don't really work on Linux so I'm no expert, but happy for someone to help try and solve things - as far as I can tell from my albeit limited perspective, Linux is a piece of sh1t and designed by C programmers who clearly hate assembly language. :)
Title: Re: UASM 2.57
Post by: mineiro on August 22, 2024, 08:44:05 AM
I'm not a C programmer, so I can't help in this sense.
My investigation tolds me that if a shared library don't use internally a call to an external function that exist in a library, so that works fine. The main problem that I faced was when calling an external function that exist in a library.

native.asm
;not modified uasm without calling a function in an external library
;uasm -elf64 -pie native.asm
;ld --no-dynamic-linker -pie -e _start -o native native.o

;or using plugin.o from previous post
;uasm -elf64 -pie native.asm
;gcc -shared -o libplugin.so plugin.o native.o

.x64
.data
hello db "hello",10,0


.code
public _start
_start:
public quit
quit:

    mov rax,1
    mov rdi,1
    lea rsi,hello
    mov rdx,sizeof hello
    syscall

    mov rax,60
    mov rdi,0
    syscall


;end _start
end

Position independent code is working in my tests too (with modified uasm from previous post).
pie.asm
;modified uasm
;uasm -elf64 pie.asm
;gcc -lc -pie pie.o -o pie

.X64
option casemap:none

printf proto :vararg
exit proto :dword

.code
public main
main proc uses r12 argc:dword, argv:ptr
; call @F
;@@:
; pop r12
; sub r12,$-main

lea r12,main
invoke printf,CStr("%016llx",10),r12
    invoke exit,0
main endp

end main

results from program above run multiple times (checked with debugger too):
./pie
0000555841760150
000055e0f34cc150
00005591c59ca150
...

edited: lea r12, main
I was thinking in a switch in uasm command line to elf64, that description is something like "use R_X86_64_PLT32 instead of R_X86_64_PC32".
Title: Re: UASM 2.57
Post by: tenkey on September 15, 2024, 11:47:21 PM
PROC directive appears to be broken. It doesn't list the PROC line and affects the following line.

Example:

The original source:

xWinMain PROC

invoke DialogBoxIndirectParam, InstanceHandle, addr TheDialogTemplate, NULL, addr TheDialogProc, NULL

XOR EAX, EAX

The listing:

00000031                    00000031  4883EC08          *   sub rsp, 8
          invoke __im00000035                    nstanceHandle, addr TheDialogTemplate, NULL, addr TheDialogProc, NULL
0000002D                    *   sub rsp, 48
00000035  4883EC30           *    mov rcx, In00000039  488B0D00000000                  *    lea rdx, Th00000040  488D1500000000                     *    xor r8d, r800000047  4533C0               *    lea r9, The0000004A  4C8D0D00000000                *    mov qword p00000051  48C744242000000000                   *    call __imp_0000005A  FF1500000000      00059                    *    add rsp, 48000000000064  33C0                  XOR EAX, EAX

The command line:

uasm -win64 -Fl -Sg -Sn GOL.asm
One file, several examples: GOL.zip
Title: Re: UASM 2.57
Post by: lucho on September 25, 2024, 04:51:41 PM
Thanks, John, for continuing the development of UASM! I've now built version 2.57 also for macOS, Solaris, FreeBSD, NetBSD and OpenBSD, so if anyone needs some of these binaries, please let me know.

Unfortunately, UASM can only generate debug information for Windows, so these builds cannot generate one for the corresponding operating system they've been built for.

Lucho (https://lucho.ddns.net/)
Title: Re: UASM 2.57
Post by: 2B||!2B on September 28, 2024, 01:33:03 PM
Thanks for the update.

With this new version, I'm occasionally getting error from the linker

fatal error LNK1103: debugging information corrupt; recompile module
This error didn't exist in 2.56 version.
This is UASM64.

For UASM32 2.57, there are also bugs with the linker
The 32-bit linker ... ran out of heap space and is going to restart linking with a 64-bit linker
But if I use the 64 linker,
Another error shows up
link : fatal error lnk1102: out of memory
I'm not sure what changed in 2.57 that broke this.
For now I will just stick to 2.56.
Title: Re: UASM 2.57
Post by: johnsa on March 13, 2025, 06:59:43 AM
Which version of Link are you running?

I'm logging this to work on for 2.58 now.