The MASM Forum

General => The Workshop => Topic started by: TouEnMasm on December 12, 2014, 06:13:51 AM

Title: problem building a 64 bits executable
Post by: TouEnMasm on December 12, 2014, 06:13:51 AM
Hello,
I have made a set of header files for 64 bits
To test them,i use sample provided with jwasm Win64_8.asm
I have just replace the definitions by the include.
The problem is that he don't want to run.
I have made verifies on the prototypes,on the structure without finding any error.
Help !
Title: Re: problem building a 64 bits executable
Post by: TouEnMasm on December 12, 2014, 06:26:17 AM
found:
just use link without adding libraries

Quote
Link  /SUBSYSTEM:WINDOWS /DEBUG /debugtype:cv /OUT:%FILE%.exe *.obj %FILE%.bin

It seems also that the link option /NXCOMPAT:NO could help
Title: Re: problem building a 64 bits executable
Post by: Gunther on December 12, 2014, 06:58:50 PM
Hi ToutEnMasm,

you could use GoLink as an alternative, too. You can find usage examples here (http://masm32.com/board/index.php?topic=1892.msg19653#msg19653) and here (http://masm32.com/board/index.php?topic=1504.msg15448#msg15448).

Gunther
Title: Re: problem building a 64 bits executable
Post by: TouEnMasm on December 12, 2014, 07:21:38 PM
Thanks for answer
My first attempt was a little confused with header path (I have mixed 32 and 64 headers).
Title: Re: problem building a 64 bits executable
Post by: Gunther on December 12, 2014, 07:58:46 PM
Quote from: ToutEnMasm on December 12, 2014, 07:21:38 PM
My first attempt was a little confused with header path (I have mixed 32 and 64 headers).

That's indeed a bit confused and a bad idea. But you found the error and that counts.

Gunther
Title: Re: problem building a 64 bits executable
Post by: TouEnMasm on December 13, 2014, 01:42:25 AM

I have re-posted the sample working (show a window and an image) using the include.
Now it's the messagebox who don't want to work,it's in the message directory.
This one seems to be more difficult to find.
Title: Re: problem building a 64 bits executable
Post by: qWord on December 13, 2014, 02:07:10 AM
You must align the stack on program entry.
I'm wondering, why this strange type XMASM? Types like HBITMAP, HINSTANCE, LPTSTR, HWND, HANDLE, ... should be usable?
Title: Re: problem building a 64 bits executable
Post by: TouEnMasm on December 13, 2014, 02:47:59 AM
Quote
XMASM?

XMASM typedef ptr    ;dword size in 32 bits,64 in X64

align the stack ?
Must be done on the window sample,and the messagebox don't work
Title: Re: problem building a 64 bits executable
Post by: qWord on December 13, 2014, 03:09:43 AM
Quote from: ToutEnMasm on December 13, 2014, 02:47:59 AM
XMASM typedef ptr    ;dword size in 32 bits,64 in X64
yes, but Windows's "natural" pointer- and handle types should have the same behavior.

Quote from: ToutEnMasm on December 13, 2014, 02:47:59 AMalign the stack ?
lookout for fastcall calling convention.
The stack is align to 8, when reaching the start-label, but it must be aligned to 16 when calling APIs. Also you must (at least) allocate the shadow space for RCX, RDX, r8 and r9:
start:
add rsp,-(8 + 4 * 8) ; - (align + shadow space)

Title: Re: problem building a 64 bits executable
Post by: TouEnMasm on December 13, 2014, 03:29:54 AM
Quote
start:
add rsp,-(8 + 4 * 8) ; - (align + shadow space)
:t
It wasn't in the samples of jwasm and solve the two problems

I don't see what you call  "natural" pointer,the one i need change is size just  adding .X64
This avoid to made header for 32 and header for 64
Title: Re: problem building a 64 bits executable
Post by: TouEnMasm on December 13, 2014, 06:35:17 PM

I try to do a simple thing:
Quote
mov rax,45612587h
Don't seem to be allowed ?????
Title: Re: problem building a 64 bits executable
Post by: habran on December 13, 2014, 09:04:51 PM

mov rax,45612587h
000000013F6D11C9 48 C7 C0 87 25 61 45 mov         rax,45612587h
Title: Re: problem building a 64 bits executable
Post by: Gunther on December 14, 2014, 12:26:45 AM
Hi ToutEnMasm,

Quote from: ToutEnMasm on December 13, 2014, 06:35:17 PM
Quote
mov rax,45612587h
Don't seem to be allowed ?????

no, it's allowed, see also Habran's answer.

Gunther
Title: Re: problem building a 64 bits executable
Post by: TouEnMasm on December 14, 2014, 12:55:41 AM
I have the sample without include wo works (b61710b4 48c7c087256145  mov     rax,45612587h)
Put it in the WndProc or after start,same result
The message sample work with this instruction and the header
But the one with include (who show the window and work) just failed to run ,what Happen ??????

The question seems to be,How allocate the stack for a PROC ?
I had try to increase at start,but it doesn't work.

Quote
WinMain proc FRAME hInst:XMASM, hPrevInst:XMASM, CmdLine:XMASM, CmdShow:DWORD

    LOCAL wc:WNDCLASSEX
    LOCAL msg:MSG
    LOCAL hwnd:XMASM
    ;---------- miss something here  --------
Title: Re: problem building a 64 bits executable
Post by: TWell on December 14, 2014, 01:46:13 AM
sub rsp, 4 * sizeof QWORD ?
4 is for shadow for first 4 parameters
Can't say how locals are handled by assembler.
Title: Re: problem building a 64 bits executable
Post by: TouEnMasm on December 14, 2014, 02:12:55 AM

It seems there is need to erase the old  binaries files before a new compile.
If not erase,the new code is bad coded.
 
Title: Re: problem building a 64 bits executable
Post by: qWord on December 14, 2014, 05:47:16 AM
Quote from: ToutEnMasm on December 13, 2014, 03:29:54 AMI don't see what you call  "natural" pointer,the one i need change is size just  adding .X64
This avoid to made header for 32 and header for 64
yes, but why do you use that type in the example code? HBITMAP, HWND, ... are also aliases for XMASM in your include files.
I just thought on readability of the example code, e.g. hWnd:HWND vs. hWnd:XMASM.
Title: Re: problem building a 64 bits executable
Post by: habran on December 14, 2014, 05:50:12 AM
Hi ToutEnMasm :biggrin:
Why do you always complicate things :icon_eek:
Use my version of JWasm and:

option casemap : none
option win64 : 11
option frame : auto
option stackbase : rsp
.xmm

It will align stack and data for you
and use WinInc
You can use Visual Studio Community 2013 for building and debugging you projects 
and your ASM life will blossom :P
Title: Re: problem building a 64 bits executable
Post by: TouEnMasm on December 14, 2014, 06:17:00 AM
Quote
Why do you always complicate things :icon_eek:
Use my version of JWasm and:                          --------- GENERAL FAILURE ----------
I am happy than you ask that.
If you could made the little modify given here:
http://masm32.com/board/index.php?topic=3811.msg40240#msg40240 (http://masm32.com/board/index.php?topic=3811.msg40240#msg40240)
Your build will be usable for me.

For wininc,no thanks,too much limited
For  HBITMAP, HWND ... perhaps I could arrange this
Title: Re: problem building a 64 bits executable
Post by: habran on December 14, 2014, 06:38:09 AM
This build is tailored for you my friend
RIP and AVX2 are also included
I hope you'll live happily ever after :biggrin:
Title: Re: problem building a 64 bits executable
Post by: TouEnMasm on December 14, 2014, 07:16:37 PM
Thanks,
This solve the general failure.
After further tests,i need to erase the .pdb .
I have not find yet where it is open in the source code.
The obj file is erased by fopen "w."
Perhaps the .pdb isn't erase ?.
I have visual studio community 2013 and no problem with the build of the source code.
Title: Re: problem building a 64 bits executable
Post by: habran on December 14, 2014, 07:39:06 PM
Does that mean that you are satisfied? :biggrin:
Title: Re: problem building a 64 bits executable
Post by: TouEnMasm on December 14, 2014, 07:57:15 PM

I am satisfied but .. if you can help me on how erase the .pdb before compile,I get your goods advises.
Title: Re: problem building a 64 bits executable
Post by: habran on December 14, 2014, 08:09:02 PM
Did you try to chose Rebuild Solution or Clean Solution from Build menu?
Title: Re: problem building a 64 bits executable
Post by: TouEnMasm on December 15, 2014, 06:09:18 AM
 :t
rebuild and all is OK,it's just Magic.
thanks
Title: Re: problem building a 64 bits executable
Post by: habran on December 15, 2014, 06:18:21 AM
That was my Christmas present to you :lol:
now I can sleep peacefully 8)