delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/02/17/13:11:47

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
To: cygwin AT cygwin DOT com
From: "Krzysztof Duleba" <krzysan AT skrzynka DOT pl>
Subject: Re: Assembler
Date: Tue, 17 Feb 2004 19:16:22 +0100
Lines: 72
Message-ID: <c0tlgg$vbu$1@sea.gmane.org>
References: <AE2AA130827456459AA497E8C9D6EA00412BF3 AT pauex2ku02 DOT agere DOT com>
Mime-Version: 1.0
X-Complaints-To: usenet AT sea DOT gmane DOT org
X-Gmane-NNTP-Posting-Host: fw-gw-atm.mimuw.edu.pl
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158

Williams, Gerald S (Jerry) wrote:

>> I wanted to test some of my linux assembler code on my
>> Windows-Cygwin box.
>> Is it possible at all?

> I don't know about using BIOS calls, etc., but I've
> assembled and linked a few NASM assembly functions.

What about Linux syscalls? Will Cygwin emulation layer match it? On the
Linux box that I used to work, there was a big /usr/inlude/asm directory. My
Cygwin /usr/include/asm contains only three files (byteorder.h socket.h
types.h). Does it have anything to do?

> I didn't use ELF format, though. There's a gnuwin32
> format that works with Cygwin.

And that's why ld produced corrupted executable. Thanks - with gnuwin32 at
least I get a proper binary.

> I've only ever linked them as functions called via
> the C environment, but if you take the following:

It works fine, thank you.

With gnuwin32 I get:

bash-2.05b$ nasm -f gnuwin32 hello.asm
bash-2.05b$ gcc hello.o -o hello.exe
/usr/lib/gcc-lib/i686-pc-cygwin/3.3.1/../../../libcygwin.a(libcmain.o)(.text
+0x7c):
 undefined reference to `_WinMain AT 16'
collect2: ld returned 1 exit status
bash-2.05b$ ld hello.o -o hello.exe
ld: warning: cannot find entry symbol _mainCRTStartup; defaulting to
00401000
bash-2.05b$ ./hello
bash-2.05b$

So I changed _start function name to _main:

bash-2.05b$ cat hello.asm
section .data
        t       db      'Hello world',0
        len     equ     13
section .text

global _main
_main: mov edx,len
        mov ecx,t
        mov ebx,1
        mov eax,4
        int 0x80
        mov ebx,0
        mov eax,1
        int 0x80

bash-2.05b$ nasm -f gnuwin32 hello.asm
bash-2.05b$ ld hello.o -o hello.exe
ld: warning: cannot find entry symbol _mainCRTStartup; defaulting to
00401000
bash-2.05b$ ./hello.exe
bash-2.05b$ gcc hello.o -o hello.exe
bash-2.05b$ ./hello.exe
Segmentation fault (core dumped)


Is there a way I could force Cygwin's ld to work the way Linux ld used to?

Regards
Krzysztof Duleba



--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019