Cross compiling to AIX: or missing shr.o

I was inspired by NCommander’s MinGW to Solaris cross compiler so I thought I’d dig out the one that got me started decades ago, cross compiling to the RS/6000 from Linux some time back in 1993. For this experiment I was able to beg/borrow a copy of /usr/lib & /usr/include from AIX 3.2.5 and wanted to use that as a base. I decided to use GCC and Binutils 2.11.2 as these were old enough t build somewhat easy enough from MinGW/MSYS 1, but I figured they also had the best luck of being able to parse the headers without needing ‘fixinc’.

I was able to build both binutils and GCC with this simple incanation

sh configure --target=ppc-ibm-aix325 --prefix=/aix3

One weird thing was that binutils completely sidestepped ld, so I had to configure that manually like this:

--target=powerpc-ibm-aix --prefix=/aix3

Also ‘eaixppc.c’ didn’t generate properly I had to rebuild binutils from Linux to get it to pick up and build that file, copy that back in to get a working cross linker. Older stuff has some issues with CR/LF from time to time, and sometimes it’s easier to deal with builds from other systems and pluck files as needed.

Surprisingly things built, and transferring the to my Qemu AIX image gave me this fun error:

exec(): 0509-036 Cannot load program /cdrom/demo/hello/hello because of the following errors:
0509-150 Dependent module libc.a(shr.o) could not be loaded.
0509-022 Cannot load module libc.a(shr.o).
0509-026 System error: A file or directory in the path name does not exist.

Surprisingly IBM has a fix!

# export LIBPATH=$LIBPATH:/usr/lib
# /cdrom/demo/hello/hello
hello world, compiled by GCC!


Of course it’s not all sunshine and rainbows, bigger programs like the ‘87 Infocom interpreter bomb like this:

C:\aix3\demo\infocom>gcc -v -o infocom file.o funcs.o infocom.o init.o input.o interp.o io.o jump.o object.o options.o page.o print.o property.o support.o variable.o term.o
gcc version
ld -T512 -H512 -btextro -bhalt:4 -bnodelcsect -o infocom /aix3/lib/crt0.o -L/aix3/lib file.o funcs.o infocom.o init.o input.o interp.o io.o jump.o object.o options.o page.o print.o property.o support.o variable.o term.o /aix3/lib/libgcc.a -lc /aix3/lib/libgcc.a
ld: section .data [0000000000000000 -> 00000000000007ff] overlaps section .text [0000000000000200 -> 0000000000009b0b]
ld: section .loader [0000000000000000 -> 00000000000014a8] overlaps section .text [0000000000000200 -> 0000000000009b0b]
gcc: Internal compiler error: program ld got fatal signal 1

Initially I thought this was a problem with the GCC Linker, but after copying the objects to Qemu, and linking from there, I found out that the GNAT gcc driver calls the linker in a different manner:

ld -bpT:0x10000000 -bpD:0x20000000 -btextro -bnodelcsect -o infocom /aix3/lib/crt0.o file.o funcs.o infocom.o init.o input.o interp.o io.o jump.o object.o options.o page.o print.o property.o support.o variable.o term.o /aix3/lib/libgcc.a /aix3/lib/libc.a /aix3/lib/libgcc.a

Reformatted for my cross, but this produces a running executable.

And finally phoon which heavily relies on floating point math:

