### Author Topic: Linux and LIBC  (Read 975 times)

#### nidud

• Member
• Posts: 1565
##### Linux and LIBC
« on: June 19, 2017, 02:25:10 AM »
I've added _LINUX and _WIN64 to switch -elf, -elf64, and -win64

-elf --> _LINUX = 1
-elf64 --> _LINUX = 2 + _WIN64 = 1
-win64 --> _WIN64 = 1

libc.inc use SYSCALL if elf is defined.
Code: [Select]
`ifdef _LINUX_CType equ <syscall>_CDecl equ <syscall>__cdecl equ <syscall>`
This enables use of the include files for LIBC functions.

Test case used for 64-bit:
Code: [Select]
`include stdio.inc    .codemain proc argc:SINT, argv:ptr    .for r12d=argc, r13=argv, ebx=0: r12d: r12d--, ebx++, r13+=size_t            printf("[%d]: %s\n", ebx, [r13])    .endf    xor eax,eax    retmain endp    end`
Output:
Code: [Select]
`nidud@nidud-VB ~/asmc \$ ./asmc -q -Iinclude -elf64 arg64.asmnidud@nidud-VB ~/asmc \$ gcc -o arg64 arg64.onidud@nidud-VB ~/asmc \$ ./arg64 1 2 3[0]: ./arg64[1]: 1[2]: 2[3]: 3`
Test case used for 32-bit:
Code: [Select]
`include stdio.inc    .codemain proc argc:SINT, argv:ptr    .for ebx=argc, esi=argv, edi=0: ebx: ebx--, edi++, esi+=size_t     printf("[%d]: %s\n", edi, [esi])    .endf    xor eax,eax    retmain endp    end`
Output:
Code: [Select]
`nidud@nidud-VB ~ \$ cd asmcnidud@nidud-VB ~/asmc \$ ./asmc -elf -Iinclude arg32.asmAsmc Macro Assembler Version 2.24Portions Copyright (c) 1992-2002 Sybase, Inc. All Rights Reserved. Assembling: arg32.asmnidud@nidud-VB ~/asmc \$ gcc arg32.o -o arg32nidud@nidud-VB ~/asmc \$ ./arg32[0]: ./arg32nidud@nidud-VB ~/asmc \$ ./arg32 1 2 3[0]: ./arg32[1]: 1[2]: 2[3]: 3`
I also changed the default size of indirect addressing using register in 64-bit. This was 4 but now 8. This effect :VARARG arguments using -elf64 and -win64.
Code: [Select]
`     printf("[%d]: %s\n", ebx, [r13])`

#### Greenhorn

• Member
• Posts: 98
##### Re: Linux and LIBC
« Reply #1 on: April 04, 2018, 06:01:24 AM »
Hi nidud,

I'm trying to get ASMC working for me, but it throws an error "A2005: symbol redefinition : _WIN64".
After removing the switch /D"_WIN64" from command line and quoted out the one and only conditional definition of _WIN64 in my header files, I still get that error. Now I'm at a loss about that and don't know what to do to get it working.

In my opinion the definition of such macros shoul be the responsibility of the toolset where it is needed. In this case the windows header files or it should be the programmer's responsibility.

However, keep on the good work on ASMC.

Kind Regards
Greenhorn

#### nidud

• Member
• Posts: 1565
##### Re: Linux and LIBC
« Reply #2 on: April 04, 2018, 06:38:08 AM »
I ended up writing quite a few of these command lines:
asmc -q -win64 -D_WIN64 -ws -D_UNICODE \$*.asm

So the logic here is:
-win64 defines _WIN64
-ws defines _UNICODE
-elf defines _LINUX=1
-elf64 defines _LINUX=2

However, the first version created a problem if the symbol was already defined. This is fixed in later versions so the Linux version needs an update. The development is currently done in assembler so the C source to build an updated version is currently missing.

