Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"God is a comedian playing to an audience too afraid to laugh." -- Voltaire


computers / comp.os.vms / Re: How to write "Hello, world" in x86 assembly (llvm-mc)?

Re: How to write "Hello, world" in x86 assembly (llvm-mc)?

<511fa7b5-728f-4b6d-b3ac-25e8d33f8969n@googlegroups.com>

  copy mid

https://www.novabbs.com/computers/article-flat.php?id=31042&group=comp.os.vms#31042

  copy link   Newsgroups: comp.os.vms
X-Received: by 2002:a05:620a:404e:b0:76f:109e:e244 with SMTP id i14-20020a05620a404e00b0076f109ee244mr642332qko.5.1699385639791;
Tue, 07 Nov 2023 11:33:59 -0800 (PST)
X-Received: by 2002:a05:6870:788:b0:1d5:8e96:7d85 with SMTP id
en8-20020a056870078800b001d58e967d85mr1761701oab.1.1699385639362; Tue, 07 Nov
2023 11:33:59 -0800 (PST)
Path: i2pn2.org!i2pn.org!news.neodome.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer02.ams4!peer.am4.highwinds-media.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.os.vms
Date: Tue, 7 Nov 2023 11:33:58 -0800 (PST)
In-Reply-To: <uie160$14tpr$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2600:1700:46b0:abc0:2d21:2f25:27d3:d24d;
posting-account=OGFVHQoAAAASiNAamRQec8BtkuXxYFnQ
NNTP-Posting-Host: 2600:1700:46b0:abc0:2d21:2f25:27d3:d24d
References: <60f6d6cf-92aa-4de0-9e39-a95ab630324en@googlegroups.com> <uie160$14tpr$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <511fa7b5-728f-4b6d-b3ac-25e8d33f8969n@googlegroups.com>
Subject: Re: How to write "Hello, world" in x86 assembly (llvm-mc)?
From: jake.ha...@gmail.com (Jake Hamby (Solid State Jake))
Injection-Date: Tue, 07 Nov 2023 19:33:59 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 17947
 by: Jake Hamby (Solid St - Tue, 7 Nov 2023 19:33 UTC

On Tuesday, November 7, 2023 at 10:55:01 AM UTC-8, Simon Clubley wrote:
> >
> The clues might be elsewhere.
>
> Generate a linker memory map and see if there are any clues in there.
>
> Look to see what the entry point is in both cases and if there's
> something that should be getting called before your entry point.
>
> You may need to do something with the linker command.
>
> Try posting your _exact_ linker and assembly commands.
>
> Also try posting your traceback.

Good suggestions. My assembler command is "llvmmc -o=vms-hello.obj --filetype=obj vms-hello.s". I'm using no special linker options. Here's what the linker map looks like for the asm version:

+---------------------------+
! Object and Image Synopsis !
+---------------------------+

Module/Image File Ident Attributes Bytes Creation Date Creator
------------ ---- ----- ---------------- ----- ------------- -------
(Unknown) (Unknown) 119 (Unknown) (Unknown)
DISK$X86DATA:[home.jhamby.Projects]vms-hello.obj;5
LIBRTL X01-001 0 30-SEP-2023 07:11 Linker I02-94
SYS$COMMON:[SYSLIB]LIBRTL.EXE;1
SYS$PUBLIC_VECTORS X-3 Sel 0 16-MAY-2023 13:31 Linker I02-94
SYS$COMMON:[SYSLIB]SYS$PUBLIC_VECTORS.EXE;1

Key for Attributes
+------------------------------------------+
! Sel - Module was selectively searched !
+------------------------------------------+

+------------------+
! Cluster Synopsis !
+------------------+

Cluster Match Majorid Minorid
------- ----- ------- ----------
DEFAULT_CLUSTER
LIBRTL LESS/EQUAL 1 1
SYS$PUBLIC_VECTORS EQUAL 14443 2200863325

+------------------------+
! Image Segment Synopsis !
+------------------------+

Seg# Cluster Type Pglts Base Addr Disk VBN PFC Protection Attributes
---- ------- ---- ----- --------- -------- --- ---------- ----------
0 DEFAULT_CLUSTER LOAD 1 00002000 2 0 READ WRITE
1 LOAD 1 Q-00000000
80000000 3 0 READ ONLY EXECUTABLE
2 LOAD 1 Q-00000000
80002000 4 0 READ ONLY FIXED OFFSET,[UNWIND]
3 LOAD 1 Q-00000000
80004000 5 0 READ ONLY FIXED OFFSET
4 LOAD 1 00004000 6 0 READ ONLY EXECUTABLE
5 DYNAMIC 2 Q-00000000
80006000 7 0 READ ONLY

Key for special characters above
+----------------------+
! Q - Quad Value !
+----------------------+

+--------------------------+
! Program Section Synopsis !
+--------------------------+

Psect Name Module/Image Base End Length Align Attributes
---------- ------------ ---- --- ------ ----- ----------
..data 00002000 00002025 00000026 ( 38.) QUAD 3 CON,REL,LCL,NOSHR,NOEXE, WRT,
NOVEC, MOD
vms-hello 00002000 00002025 00000026 ( 38.) QUAD 3
$LINKER SCODE$ 00004000 0000402F 00000030 ( 48.) OCTA 4 CON,REL,GBL,NOSHR, EXE,NOWRT,
NOVEC, MOD
<Linker> 00004000 0000402F 00000030 ( 48.) OCTA 4
$CODE$ Q-00000000 00000000 00000000 OCTA 4 CON,REL,LCL,NOSHR, EXE,NOWRT,
NOVEC, MOD
80000000 80000020 00000021 ( 33.)
vms-hello Q-00000000 00000000 00000000 OCTA 4
80000000 80000020 00000021 ( 33.)
$LINKER C$0 Q-00000000 00000000 00000000 OCTA 4 CON,REL,LCL,NOSHR, EXE,NOWRT,
NOVEC, MOD
80000030 8000003F 00000010 ( 16.)
<Linker> Q-00000000 00000000 00000000 OCTA 4
80000030 8000003F 00000010 ( 16.)
..eh_frame Q-00000000 00000000 00000000 QUAD 3 CON,REL,LCL,NOSHR,NOEXE,NOWRT,
NOVEC, MOD
80002000 8000206F 00000070 ( 112.)
vms-hello Q-00000000 00000000 00000000 QUAD 3
80002000 8000202F 00000030 ( 48.)
<Linker> Q-00000000 00000000 00000000 QUAD 3
80002030 8000206F 00000040 ( 64.)
..eh_frame_hdr64 Q-00000000 00000000 00000000 LONG 2 CON,REL,LCL,NOSHR,NOEXE,NOWRT,
NOVEC, MOD
80002070 80002093 00000024 ( 36.)
<Linker> Q-00000000 00000000 00000000 LONG 2
80002070 80002093 00000024 ( 36.)
$LINKER GOT64$ Q-00000000 00000000 00000000 QUAD 3 CON,REL,LCL,NOSHR,NOEXE,NOWRT,
NOVEC, MOD
80004000 8000400F 00000010 ( 16.)
<Linker> Q-00000000 00000000 00000000 QUAD 3
80004000 8000400F 00000010 ( 16.)

Key for special characters above
+----------------------+
! Q - Quad Value !
+----------------------+

+-----------------+
! Symbols By Name !
+-----------------+

Symbol Value Symbol Value Symbol Value Symbol
Value
------ ----- ------ ----- ------ ----- ------
-----
ELF$TFRADR 80000000-RQ

Key for special characters above
+----------------------+
! * - Undefined !
! (U) - Universal !
! R - Relocatable !
! X - External !
! C - Code Address !
! WK - Weak !
! UxWk - Unix-Weak !
! Q - Quad Value !
+----------------------+

And here's the link map for the Pascal version:

+---------------------------+
! Object and Image Synopsis !
+---------------------------+

Module/Image File Ident Attributes Bytes Creation Date Creator
------------ ---- ----- ---------------- ----- ------------- -------
HELLO 01 156 07-Nov-2023 09:35 VSI Pascal x86-6
4 X6.3-139
DISK$X86DATA:[home.jhamby.Projects]hello.OBJ;1
LIBRTL X01-001 0 30-SEP-2023 07:11 Linker I02-94
SYS$COMMON:[SYSLIB]LIBRTL.EXE;1
SYS$PUBLIC_VECTORS X-3 Sel 0 16-MAY-2023 13:31 Linker I02-94
SYS$COMMON:[SYSLIB]SYS$PUBLIC_VECTORS.EXE;1

Key for Attributes
+------------------------------------------+
! Sel - Module was selectively searched !
+------------------------------------------+

+------------------+
! Cluster Synopsis !
+------------------+

Cluster Match Majorid Minorid
------- ----- ------- ----------
DEFAULT_CLUSTER
LIBRTL LESS/EQUAL 1 1
SYS$PUBLIC_VECTORS EQUAL 14443 2200863325

+------------------------+
! Image Segment Synopsis !
+------------------------+

Seg# Cluster Type Pglts Base Addr Disk VBN PFC Protection Attributes
---- ------- ---- ----- --------- -------- --- ---------- ----------
0 DEFAULT_CLUSTER LOAD 1 00002000 2 0 READ WRITE
1 LOAD 1 00004000 3 0 READ ONLY
2 LOAD 1 Q-00000000
80000000 4 0 READ ONLY EXECUTABLE
3 LOAD 1 Q-00000000
80002000 5 0 READ ONLY FIXED OFFSET,[UNWIND]
4 LOAD 1 Q-00000000
80004000 6 0 READ ONLY FIXED OFFSET
5 LOAD 1 00006000 7 0 READ ONLY EXECUTABLE,[UNWIND]
6 DYNAMIC 2 Q-00000000
80006000 8 0 READ ONLY

Key for special characters above
+----------------------+
! Q - Quad Value !
+----------------------+

+--------------------------+
! Program Section Synopsis !
+--------------------------+

Psect Name Module/Image Base End Length Align Attributes
---------- ------------ ---- --- ------ ----- ----------
..data.rel.ro 00002000 00002007 00000008 ( 8.) QUAD 3 CON,REL,LCL,NOSHR,NOEXE, WRT,
NOVEC, MOD
HELLO 00002000 00002007 00000008 ( 8.) QUAD 3
..rodata 00004000 0000400C 0000000D ( 13.) QUAD 3 CON,REL,LCL,NOSHR,NOEXE,NOWRT,
NOVEC, MOD
HELLO 00004000 0000400C 0000000D ( 13.) QUAD 3
$LINKER SCODE$ 00006000 00006083 00000084 ( 132.) OCTA 4 CON,REL,GBL,NOSHR, EXE,NOWRT,
NOVEC, MOD
<Linker> 00006000 00006083 00000084 ( 132.) OCTA 4
$CODE$ Q-00000000 00000000 00000000 OCTA 4 CON,REL,LCL, SHR, EXE,NOWRT,
NOVEC, MOD
80000000 8000004E 0000004F ( 79.)
HELLO Q-00000000 00000000 00000000 OCTA 4
80000000 8000004E 0000004F ( 79.)
$LINKER C$0 Q-00000000 00000000 00000000 OCTA 4 CON,REL,LCL, SHR, EXE,NOWRT,
NOVEC, MOD
80000050 8000005F 00000010 ( 16.)
<Linker> Q-00000000 00000000 00000000 OCTA 4
80000050 8000005F 00000010 ( 16.)
..eh_frame Q-00000000 00000000 00000000 QUAD 3 CON,REL,LCL,NOSHR,NOEXE,NOWRT,
NOVEC, MOD
80002000 80002077 00000078 ( 120.)
HELLO Q-00000000 00000000 00000000 QUAD 3
80002000 80002037 00000038 ( 56.)
<Linker> Q-00000000 00000000 00000000 QUAD 3
80002038 80002077 00000040 ( 64.)
..eh_frame_hdr64 Q-00000000 00000000 00000000 LONG 2 CON,REL,LCL,NOSHR,NOEXE,NOWRT,
NOVEC, MOD
80002078 8000209B 00000024 ( 36.)
<Linker> Q-00000000 00000000 00000000 LONG 2
80002078 8000209B 00000024 ( 36.)

Psect Name Module/Image Base End Length Align Attributes
---------- ------------ ---- --- ------ ----- ----------
$LINKER GOT64$ Q-00000000 00000000 00000000 QUAD 3 CON,REL,LCL,NOSHR,NOEXE,NOWRT,
NOVEC, MOD
80004000 80004017 00000018 ( 24.)
<Linker> Q-00000000 00000000 00000000 QUAD 3
80004000 80004017 00000018 ( 24.)

Key for special characters above
+----------------------+
! Q - Quad Value !
+----------------------+

+-----------------+
! Symbols By Name !
+-----------------+

Symbol Value Symbol Value Symbol Value Symbol
Value
------ ----- ------ ----- ------ ----- ------
-----
ELF$TFRADR 80000000-RCQ

Key for special characters above
+----------------------+
! * - Undefined !
! (U) - Universal !
! R - Relocatable !
! X - External !
! C - Code Address !
! WK - Weak !
! UxWk - Unix-Weak !
! Q - Quad Value !
+----------------------+

I still don't know how to fix my source file, but I can see that the ELF$TFRADR symbol is marked "RCQ" (relocatable, code address, quad value) in the working Pascal version, and "RQ" in my non-working asm version. The Pascal ..exe also has a ".data.rel.ro" program section that I don't know how to generate, and the $CODE$ section is marked "SHR" instead of "NOSHR", which I already knew from the .obj file disassembly.

I suspect the fix is as simple as a slightly different declaration for my code segment or the ELF$TFRADR global symbol. The nice thing about using Pascal instead of C for comparison is the Pascal version isn't pulling in any runtime support libraries, and its ELF$TFRADR is pointing at the start of the procedure code. So the linker mapping looks like the only relevant difference. I also wrote a MACRO-32 version and that looked essentially the same as the Pascal version, except with more pushing and popping of (unused) temp registers to the stack.

SubjectRepliesAuthor
o How to write "Hello, world" in x86 assembly (llvm-mc)?

By: Jake Hamby (Solid St on Tue, 7 Nov 2023

5Jake Hamby (Solid State Jake)
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor