Page 1 of 1

Building GCC cross-compiler on AIX 7.3 2 for target powerpc64-linux

Posted: Thu Oct 17, 2024 9:06 am
by tyler87898
Hi all

I'm attempting to build GCC on AIX 7.3.2 as a cross compiler for the first time with the following configure parameters:

--host=powerpc-ibm-aix7.3.2.0 (--build should be the same)
--target=powerpc64-linux (big endian)
--disable-threads
--disable-nls
--prefix=/my/gcc_upgrade/installdir
--enable-languages=c (only C is needed)

I'm running config and make from /my/gcc_upgrade/objdir

The native AIX7.3 compiler I'm using to start off with is gcc-12 which is included in the AIX toolbox for Linux applications. Same with g++ (g++-12). I also installed GNU make from the same toolbox.

Instead of downloading the other prereqs from the toolbox, I executed the script in the gcc-14.2.0 source tree contrib/download_prerequisites to download the gmp/mpfr/mpc source code into the gcc-14.2.0 source tree. I also placed the source code for various binutils 2.43.1 tools in the same source tree.

I'm building outside of the source directory as instructed.

I've read that binutils may not work correctly on AIX and may need to use the native tools (as, ld, etc.), so maybe I need to remove these binutils... But I'm also confused - don't I need to build binutils for the host/target combo (aix/powerpc64-linux) at some point? Since the built-in AIX tools are not cross-tools? It's not clear to me if this is giving me an issue or not. The build seems to progress up to a certain point until I run into this issue:

Despite the config of --disable-threads, I'm getting this linker issue that breaks out of the make:

ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock

I'm confused as to why these symbols are necessary if I configured the build with --disable-threads ...? Not sure how I can get around this. Do I need to add a -lpthread or -pthread flag somewhere? Where would it be (in a makefile? That thing is huge...). Clearly I'm still inexperienced with builds of this magnitude and complexity.

I'm using --disable-threads because that's what my old cross-compiler used (20 years ago), plus I will not be using threads in any compiled program.

Another side-question: I assume the make is using ld that was built from the binutils source, but is there a way to confirm this? Again, not sure if this is related to the linker issue I'm experiencing that breaks the make.


Thanks in advance and let me know if I can provide more info.


Here is a larger snippet of the make fail:

Code: Select all

make[6]: Leaving directory '/my/gcc_upgrade/objdir/gettext/gnulib-lib'
make[5]: Leaving directory '/my/gcc_upgrade/objdir/gettext/gnulib-lib'
make[4]: Leaving directory '/my/gcc_upgrade/objdir/gettext/gnulib-lib'
Making all in src
make[4]: Entering directory '/my/gcc_upgrade/objdir/gettext/src'
gcc -DLOCALEDIR=\"/my/gcc_upgrade/installdir/share/locale\" -DHAVE_CONFIG_H -I. -I/my/gcc_upgrade/gcc-14.2.0/gettext/gettext-runtime/src -I..  -I. -I/my/gcc_upgrade/gcc-14.2.0/gettext/gettext-runtime/src -I.. -I../intl -I/my/gcc_upgrade/gcc-14.2.0/gettext/gettext-runtime/src/../intl -I../gnulib-lib -I/my/gcc_upgrade/gcc-14.2.0/gettext/gettext-runtime/src/../gnulib-lib  -DINSTALLDIR=\"/my/gcc_upgrade/installdir/bin\" -g -O2     -c -o gettext-gettext.o `test -f 'gettext.c' || echo '/my/gcc_upgrade/gcc-14.2.0/gettext/gettext-runtime/src/'`gettext.c
/bin/sh ../libtool  --tag=CC   --mode=link gcc -DINSTALLDIR=\"/my/gcc_upgrade/installdir/bin\" -g -O2      -static-libstdc++ -static-libgcc -Wl,-bbigtoc -o gettext gettext-gettext.o ../gnulib-lib/libgrt.a  -liconv
libtool: link: gcc -DINSTALLDIR=\"/my/gcc_upgrade/installdir/bin\" -g -O2 -static-libstdc++ -static-libgcc -Wl,-bbigtoc -o gettext gettext-gettext.o  ../gnulib-lib/libgrt.a -liconv
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_lock
ld: 0711-317 ERROR: Undefined symbol: .pthread_mutex_unlock
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
collect2: error: ld returned 8 exit status
make[4]: *** [Makefile:1648: gettext] Error 1
make[4]: Leaving directory '/my/gcc_upgrade/objdir/gettext/src'
make[3]: *** [Makefile:1644: all-recursive] Error 1
make[3]: Leaving directory '/my/gcc_upgrade/objdir/gettext'
make[2]: *** [Makefile:1549: all] Error 2
make[2]: Leaving directory '/my/gcc_upgrade/objdir/gettext'
make[1]: *** [Makefile:9485: all-gettext] Error 2
make[1]: Leaving directory '/my/gcc_upgrade/objdir'
make: *** [Makefile:1059: all] Error 2