C:\aix3\demo\phoon>ld -bpT:0x10000000 -bpD:0x20000000 -btextro -bnodelcsect -o phoon /aix3/lib/crt0.o phoon.o date_parse.o astro.o /aix3/lib/libc.a /aix3/lib/libgcc.a /aix3/lib/libm.a
/aix3/lib/libm.a(atan2.o)(.pr+0x308):atan2.c: undefined reference to __itrunc' /aix3/lib/libm.a(atan2.o)(.pr+0x33c):atan2.c: undefined reference to__itrunc'
/aix3/lib/libm.a(atan2.o)(.pr+0x3c4):atan2.c: undefined reference to `__itrunc'

I thought first I could just tack -lm onto the end. However remembering years ago, linkers ARE position dependent, and on AIX libm must come before libc.

ld -bpT:0x10000000 -bpD:0x20000000 -btextro -bnodelcsect -o phoon /aix3/lib/crt0.o phoon.o date_parse.o astro.o /aix3/lib/libm.a /aix3/lib/libgcc.a /aix3/lib/libc.a

And yep it runs!

Sadly networking is a bit goofed on 4.3.3, and Im unable to upload more than a few hundred bytes before a stall on the console so slip/ppp would be a bit useless.

Speaking of useless, if anyone is crazy enough, you can follow here: MinGW-AIX325.7z

Installing AIX on Qemu!

YES it’s real!

I’m using the Linux subystem on Windows, as it’s easier to build this Qemu tree from source. I’m using Debian, but these steps will work on other systems that use Debian as a base.

First thing first, you need to get your system with the needed pre-requisites to compile:

apt-get update;apt-get upgrade apt-get install build-essential pkg-config libz-dev libglib2.0-dev libpixman-1-dev libfdt-dev

Great with those in place, now clone Artyom Tarasenko’s source repository

git clone --branch 40p-20190406-aix-boots --single-branch

Since the frame buffer apparently isn’t quite working just yet, I configure for something more like a text mode build.

./configure --target-list=ppc-softmmu --disable-sdl --disable-vnc --disable-gtk

Now for me, GCC 7 didn’t build the source cleanly. I had to make a change to the file config-host.mak and remove all references to -Werror. Also I removed the sound hooks, as we won’t need them. remove the following lines:


Now you can build Qemu. it’ll happily build in parallel so feel free to build using the -j parameter with how many cores you have. I have 32, so I use

make -j32

Okay, all being well you now have a Qemu. Now following the steps from
Artyom Tarasenko’s blog post, we can get started on the install!

First we create a 8GB disk

qemu-img create -f qcow2 aix-hdd.qcow2 8G

Next we need the custom BIOS with serial as the console.


You’ll need some AIX. I tried a 3.2.5 CD-ROM and it didn’t pick up, but AIX 4.3.3 did.

Now with all those bits in place, it’s time to run Qemu.

./ppc-softmmu/qemu-system-ppc -M 40p -bios q40pofw-serial.rom -serial telnet::4441,server -hda aix-hdd.qcow2 -vga none -nographic -net none -cdrom Volume_1.iso

Now telnet to your localhost on port 4441 and you will see the console doing it’s BIOS initialize and eventually drop to the OK prompt.

One trick I’ve found is that from the Open Firmware prompt you can find out what partitions are recognized from the firmware. If it see’s partitions then there is some hope that the image you have is valid enough to boot. In the last few days I’ve found quite a few AIX images, which are lacking the partition table, and unable to boot.

.partitions cdrom

simply type in boot cdrom:2 to kick off the installer. It may take a minute or so for the installer to kick off.

If all goes well, you’ll see the BIOS reload itself, then after a minute you’ll be prompted to press 1 to select the console

It doesn’t echo, don’t panic!

Next select your language. I’m doing English.

Next it’ll ask about installation type. Default ought to be fine.

Because this will destroy the contents of the disk (which doesn’t matter as it’s blank) it’ll prompt for confirmation.

After this it’ll begin the installation. Depending on how fast your disk & CPU is this will take a while.

For me, the installation took about 11 minutes. This is using my Xeon E5-2667 v2. It took 17 minutes on my 2006 Mac Pro, with X5365’s it .

After it’s done, right around the 96% time it’ll reboot back to the BIOS

Once you are back at the OK prompt, you can now boot disk:

it’ll look like it’s hung for a minute, then it’ll start booting from disk!

Once the OS is booted up, you select the terminal type. I’m using putty but I’ll select the vt100. Of note the function keys are selected by hitting escape and then the number key. So F3 is ESC 3.

I’m just going to finish the install, as we can always run smitty to mess with the system more, but right now I’m just interested in a base install of the BOS (Base Operating System, and IBM ISM).

A few moments later, you’ll get dumped to the login prompt.

By default there is no password, so just login as root, and there you go, your very own virtual AIX 4.3 system.

# uname -a AIX localhost 3 4 000000004C00

So there you go! All thanks to Artyom’s hard work!