Terraspace / UASM

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

Nix64 mis-aligned stack #170

Closed john-terraspace closed 3 months ago

john-terraspace commented 2 years ago

Symptom: Stack misaligned using invoke in procedures "buffer_insert_text" and "control_g". Test: If the first two invokes in the first two procedures are commented out then the stack in later functions aligns to multiples of 16 and works ok. This is why I included them in this test case, same functions in different procedures are conflicting. Before refining this test case, I noticed that the listing while assembling was generating correct opcodes but the resulting object file was stack misaligned. In this test case the listing (opcodes) is a bit ghost. Could you take a look, please? Thank you in advance.

;uasm -elf64 main.asm .X64 gpointer typedef qword gint typedef dword

gtk_list_store_set proto :vararg gtk_tree_model_get proto :vararg

GtkTreeIter struct sizeof gpointer stamp gint 0 user_data gpointer 0 user_data2 gpointer 0 user_data3 gpointer 0 GtkTreeIter ends

.DATA

WedgNewProject_iter GtkTreeIter <>

.CODE

add_to_WTVListTemplate PROC _str:gpointer ,_Desc:gpointer, _FulFile:gpointer local store:gpointer local l_str:gpointer local l_Desc:gpointer local l_FulFile:gpointer invoke gtk_list_store_set,store, addr WedgNewProject_iter, 0, l_str,1,l_Desc,2,l_FulFile, -1 RET add_to_WTVListTemplate ENDP

on_WTVListTemplatechanged proc local lTreeModel:gpointer local lTreeIter:GtkTreeIter local lValue:gpointer local lDesc:gpointer local lFile:gpointer invoke gtk_tree_model_get,lTreeModel, addr lTreeIter,0,addr lValue,1,addr lDesc,2,addr lFile,-1 ret on_WTVListTemplatechanged endp

buffer_insert_text PROC local _store:gpointer local tree_iter:GtkTreeIter invoke gtk_list_store_set,_store,addr tree_iter,0,CStr("File"),-1 ret buffer_insert_text ENDP

control_g PROC local model:gpointer local iter:gpointer local value:gpointer invoke gtk_tree_model_get,model,addr iter,0,addr value,-1 ret control_g ENDP

end

john-terraspace commented 2 years ago

Fixed in 2.56. I've changed the sys-v abi invoke and proc prologue quite a bit, to not only fix the misalignment but get rid of the extra sub/add pairs. The alignment offset is calculated by invokes and applied to the parent proc now.