Here is a the result of the line that broke the make which I don't understand, but with the -bnoquiet flag added

Code: Select all

bash-5.2# /bin/sh ../libtool  --tag=CC   --mode=link gcc -DINSTALLDIR=\"/my/
gcc_upgrade/installdir/bin\" -g -O2      -static-libstdc++ -static-libgcc -Wl,-
bbigtoc,-bnoquiet -o gettext gettext-gettext.o ../gnulib-lib/libgrt.a  -liconv
libtool: link: gcc -DINSTALLDIR=\"/my/gcc_upgrade/installdir/bin\" -g -O2 -static-libstdc++ -static-libgcc -Wl,-bbigtoc -Wl,-bnoquiet -o gettext gettext-gettext.o  ../gnulib-lib/libgrt.a -liconv
(ld): halt 4
(ld): setopt r/o->w
(ld): setopt bigtoc
(ld): setfflag 4
(ld): savename gettext
(ld): filelist 10 1
(ld): i /lib/crt0.o
(ld): i /opt/freeware/lib/gcc/powerpc-ibm-aix7.3.0.0/12/crtcxa.o
(ld): i /opt/freeware/lib/gcc/powerpc-ibm-aix7.3.0.0/12/crtdbase.o
(ld): i gettext-gettext.o
(ld): i ../gnulib-lib/libgrt.a
(ld): lib /opt/freeware/lib/gcc/powerpc-ibm-aix7.3.0.0/12/../../../libiconv.a
(ld): i /opt/freeware/lib/gcc/powerpc-ibm-aix7.3.0.0/12/libgcc.a
(ld): i /opt/freeware/lib/gcc/powerpc-ibm-aix7.3.0.0/12/libgcc_eh.a
(ld): lib /usr/lib/libg.a
(ld): lib /usr/lib/libc.a
LIBRARY: Shared object libiconv.a[libiconv.so.2]: 14 symbols imported.
LIBRARY: Shared object libc.a[shr.o]: 3355 symbols imported.
LIBRARY: Shared object libc.a[meth.o]: 2 symbols imported.
LIBRARY: Shared object libc.a[posix_aio.o]: 20 symbols imported.
LIBRARY: Shared object libc.a[aio.o]: 18 symbols imported.
LIBRARY: Shared object libc.a[pse.o]: 8 symbols imported.
LIBRARY: Shared object libc.a[dl.o]: 4 symbols imported.
LIBRARY: Shared object libc.a[pty.o]: 1 symbols imported.
LIBRARY: Shared object libc.a[cthread.o]: 25 symbols imported.
LIBRARY: Shared object libc.a[uchar.o]: 4 symbols imported.
FILELIST: Number of previously inserted files processed: 10
(ld): resolve
RESOLVE: 405 of 13867 symbols were kept.
(ld): addgl /usr/lib/glinkl.o
ADDGL: Glink code added for 37 symbols.
(ld): er full
ld: 0711-318 ERROR: Undefined symbols were found.
        The following symbols are in error:
 Symbol                    Inpndx  TY CL Source-File(Object-File) OR Import-File{Shared-object}
                              RLD: Address  Section  Rld-type Referencing Symbol
 ----------------------------------------------------------------------------------------------
 .pthread_mutex_lock       [4]     ER PR /my/gcc_upgrade/gcc-14.2.0/gettext/gettext-runtime/gnulib-lib/setlocale_null.c(../gnulib-lib/libgrt.a[libgrt_a-setlocale_null.o])
                                   00000038 .text    R_RBR    [34]    <.setlocale_null_with_lock>
 .pthread_mutex_unlock     [12]    ER PR /my/gcc_upgrade/gcc-14.2.0/gettext/gettext-runtime/gnulib-lib/setlocale_null.c(../gnulib-lib/libgrt.a[libgrt_a-setlocale_null.o])
                                   00000098 .text    R_RBR    [34]    <.setlocale_null_with_lock>