EDIT:
« Last Edit: April 04, 2018, 10:14:27 AM by nidud »

#### Greenhorn

• Member
• Posts: 98
##### Re: Linux and LIBC
« Reply #3 on: April 05, 2018, 04:29:24 AM »
Hi,

The problem occurs with using Windows. I've got ASMC working with Visual Studio 2010.

Command line is:
Code: [Select]
`asmc.exe /c -win64 -Zp8 /nologo /ws /Sg /Zi /Fo"x64\Debug\%(FileName).obj" /D"WIN32" /D"_DEBUG" /D"_WINDOWS" /D"_UNICODE" /D"UNICODE" /Fl"x64\Debug\%(Filename).lst" /I"D:\Win7Inc\include" /Cp /W2 /win64 /Zp8`
The only possible definition of _WIN64 is in Winasm.inc (originally from Japhet's WinInc files).
So I've quoted out:
Code: [Select]
`ifndef _WIN64if near eq 0ff08h   ;64-bit enabled?;_WIN64 equ <>endifendif`
Seems that I'm too stupid. Cannot find the error. Searched all files for _WIN64 ... *sigh*

Regards

#### Greenhorn

• Member
• Posts: 98
##### Re: Linux and LIBC
« Reply #4 on: April 05, 2018, 04:38:30 AM »
Sorry, and yes, I'm definitely too stupid !

The command line contains: -win64 and -Zp8, which is doubled defined in command line. But it's not generated by Visual Studio. VS uses "/" and not "-" as switch prefix. So this is also generated by ASMC ?

Now I'm a little bit confused, but at first I'll go and rubbing the tomatoes out of my eyes ...

Edit:
Mmmh, "-win64 -Zp8" appears in project settings command line, so ... mmh.

Edit:
Aaargh, got it. I've modified Japhet's VS2010 Cunstom Build Rule files to create the ASMC build files. Japhet predefind in *.props file -win64 -Zp8 for x64 build.

Sorry for stealing your time, nidud.

#### nidud

• Member
• Posts: 1565
##### Re: Linux and LIBC
« Reply #5 on: April 05, 2018, 06:18:36 AM »
You posted under Linux and LIBC so I assumed Linux.

Not sure what to add here other than whats already said except to give a few examples on how it works. All the samples below works:

asmc -win64 test.asm
asmc -win64 -D_WIN64 test.asm
asmc -win64 -D"_WIN64" test.asm
Code: [Select]
`    .codeifdef _WIN64    mov al,1endif    end`
Same with this code:
Code: [Select]
`_WIN64 equ <>    .codeifdef _WIN64    mov al,1endif    end`
This however ends with a fatal error:
asmc /c -win64 -Zp8 /nologo /ws /Sg /Zi /D"WIN32" /D"_DEBUG" /D"_WINDOWS" /D"_UNICODE" /D"UNICODE" /Fl /Cp /W2 /win64 /Zp8 test.asm

ASMC : fatal error A1901: Internal Assembler Error

The reason is the second (or first) definition of -win64. Bit tricky that switch so there can be only on of them.

Quote
The only possible definition of _WIN64 is in Winasm.inc (originally from Japhet's WinInc files).
Doesn't really matter but _WIN64 should not be defined inside any of the windows include files but the IF NEAR thing is clever thought. Asmc also comes with a full set of Windows include files.

Quote
The command line contains: -win64 and -Zp8, which is doubled defined in command line. But it's not generated by Visual Studio. VS uses "/" and not "-" as switch prefix. So this is also generated by ASMC ?
Not sure I understand the question. Asmc do not interact with Visual Studio so if you have any problems with VS you should direct your questions to Microsoft.

#### nidud

• Member
• Posts: 1565
##### Re: Linux and LIBC
« Reply #6 on: April 05, 2018, 06:58:07 AM »
Sorry for stealing your time, nidud.

Well, the Linux version got a face-lift so I guess some good came out of it.