Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
987 views
in Technique[技术] by (71.8m points)

linux - Cygwin: Compatibility Issue

Hello StackOverFlowers!

I'm extremely new to the whole linux thing and I'm using Cygwin to try to do the following..

Put a test file through a parser...

./parser < test.c > test.asm //Works and generates ASM code

Do this line as described in the tutorial which I'm not sure exactly what it does...

nasm -f elf test.asm //Works

And finally this line to create the exectuable(If I am understanding the tutorial correctly)

ld -s -o test test.o

I'm getting an error of ld: i386 architecture of input file test.o' is incompatible with i386:x86-64 output on this line. I know it's because I'm trying to go from a 32-bit to a 64-bit, but I can't figure out how to combat this. I've tried using elf_i386, but I get ld: unrecognised emulation mode: elf_i386. Supported emulations: i386pep i386pe.

Any and all suggestions are much appreciated!!

EDIT:

Test.asm file

section .data
numbers db "0123456789", 0xA
inputchar db 0
section .text
global F_124565444
F_124565444:
push    ebp
mov ebp, esp
sub esp, 4
mov dword [ebp-4], 0
jmp G2
G1:
add dword [ebp-4], 1
push edx
G2:
mov edx, 0
mov eax, [ebp+8]
mov ebx, 10
div ebx
mov [ebp+8], eax
cmp eax, 0
jnz G1
push edx
add dword [ebp-4], 1
jmp G3
G4:
sub dword [ebp-4], 1
pop edx
mov eax, 4
mov ebx, 1
mov ecx, numbers
add ecx, edx
mov edx, 1
int 80h
G3:
cmp dword [ebp-4], 0
jnz G4
mov eax, 4
mov ebx, 1
lea ecx, [numbers+10]
mov edx, 1
int 80h
leave
ret
global F_7362500
F_7362500:
push    ebp
mov ebp, esp
sub esp, 4
mov dword [ebp-4], 0
mov byte [inputchar], 0
jmp G6
G5:
mov dword eax, [ebp-4]
mov ebx, 10
mul ebx
xor ecx, ecx
mov byte cl, [inputchar]
sub ecx, 48
add eax, ecx
mov dword [ebp-4], eax
G6:
mov eax, 03h
mov ebx, 00h
mov ecx, inputchar
mov edx, 01h
int 80h
cmp byte [inputchar], 0ah
jne G5
mov dword eax, [ebp-4]
leave
ret
global F_28052
F_28052:
push    ebp
mov ebp, esp
push    dword [ebp+8]
push    dword 0
pop ebx
pop eax
cmp eax, ebx
sete    al
movzx   eax, al
push    dword eax
pop eax
cmp eax, 0
je  L1
push    dword [ebp+12]
pop eax
leave
ret
jmp L2
L1:
push    dword [ebp+8]
push    dword [ebp+12]
push    dword [ebp+12]
push    dword [ebp+8]
pop ebx
pop eax
mov edx, eax
sar edx, 31
idiv    ebx
push    dword eax
push    dword [ebp+8]
pop ebx
pop eax
imul    eax, ebx
push    dword eax
pop ebx
pop eax
sub eax, ebx
push    dword eax
call    F_28052
add esp, 8
push    dword eax
pop eax
leave
ret
L2:
leave
ret
global _start
_start:
push    ebp
mov ebp, esp
sub esp, 4
sub esp, 4
call    F_7362500
add esp, 0
push    dword eax
lea ebx, [ebp-4]
pop eax
mov dword [ebx], eax
call    F_7362500
add esp, 0
push    dword eax
lea ebx, [ebp-8]
pop eax
mov dword [ebx], eax
push    dword [ebp-4]
push    dword [ebp-8]
call    F_28052
add esp, 8
push    dword eax
call    F_124565444
add esp, 8
push    dword 0
pop eax
leave
mov ebx, eax
mov eax,1
int 80h
leave
mov ebx, eax
mov eax,1
int 80h
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

It appears from your question and comments that you may have been lead to believe that Cygwin was the same as Linux. That isn't the case. Cygwin is a unix-like posix compatible environment that runs natively on Windows:

Cygwin is a Unix-like environment and command-line interface for Microsoft Windows. Cygwin provides native integration of Windows-based applications, data, and other system resources with applications, software tools, and data of the Unix-like environment. Thus it is possible to launch Windows applications from the Cygwin environment, as well as to use Cygwin tools and applications within the Windows operating context.

In particular all the Linux specific code that uses int 80h system call will fail when run on Windows, as it doesn't apply to the Windows environment.

If you want to create code that runs on Linux, then you'll need to install Linux. You can do that by running Virtual Machine software on Windows and install a flavor of Linux into it (Ubuntu is the choice for a lot of people).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...