[Info-vax] How to write "Hello, world" in x86 assembly (llvm-mc)?

Jake Hamby (Solid State Jake) jake.hamby at gmail.com
Tue Nov 7 14:33:58 EST 2023


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.



More information about the Info-vax mailing list