using JWasm with mingw headers and libs (?)

Started by SteveAsm, October 27, 2011, 02:40:09 PM

Previous topic - Next topic

Vortex

Hi SteveAsm,

lib2def can convert a MinGW import library to a module definition file :


lib2def.exe libkernel32.a

ren libkernel32.def kernel32.def

Vortex

QuoteWhy mentioning the use of MINGW libs at all then? PellesC package has its own lib files.

Hi drizz,

You are right but it has been asked to use \ convert MinGW import libraries. The MinGW package provides more libraries and they can be converted to MS \ Pelles C import libraries.

drizz

Quote from: Vortex on October 27, 2011, 07:55:24 PMYou are right but it has been asked to use \ convert MinGW import libraries.
And I have been telling constantly that jwasm does not use libraries.
The truth cannot be learned ... it can only be recognized.

SteveAsm

Quote from: drizz on October 27, 2011, 08:11:42 PM
And I have been telling constantly that jwasm does not use libraries.

Huh.
Can someone confirm that ?
I didn't see that written down anywhere.

steve

SteveAsm

Quote from: Vortex on October 27, 2011, 07:51:20 PM
lib2def can convert a MinGW import library to a module definition file :

Hey thanks for the link Vortex.
This could come in quite handy.

steve

SteveAsm

Quote from: jcfuller on October 27, 2011, 07:18:13 PM
I just assumed MinGW was elf format on Windows?

These are the two batch files I am using with jwasm and MinGW.

So James,
you are using them both (Include and Lib files) right out of the box ?
Without any conversion ?

That is to say: *.h and *.a .
For use with jwasm, it appear that they would need to be converted to *.inc and *.lib.
That is the question.

dedndave

Steve,
when you use
        INCLUDE    \masm32\include\kernel32.inc
it adds additional lines to the assembly source

when you use
        INCLUDELIB \masm32\lib\kernel32.lib
it tells the assembler where to resolve external references
however, this is really telling the linker (via the OBJ file), where to resolve external references

drizz

Quote from: SteveAsm on October 27, 2011, 09:05:17 PM
Quote from: drizz on October 27, 2011, 08:11:42 PM
And I have been telling constantly that jwasm does not use libraries.

Huh.
Can someone confirm that ?
I didn't see that written down anywhere.

steve

INCLUDELIB
http://msdn.microsoft.com/en-us/library/e0x6w856(v=vs.80).aspx
QuoteInforms the linker that the current module should be linked with libraryname.

The "includelib" directive just adds a "-defaultlib" command for the linker
If you do a "link /dump /all myfile.obj" and myfile contains "includelib" lines you will see something like:
SECTION HEADER #4
.drectve name
      D0 physical address
       0 virtual address
      3D size of raw data
     1AD file pointer to raw data (000001AD to 000001E9)
       0 file pointer to relocation table
       0 file pointer to line numbers
       0 number of relocations
       0 number of line numbers
     A00 flags
         Info
         Remove
         (no align specified)

RAW DATA #4
  00000000: 2D 64 65 66 61 75 6C 74 6C 69 62 3A 6B 65 72 6E  -defaultlib:kern
  00000010: 65 6C 33 32 2E 6C 69 62 20 2D 64 65 66 61 75 6C  el32.lib -defaul
  00000020: 74 6C 69 62 3A 75 73 65 72 33 32 2E 6C 69 62 20  tlib:user32.lib
  00000030: 2D 65 6E 74 72 79 3A 73 74 61 72 74 20           -entry:start

   Linker Directives
   -----------------
   -defaultlib:kernel32.lib
   -defaultlib:user32.lib
   -entry:start


jwasm/ml does not need includelib lines to compile .asm source!
You can merrily specify the needed libs only on the linker command line.
hint: see jcfullers "@ld" batch  line.

The truth cannot be learned ... it can only be recognized.

drizz

Heres a step by step example:

download and unpack WinInc
mine is in dir=D:\WININC