ER: The return code is 8.
collect2: error: ld returned 8 exit status

Re: Building GCC cross-compiler on AIX 7.3 2 for target powerpc64-linux

Posted: Thu Oct 17, 2024 10:39 am
by Octocontrabass
tyler87898 wrote: Thu Oct 17, 2024 9:06 am--target=powerpc64-linux (big endian)
Since you're building a compiler that targets Linux, you need a Linux C standard library and its associated headers. Do you have those?
tyler87898 wrote: Thu Oct 17, 2024 9:06 amInstead of downloading the other prereqs from the toolbox, I executed the script in the gcc-14.2.0 source tree contrib/download_prerequisites to download the gmp/mpfr/mpc source code into the gcc-14.2.0 source tree.
I'd actually try the toolbox first. Sometimes the packages downloaded by that script aren't compatible with non-Linux hosts.
tyler87898 wrote: Thu Oct 17, 2024 9:06 amBut I'm also confused - don't I need to build binutils for the host/target combo (aix/powerpc64-linux) at some point? Since the built-in AIX tools are not cross-tools?
The GCC documentation says it will build the target binutils as long as you provide the source code at the correct location, but I've always built binutils separately, so I don't know how well it works.
tyler87898 wrote: Thu Oct 17, 2024 9:06 amDespite the config of --disable-threads, I'm getting this linker issue that breaks out of the make:
You're disabling threads for your target, but the link error is coming from a host binary. You probably need to pass an override somewhere (host_configargs?) to link host binaries against the correct pthreads library for AIX.

Re: Building GCC cross-compiler on AIX 7.3 2 for target powerpc64-linux

Posted: Fri Oct 18, 2024 10:36 am
by tyler87898
Since you're building a compiler that targets Linux, you need a Linux C standard library and its associated headers. Do you have those?
No, I don't. However, if I don't plan on building any actual code to run on Linux, do I still need these (long story, but I do need to target Linux)? Either way, it wouldn't hurt to try including these anyway. Would you know what specific standard library I need and where I should get it? I'll do some searching...


I'd actually try the toolbox first. Sometimes the packages downloaded by that script aren't compatible with non-Linux hosts.
The GCC documentation says it will build the target binutils as long as you provide the source code at the correct location, but I've always built binutils separately, so I don't know how well it works.
I decided to try this. I reset my gcc-14.2.0 source tree and cleared my build directory and used dnf to install those packages. I also decided to try and build binutils 2.43.1 separately. But now, I seem to have hit a roadblock even sooner as I can't even build binutils.

Here is my configure command:

Code: Select all

../binutils-2.43.1/configure --prefix=/my/gcc_upgrade/installdir -
-disable-shared --disable-nls --host=powerpc-ibm-aix7.3.2.0 --target=powerpc64-
linux
And here is my error output from make:

Code: Select all

