delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2019/04/26/07:16:57

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:reply-to:subject:to:references:from:message-id
:date:mime-version:in-reply-to:content-type
:content-transfer-encoding; q=dns; s=default; b=BuzekLKKhyel6R1L
eBFHBRLzrklQVTTOCsOtsccDcVlRGWOVJeLjRYh6UR2Anq6DLq1ovqWPYCyf9XHP
3Kq+xnS2Fu18rLhMvCf7VlXMZ4oMORTNmzNcvBnchjtsgksJbRYejy7YtC6blk1J
BNmbhsloFXBdu3buiR/PiI+JPSQ=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:reply-to:subject:to:references:from:message-id
:date:mime-version:in-reply-to:content-type
:content-transfer-encoding; s=default; bh=qWtW3OwyWoGjm4OUoXUR74
ZZwr4=; b=XvQaBX4pe0epbngHJvLK19KqXdfAZkfy6P7YaXPMX9vgcQO33EOkk4
jnpk/TCf0sfGUZ5gtJchbK0aLKLMSYboC1f5yoUNHbZUZVCj4bzdK/9JNJhBycPS
RIiQ6QhiUx/C+4v/PtFRYPYqB0hGqJOTI+MoamkuQNuFkEcsy7Bi4=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/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
Authentication-Results: sourceware.org; auth=none
X-Spam-SWARE-Status: No, score=-1.1 required=5.0 tests=AWL,BAYES_00,SPF_PASS autolearn=ham version=3.3.1 spammy=extent, Thompson, thompson, specifics
X-HELO: mailsrv.cs.umass.edu
Reply-To: moss AT cs DOT umass DOT edu
Subject: Re: Request for an example x68 assembler portable Hello World script
To: cygwin AT cygwin DOT com
References: <CA+wh7Kg4UAO+_ZBONXbJ=3Hf9Tz6LSX2DX+LQNPLYqty4wkTag AT mail DOT gmail DOT com>
From: Eliot Moss <moss AT cs DOT umass DOT edu>
Message-ID: <a0a83284-2869-bf15-01fd-8585105d117a@cs.umass.edu>
Date: Fri, 26 Apr 2019 07:16:38 -0400
User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.6.1
MIME-Version: 1.0
In-Reply-To: <CA+wh7Kg4UAO+_ZBONXbJ=3Hf9Tz6LSX2DX+LQNPLYqty4wkTag@mail.gmail.com>
X-IsSubscribed: yes

On 4/26/2019 3:25 AM, Jesse Thompson wrote:
> I would like to learn how to write assembly programs for the command line
> that with as little alteration as is feasable will compile both in Cygwin
> and in other flavors of Unix like Linux and/or FreeBSD.
> 
> I am targeting only x64 CPUs and I'm perfectly happy to use libc calls
> instead of direct syscalls or interrupts. I'm hoping to use nasm+gcc, or
> perhaps fasm to do the deed. Crosspiling is not a concern, I'll build
> cygwin binaries in cygwin and unix binaries in unix.
> 
> But I'm confused by the differences in calling convention/ABI between
> Windows and/or Cygwin and Linux?
> 
> For example, I can get this to compile and run in Cygwin:
> 
> ```
>          global  main
>          extern  puts
>          section .text
> main:
>          sub     rsp, 20h                        ; Reserve the shadow space
>          mov     rcx, message                    ; First argument is address
> of message
>          call    puts                            ; puts(message)
>          add     rsp, 20h                        ; Remove shadow space
>          ret
> message:
>          db      'Hello', 0                      ; C strings need a zero
> byte at the end
> ```
> 
> 
> but it segfaults in Linux (and complains about "Symbol `puts' causes
> overflow in R_X86_64_PC32 relocation")
> 
> and I can get the following to compile and run in Linux:
> ```
>      extern puts
>      global main
> 
> section .text
> main:
>      mov rdi,message
>      call puts
>      ret
> 
> message:
>      db  "Hello World",0
> ```
> 
> but *that* segfaults in cygwin.
> 
> TL;DR: I think I could get a lot more done if I could start from a single
> Hello World asm file that can compile and run in both places, calling out
> to puts or something simple like that.
> 
> Any help would be appreciated, I hope everything about my question makes
> sense. :)

Der Jesse -- Someone else may be able to speak to the specifics, but
register use and calling conventions, and to some extent stack layout,
very from platform to platform.  Roughly, platform = processor + OS.
So (to me anyway) it would not be at all surprising if you have to
write code different for each of Windows, Cygwin, and Linux.  Cygwin
tries to offer library level compatibility for program designed to
run under Posix (there are some seams here and there, where Windows
differences are hard to hide).  But the programs have to be recompiled
to the Cygwin ABI.

Another thing you may be encountering is the difference between the
32-bit and 64-bit worlds.  Recent x86 processor support the x86_64
version as well.  Cygwin offers both 32 and 64 bit versions, but they
are distinct, and a program needs to be compiled to the one under
which you wish to run it.  (I have both 32 and 64 bit Cygwin on my
computer, and the programs can invoke one another, but the installations
need to be in separate file hierarchies.)  The same would tend to hold
under Linux and Windows, though the OS can determine automatically
for a given program whether it is 32 or 64 bit from details of the
first bytes of the executable file.

Regards - EM

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

- Raw text -


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