download and install mingw, I chose TDM-GCC-MINGW64 (http://tdm-gcc.tdragon.net/download)
mine is indir=D:\MINGW64

download and unpack latest JWASM
put JWASM.EXE to
dir=D:\MINGW64\bin

put Win32_1.asm form JWASM zip to a folder of your choice.
dir=D:\Temp

optional: put MINGW\bin dir on the path so you don't have to use paths on the command line.

Example 1

step1, assemble:
D:\MINGW64\jwasm -c -coff -nologo Win32_1.asm

result:
Win32_1.asm: 45 lines, 2 passes, 0 ms, 0 warnings, 0 errors

step 2, link:
d:\MinGW64\bin\ld -m i386pe -s -o Win32_1.exe --entry mainCRTStartup --subsystem console Win32_1.obj -L"d:\MinGW64\x86_64-w64-mingw32\lib32" -lkernel32

result:
Warning: .drectve `-entry:ainCRTStartup ' unrecognized

step 3, run:
Win32_1.exe

result:
hello, world.


Another example: WinXX_1.asm as 32 bit

D:\MINGW64\bin\jwasm -c -coff -nologo -I"d:\WinInc\Include" WinXX_1.asm
d:\MinGW64\bin\ld -m i386pe -s -o WinXX_1.exe --entry _mainCRTStartup@0 --subsystem console WinXX_1.obj -L"d:\MinGW64\x86_64-w64-mingw32\lib32" -lkernel32

Another example: WinXX_1.asm as 64 bit

D:\MINGW64\bin\jwasm -c -win64 -nologo -I"d:\WinInc\Include" WinXX_1.asm
d:\MinGW64\bin\ld -m i386pep -s -o WinXX_1.AMD64.exe --entry mainCRTStartup --subsystem console WinXX_1.obj -L"d:\MinGW64\x86_64-w64-mingw32\lib" -lkernel32
The truth cannot be learned ... it can only be recognized.

SteveAsm

Quote from: dedndave on October 27, 2011, 09:59:34 PM
when you use
        INCLUDE    \masm32\include\kernel32.inc
it adds additional lines to the assembly source

when you use
        INCLUDELIB \masm32\lib\kernel32.lib
it tells the assembler where to resolve external references
however, this is really telling the linker (via the OBJ file), where to resolve external references

I understand this completely and I have no issue with this.
That was never a part of the question.

SteveAsm

Quote from: drizz on October 27, 2011, 10:53:00 PM
And I have been telling constantly that jwasm does not use libraries.

Drizz, perhaps you misunderstood my intent.
When I used the term "JWasm" it was in a generic fashion.
As in, the JWasm assembler package.

I wasn't asking how to make JWasm.exe use library files, it was more about using ".lib" versus ".a" files with the JWasm assembler package.
Your respones that:
QuoteAnd I have been telling constantly that jwasm does not use libraries.
in the present context, can only cause confusion.
It implied that, no, you cannot use libraries with the JWasm package.
Which of course is not correct.

In the present company, I didn't think I need to be so specific as to have to specify jwlink.exe.

Sincerely

edit:
Drizz, thanks for your detailed explaination.
I have Masm32 (package) installed (as I have for many years now),
I have mingw (package) installed (as I have for many years now),
i recently installed JWasm (package).
I have been using Masm32 for many years, as well as mingw.

This is only about what from mingw can I use in conjuction with jwasm.

BTW:
Quotehint: see jcfullers "@ld" batch  line.
I understand that James is linking with the mingw linker, as opposed to using the jwlink linker.
That is not my aim.

Thanks  :U

jcfuller

drizz, (or others)

  elf vs coff  opinions

James

drizz

Quote from: SteveAsm on October 28, 2011, 12:06:29 AM
Drizz, perhaps you misunderstood my intent.
When I used the term "JWasm" it was in a generic fashion.
As in, the JWasm assembler package.

I wasn't asking how to make JWasm.exe use library files, it was more about using ".lib" versus ".a" files with the JWasm assembler package.
Your respones that:
QuoteAnd I have been telling constantly that jwasm does not use libraries.
in the present context, can only cause confusion.
It implied that, no, you cannot use libraries with the JWasm package.
Which of course is not correct.

In the present company, I didn't think I need to be so specific as to have to specify jwlink.exe.

I went to japheth's site  and I can't find "JWasm assembler package", care to point where it is?
I can only find : JWasm207bw.zip, WinInc202.zip, JWlinkbw.zip which are all separate packages.


Btw, open watcom package also has win32 os libraries. I can't comment on the OW tools as I have never used them (including the modified linker from japheth), my guess is that the modified linker would work great with its originating package.

Also, since jwlink supports:
OMF the standard Intel Object Module Format, including Microsoft's 32-bit extensions
COFF both 32-bit and 64-bit variants of this format
ELF both 32-bit and 64-bit variants of this format
OMF-386 Phar Lap's 32-bit OMF variant (Easy OMF)
OMF library format
AR object library format (Microsoft, GNU or BSD compatible)

then, I think you can use anything you want, install the "Windows SDK" and use that.

The truth cannot be learned ... it can only be recognized.

drizz

Quote from: jcfuller on October 28, 2011, 12:09:49 AM
drizz, (or others)

  elf vs coff  opinions

James


If you mean "as jwasm.exe output format for mingw linker", my preference is to use the same format for input and output.
The truth cannot be learned ... it can only be recognized.

jcfuller

Steve,
  I am using the WinInc files with no changes to the library files.

Using this source:

.686
.XMM
.model flat,stdcall
option casemap:none
include c:\jwasm\include\windows.inc

;includelib kernel32.lib
;includelib user32.lib
;includelib gdi32.lib

.data?
   hInstance HINSTANCE ?
   CommandLine LPSTR ?
   
.data
   ClassName TCHAR "MainWinClass",0
   AppName TCHAR "FirstWindow",0

.code

; ---------------------------------------------------------------------------

start:
invoke GetModuleHandle, NULL
mov    hInstance,eax

invoke GetCommandLine
mov    CommandLine,eax

invoke WinMain, hInstance,NULL,CommandLine, SW_SHOWDEFAULT
invoke ExitProcess,eax

WinMain proc hInst:HINSTANCE,hPrevInst:HINSTANCE,CmdLine:LPSTR,CmdShow:DWORD
LOCAL wc:WNDCLASSEX
LOCAL msg:MSG
LOCAL hwnd:HWND

mov   wc.cbSize,SIZEOF WNDCLASSEX
mov   wc.style, CS_HREDRAW or CS_VREDRAW
mov   wc.lpfnWndProc, OFFSET WndProc
mov   wc.cbClsExtra,0
mov   wc.cbWndExtra,0
push  hInstance
pop   wc.hInstance
invoke GetStockObject,WHITE_BRUSH
mov   wc.hbrBackground,EAX
mov   wc.lpszMenuName,NULL
mov   wc.lpszClassName,OFFSET ClassName
invoke LoadIcon,NULL,IDI_APPLICATION
mov   wc.hIcon,eax
mov   wc.hIconSm,eax

invoke LoadCursor,NULL,IDC_ARROW
mov   wc.hCursor,eax

invoke RegisterClassEx, addr wc

invoke CreateWindowEx,
   NULL,
   ADDR ClassName,
   ADDR AppName,
           WS_OVERLAPPEDWINDOW,
           CW_USEDEFAULT,
           CW_USEDEFAULT,
           CW_USEDEFAULT,
           CW_USEDEFAULT,
           NULL,
           NULL,
           hInst,
           NULL

mov   hwnd,eax

invoke ShowWindow, hwnd,SW_SHOWNORMAL
invoke UpdateWindow, hwnd

.while TRUE
invoke GetMessage, ADDR msg,NULL,0,0
.BREAK .if (!eax)
invoke TranslateMessage, ADDR msg
invoke DispatchMessage, ADDR msg
.endw

mov     eax,msg.wParam
ret
WinMain endp

WndProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

LOCAL hdc:HDC
LOCAL ps:PAINTSTRUCT

.if uMsg==WM_DESTROY
invoke PostQuitMessage,0

.elseif uMsg==WM_CREATE

.elseif uMsg == WM_PAINT
invoke BeginPaint, [hWnd], addr ps
mov  [hdc], EAX
invoke EndPaint, [hWnd],addr ps

.elseif uMsg == WM_SIZE

.else
invoke DefWindowProc, hWnd, uMsg, wParam, lParam
ret
.endif

xor eax,eax
ret
WndProc endp


end start



and the batch files I posted all is fine.

If I change to coff format

jwasm -coff %1.asm
ld --format pe-i386  --subsystem windows -s -o %1.exe %1.obj -L%LIB% -lmingw32
-lmsvcrt -lkernel32 -luser32 -lgdi32 -lcomctl32 -ladvapi32 -lwinspool -lshell32 -lole32
-loleaut32 -luuid -lodbc32 -lodbccp32 -lwinmm -lcomdlg32 -limagehlp -lversion


I receive a warning: Warning: .drectve `-entry:start ' unrecognized

I am a real novice at this especially on windows as all my early jwasm testing was on Linux

James






Quote from: SteveAsm on October 27, 2011, 09:13:17 PM
Quote from: jcfuller on October 27, 2011, 07:18:13 PM
I just assumed MinGW was elf format on Windows?

These are the two batch files I am using with jwasm and MinGW.

So James,
you are using them both (Include and Lib files) right out of the box ?
Without any conversion ?

That is to say: *.h and *.a .
For use with jwasm, it appear that they would need to be converted to *.inc and *.lib.
That is the question.