make[4]: Entering directory '/my/gcc_upgrade/build-binutils/gas'
  GEN      doc/asconfig.texi
  CC       app.o
  CC       as.o
  CC       atof-generic.o
  CC       codeview.o
  CC       compress-debug.o
  CC       cond.o
  CC       depend.o
  CC       dwarf2dbg.o
  CC       dw2gencfi.o
  CC       ecoff.o
  CC       ehopt.o
  CC       expr.o
  CC       flonum-copy.o
  CC       flonum-konst.o
  CC       flonum-mult.o
  CC       frags.o
  CC       gen-sframe.o
  CC       ginsn.o
  CC       hash.o
  CC       input-file.o
  CC       input-scrub.o
  CC       listing.o
  CC       literal.o
  CC       macro.o
  CC       messages.o
  CC       output-file.o
  CC       read.o
  CC       remap.o
  CC       sb.o
  CC       scfidw2gen.o
  CC       scfi.o
  CC       sframe-opt.o
  CC       stabs.o
  CC       subsegs.o
  CC       symbols.o
  CC       write.o
  CC       config/tc-ppc.o
  CC       config/obj-elf.o
  CC       config/atof-ieee.o
  CCLD     as-new
ld: 0711-317 ERROR: Undefined symbol: .__get_tpointer
ld: 0711-345 Use the -bloadmap or -bnoquiet option to obtain more information.
collect2: error: ld returned 8 exit status
make[4]: *** [Makefile:1312: as-new] Error 1
make[4]: Leaving directory '/my/gcc_upgrade/build-binutils/gas'
make[3]: *** [Makefile:1694: all-recursive] Error 1
make[3]: Leaving directory '/my/gcc_upgrade/build-binutils/gas'
make[2]: *** [Makefile:1031: all] Error 2
make[2]: Leaving directory '/my/gcc_upgrade/build-binutils/gas'
make[1]: *** [Makefile:5518: all-gas] Error 2
make[1]: Leaving directory '/my/gcc_upgrade/build-binutils'
make: *** [Makefile:1036: all] Error 2

Re: Building GCC cross-compiler on AIX 7.3 2 for target powerpc64-linux

Posted: Fri Oct 18, 2024 11:55 am
by Octocontrabass
tyler87898 wrote: Fri Oct 18, 2024 10:36 amHowever, if I don't plan on building any actual code to run on Linux, do I still need these (long story, but I do need to target Linux)?
I think you only need the headers, but I don't know for sure. Most people who target Linux intend to build Linux binaries. (Why exactly do you need to target Linux? What does a powerpc64-linux compiler do for you that a powerpc64-elf compiler doesn't?)
tyler87898 wrote: Fri Oct 18, 2024 10:36 amBut now, I seem to have hit a roadblock even sooner as I can't even build binutils.
That seems to be a known bug, and there's a workaround.

Re: Building GCC cross-compiler on AIX 7.3 2 for target powerpc64-linux

Posted: Fri Oct 18, 2024 12:48 pm
by tyler87898
I think you only need the headers, but I don't know for sure. Most people who target Linux intend to build Linux binaries. (Why exactly do you need to target Linux? What does a powerpc64-linux compiler do for you that a powerpc64-elf compiler doesn't?)
I guess I didn't know that was an option to try. I was just going based off of my old cross-compiler that's quite old.

In gcc-14.2.0/INTSALL/specific.html it mentions: powerpc-*-elf - PowerPC system in big endian mode, running System V.4.

For one, I'm unsure if there is a powerpc64 option that is just undocumented. And second, I'm not familiar with System V.4 so unsure if that would affect anything. I may give it a try at some point.


That seems to be a known bug, and there's a workaround.
I tried adding that flag in various different places, but couldn't find the right place apparently. I ran make -n to get the full command that was failing, and it is a gcc command (see below). However, it seems that the workaround flag (-fno-extern-tls-init) is only supported by g++ anyway.

Code: Select all

echo "  CCLD    " as-new;/bin/sh ./libtool --silent --tag=CC   --mode=link gcc -W -Wall -Wstrict-prototypes -Wmissing-prototypes -Wshadow -Wstack-usage=262144 -Wwrite-strings -I../../binutils-2.43.1/gas/../zlib  -g -O2      -Wl,-bbigtoc -o as-new app.o as.o atof-generic.o codeview.o compress-debug.o cond.o depend.o dwarf2dbg.o dw2gencfi.o ecoff.o ehopt.o expr.o flonum-copy.o flonum-konst.o flonum-mult.o frags.o gen-sframe.o ginsn.o hash.o input-file.o input-scrub.o listing.o literal.o macro.o messages.o output-file.o read.o remap.o sb.o scfidw2gen.o scfi.o sframe-opt.o stabs.o subsegs.o symbols.o write.o config/tc-ppc.o config/obj-elf.o config/atof-ieee.o  ../opcodes/libopcodes.la ../bfd/libbfd.la ../libiberty/libiberty.a   -L./../zlib -lz

