delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2019/04/26/03:25:43

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:mime-version:from:date:message-id:subject:to
:content-type; q=dns; s=default; b=kA0pFlU+1AqybcBbqdTPk0lq8Mj+X
Eyfoa+rjAc68f3+aViyZS5wB/WJtxAQYOdnnyHcAQcSNbigsNrvcf4c7cKlhqhDB
0zzjYL2qEozargqWZcGzl35Q8flaLHbydIsXF91ZAMQteB69VSIybSQeSy/oEVoa
3Fa0eKhGneE0M0=
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:mime-version:from:date:message-id:subject:to
:content-type; s=default; bh=9pzob27R2eTmTrpiye9vvDwsTu4=; b=e/F
05f5JSxv9hYhh5Q9ZHSdB9NOnH8QDVsenpjrpPgm1qiZluCBzlmdVjdSpgPie3XD
Q8WNSrr02FtgwmFuJVadgJxsj172EObxhL+jz5psUXhzQfKSeoGhqJVgcSzsoEwU
wREgwsByalWwUfMhj7YJ9DBlDhd5iiCz6tziI1/Q=
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=-2.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.1 spammy=deed, HX-Languages-Length:3337, H*c:alternative, learn
X-HELO: mail-it1-f171.google.com
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=E/1eVRPP8DCcswOTErVx9S43m4gjxW3iBJTckIfuEBc=; b=AGhopem/+aKP7AKE53RM2+a3zneoA3WgP5VYkA5g8hN7f/NMaqFoxmJsSCCsxDZwwJ 2IWJXnIhGl+/fyWJf5csN0PzUjdxvLi8Y67MdjAr5vxJiemiDHGKHwGatMoJU7GtMqXj D8uXZuQpxgynhdv9rdNwvKjiH3Dpv8p0oP5wo7g3YFEX/e+qlo7WLlhTlZfVeuLaaDhe RZEi22BQeq0Tyc+0kgRcHn8ragWTe8D4XlUDj0WehZT6bDDWXBFTFfD+np3XwpxZNmSd +B1EWexN/ResAyRAvLHQq0IA6nE+Ex4tt40sVZxNxTyQ1c2FWuOTAKPjEBiR8GGrmlv6 JWqA==
MIME-Version: 1.0
From: Jesse Thompson <jesset AT gmail DOT com>
Date: Fri, 26 Apr 2019 00:25:12 -0700
Message-ID: <CA+wh7Kg4UAO+_ZBONXbJ=3Hf9Tz6LSX2DX+LQNPLYqty4wkTag@mail.gmail.com>
Subject: Request for an example x68 assembler portable Hello World script
To: cygwin AT cygwin DOT com

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. :)

- - Jesse

--
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