AIX compile, assemble, and link with gcc

If you just run gcc on some source code, it should simply create an executable for you. However, you can also break the process apart and see the compile and assemble commands.

gcc -S showsum.c
as -u -mcom -o showsum.o showsum.s
ld showsum.o /lib/crt0.o -lc -o showsum

This also leaves your showsum.o object code around, which might be all you really want of you are trying to compile a library. The most interesting part of this, however, is the showsum.s which is actually your program converted into assembler by gcc. You can look at it and even change little pieces of it if you know what you are doing:

more showsum.s
        .file   "showsum.c"
        .toc
        .csect .text[PR]
        .align 2
        .lglobl .strtoimax
        .csect strtoimax[DS]
strtoimax:
        .long .strtoimax, TOC[tc0], 0
        .csect .text[PR]
.strtoimax:
        .extern __mulh
        .extern __mull
        .extern __divss
        .extern __divus
        .extern __quoss
        .extern __quous
        mflr 0
        stw 31,-4(1)
        stw 0,8(1)
        stwu 1,-72(1)
        mr 31,1
        stw 3,96(31)
        stw 4,100(31)
        stw 5,104(31)
        lwz 3,96(31)
        lwz 4,100(31)
        lwz 5,104(31)

Of course this will also be very different on an x86 platform because the instruction set is different. It would interesting to compare what decisions gcc makes on either a Windows or Linux system. I have recently been reading about cross-compiling , and I think this gets into that territory.

Leave a Reply

Your email address will not be published. Required fields are marked *