Re: Building GCC cross-compiler on AIX 7.3 2 for target powerpc64-linux

Posted: Fri Oct 18, 2024 1:06 pm
by tyler87898
I tried building binutils 2.41 instead and got through the make and make install successfully. So will continue on with that

Re: Building GCC cross-compiler on AIX 7.3 2 for target powerpc64-linux

Posted: Fri Oct 18, 2024 1:42 pm
by Octocontrabass
tyler87898 wrote: Fri Oct 18, 2024 12:48 pmIn gcc-14.2.0/INTSALL/specific.html it mentions: powerpc-*-elf - PowerPC system in big endian mode, running System V.4.

For one, I'm unsure if there is a powerpc64 option that is just undocumented.
There is. That document only lists targets that have special notes associated with them.
tyler87898 wrote: Fri Oct 18, 2024 12:48 pmAnd second, I'm not familiar with System V.4 so unsure if that would affect anything.
Since it's talking about 32-bit PowerPC and you're targeting 64-bit PowerPC, it won't matter for you. (There's more than one ELF ABI for 32-bit PowerPC.)
tyler87898 wrote: Fri Oct 18, 2024 12:48 pmI ran make -n to get the full command that was failing, and it is a gcc command (see below). However, it seems that the workaround flag (-fno-extern-tls-init) is only supported by g++ anyway.
The error occurs during linking, but the workaround has to be applied during compiling. You should be able to add it just by setting CXXFLAGS before running configure and/or make. You might need to empty the build directory to ensure everything gets rebuilt after changing the flags.
tyler87898 wrote: Fri Oct 18, 2024 1:06 pmI tried building binutils 2.41 instead and got through the make and make install successfully.
I guess that works too.

Re: Building GCC cross-compiler on AIX 7.3 2 for target powerpc64-linux

Posted: Wed Oct 23, 2024 1:52 pm
by tyler87898
I made bits of progress but still running into issues. After using dnf to install gmp, mpfr, mpc and manually building binutils 2.41 successfully and installing in my --prefix dir, I configured gcc with the following:

Code: Select all

/my/gcc_upgrade/gcc-14.2.0/configure --prefix=/my/gcc_upgrade/installdir --disable-shared --enable-languages=c --disable-nls --host=powerpc-ibm-aix7.3.2.0 --target=powerpc64-linux --disable-threads --disable-bootstrap --without-headers
Then built/installed...

Code: Select all

make all-gcc -j20
make all-target-libgcc -j20
make install-gcc
make install-target-libgcc
This seemed to complete fine to make a freestanding cross compiler (which is what I want). I copied the compiler over to the system that I want to build on (same OS as build sys, AIX 7.3.2) and tried to compile. Unfortunately, I got this error:

Code: Select all

exec(): 0509-036 Cannot load program /xyzxyz/gcc_install/bin/../libexec/gcc/powerpc64-linux/14.2.0/cc1 because of the following errors:
        0509-150   Dependent module libmpfr.a(libmpfr.so.6) could not be loaded.
        0509-022 Cannot load module libmpfr.a(libmpfr.so.6).
        0509-026 System error: A file or directory in the path name does not exist.
It seems the problem is I don't have GMP/MPFR/MPC on this other system where I moved my installation. However, what I originally wanted anyway was for those dependencies to be built into my install (statically linked instead of dynamic). Is there a way build the dependencies into my GCC build?

