assemblyaixpowerpc

IBM AIX 6.1 PPC assembly program compile issues when using .text with as


I am trying to write programs using 'as' and 'ld' in AIX 6.1. However I cannot get anything to work. At the moment I am dealing with two issues that are stopping me in my tracks.

In the code below, the .text section is throwing an error message when I use 'as hello.s -o hello.o' to compile it: -

.text
.globl main
main:
        addi    3, 0, 1
        addi    4, 0, 2
        add     5, 3, 4
        blr

Error hello.s: line 1: 1252-016 The specified opcode or pseudo-op is not valid. Use supported instructions or pseudo-ops only.

When I remove the '.text' line, the source compiles with no issues. However, after creating the executable using 'ld -e main hello.o -o hello', I get the following error when trying to execute it: -

exec(): 0509-036 Cannot load program hello because of the following errors: 0509-026 System error: A memory address is not in the address space for the process.

'ldd' shows no dependencies, so an empty LIBPATH and LD_LIBRARY_PATH does not seem like an issue

'dbx hello' : -

Type 'help' for help.

warning: cannot execute hello

reading symbolic information ...program is not active

warning: no source compiled with -g

program is not active

Architecture information: -

Processor Type: PowerPC_POWER8

Processor Implementation Mode: POWER 7

Processor Version: PV_7_Compat

CPU Type: 64-bit

Kernel Type: 64-bit

Thank you in advance.


Solution

  • An example might help to start:

        # simple64.s
    
        # compilation (1st option):
        #   /usr/bin/as -a64 -o simple64.o simple64.s
        #   /usr/bin/ld -b64 -o simple64 simple64.o /usr/lib/crt0_64.o /usr/lib/libc.a
        #   ./simple64
    
        # compilation (2nd option):
        #   gcc -maix64 -g -o simple64 simple64.s
        #   ./simple64
    
        # Here 'main' is the function descriptor,
        # and '.main' is the actual code
        # details: https://lzsiga.users.sourceforge.net/aix-linking.html#Q0011
    
                .globl main
                .globl .main
                .toc
                .csect main[DS]
        main:
                .llong .main, TOC[tc0], 0
    
                .csect .text[PR]
        .main:
                addi    3, 0, 1
                addi    4, 0, 2
                add     5, 3, 4
                blr