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

Simon Clubley clubley at remove_me.eisner.decus.org-Earth.UFP
Tue Nov 7 13:54:57 EST 2023


On 2023-11-07, Jake Hamby (Solid State Jake) <jake.hamby at gmail.com> wrote:
>
> # Writes "Hello, World" to the console using only system calls. Runs on OpenVMS x86-64 only.
>
>         .global ELF$TFRADR
>
>         .section        $CODE$, "ax", "progbits"  # EXE,SHR
>         .align  16
>
>         .cfi_startproc
> ELF$TFRADR:
> START:
>        mov     message_descr at GOTPCREL(%rip),%rdi
>        mov     $0x0100,%ax
>        call    LIB$PUT_OUTPUT at PLT
>        mov     $0x00000001,%edi
>        mov     $0x0100,%ax
>        call    SYS$EXIT at PLT
>        pop     %rbp
>        ret
>        .cfi_endproc
>
>         .section .data
> message:
>         .ascii  "Hello, world!"
> message_end:
>         .align 8
> message_descr:
>         .word   1                       # must-be-one field
>         .byte   14                      # DSC$K_DTYPE_T
>         .byte   1                       # DSC$K_CLASS_S
>         .word   -1                      # must-be-minus-one field

Why do you have a word here instead of a longword ?

>         .quad   (message_end - message)
>         .quad   message
>

> I tried a number of variations, including a 32-bit descriptor, which also didn't work, and as I said, it crashes even with just a "ret" line. Adding/removing the "@PLT" and "%GOTPCREL(%rip)" didn't change anything, and I never saw a single line of output in my experiments. The Pascal object code for the following program looks almost identical to my asm code except that it constructs the descriptor on the stack:
>
> (* Test minimal Output *)
>
> [inherit('pascal$lib_routines', 'starlet')]
>
> program Hello;
> begin
>   lib$put_output('Hello, world!');
>   $exit(1)
> end.
>
> The only clue that something may be wrong with my asm directives is that ana/obj/disass shows the Pascal .OBJ file's code section as:
>
> .section           $CODE$, "ax", "progbits"   # EXE,SHR
>
> But my asm version, despite including the same source line, generates a file that disassembles into this:
>
> .section           $CODE$, "ax", "progbits"   # EXE
>
> The part after the "#" is a comment, so that's even more weird. I tried more UNIX-like section directives like ".text" and again, no difference. BTW, the VMS x86 disassembler treats constants as hex but doesn't include a "0x", so if you copy-and-paste the code into a gas-style .s file, it thinks they're octal numbers and you have to add the prefix. So I'm not surprised that there appears to be some round-trip issue with the disassembled section header directive not giving the same result when reassembled in llvm-mc.
>

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.

Simon.

-- 
Simon Clubley, clubley at remove_me.eisner.decus.org-Earth.UFP
Walking destinations on a map are further away than they appear.



More information about the Info-vax mailing list