I tried 2 options thus far:
  1. Putting the source of gmp, mpfr, mpc in the GCC-14.2.0 source directory so they would compile along with GCC.
    - Configured with:

    Code: Select all

    /my/gcc_upgrade/gcc-14.2.0/configure --prefix=/my/gcc_upgrade/installdir2 --disable-shared --enable-languages=c --disable-nls --host=powerpc-ibm-aix7.3.2.0 --target=powerpc64-linux --disable-threads --disable-bootstrap --without-headers --enable-static
    - I didn't get very far in this route. Following along the "make" output, it looks like gmp is built but then when coming up on the mpfr portion, I get this error:

    Code: Select all

    configure:4954: checking whether the C compiler works
    configure:4976: gcc -g -O2    -I/my/gcc_upgrade/build-gcc-v2/./gmp -static-libstdc++ -static-libgcc -Wl,-bbigtoc -L/my/gcc_upgrade/build-gcc-v2/./gmp/.libs conftest.c  >&5
    Could not load program /opt/freeware/libexec/gcc/powerpc-ibm-aix7.3.0.0/12/cc1:
            Dependent module /my/gcc_upgrade/build-gcc-v2/./gmp/.libs/libgmp.a(libgmp.so.10) could not be loaded.
            Member libgmp.so.10 is not found in archive
    configure:4980: $? = 1
    configure:5020: result: no
    configure: failed program was:
    | /* confdefs.h */
    | #define PACKAGE_NAME "MPFR"
    | #define PACKAGE_TARNAME "mpfr"
    | #define PACKAGE_VERSION "4.2.1"
    | #define PACKAGE_STRING "MPFR 4.2.1"
    | #define PACKAGE_BUGREPORT ""
    | #define PACKAGE_URL ""
    | /* end confdefs.h.  */
    |
    | int
    | main (void)
    | {
    |
    |   ;
    |   return 0;
    | }
    configure:5025: error: in `/my/gcc_upgrade/build-gcc-v2/mpfr':
    configure:5027: error: C compiler cannot create executables
    I can confirm libgmp.a is in that /my/gcc_upgrade/build-gcc-v2/gmp/.libs folder, so not sure what the problem is here.

    EDIT: When I run ar -t libgmp.a on my own built gmp, I see a bunch of .o files. When I run ar -t libgmp.a on the gmp installed by dnf, I see libgmp.so.10 and libgmp.so.3. Why is this? Aren't .so files shared libraries, so why are they in a .a (static lib)? How can I get the GCC build process to search for the .o files instead of .so? Why is it trying to load this program "/opt/freeware/libexec/gcc/powerpc-ibm-aix7.3.0.0/12/cc1" which is separate from what I am building?
  2. Configuring and building gmp, mpfr, mpc separately and then using --with-gmp --with-mpfr --with-mpc GCC configure flags.
    - I didn't get very far in this route, either. I was able to make and install gmp, but then tried to configure mpfr using the --with-gmp flag and the configure would fail with "configure: error: could not determine ar interface", which is weird because without using the --with-gmp flag, the configure would get past that and instead fail because it could not find gmp.

Re: Building GCC cross-compiler on AIX 7.3 2 for target powerpc64-linux

Posted: Fri Oct 25, 2024 4:03 pm
by Octocontrabass
tyler87898 wrote: Wed Oct 23, 2024 1:52 pmIs there a way build the dependencies into my GCC build?
Placing them in the GCC source tree and building them with GCC's build system is supposed to statically link those dependencies into the final GCC binaries, but I've never gotten it to work...
tyler87898 wrote: Wed Oct 23, 2024 1:52 pmAren't .so files shared libraries, so why are they in a .a (static lib)?
That's just how shared libraries work on AIX.
tyler87898 wrote: Wed Oct 23, 2024 1:52 pmWhy is it trying to load this program "/opt/freeware/libexec/gcc/powerpc-ibm-aix7.3.0.0/12/cc1" which is separate from what I am building?
That's the compiler you're using to build everything, why wouldn't it be trying to load that?

Your host GCC should be using its own copy of GMP instead of the one you just compiled. Either your build environment is broken (wrong LD_LIBRARY_PATH?) or you've found a script that isn't compatible with AIX.

Re: Building GCC cross-compiler on AIX 7.3 2 for target powerpc64-linux

Posted: Tue Oct 29, 2024 9:29 am
by tyler87898
I've decided to just accept (for now, at least) that I will install GMP, MPFR, and MPC on whatever system I put this new cross-compiler on.

Thank-you for talking me thru some of my questions