I have been trying to cross compile gcc for 64-bit powerpc architecture. However, GCC configuration lacks "powerpc64-elf" target. It has "powerpc64-linux", powerpc-rtems (which can produces 32/64 bit code).
Digging further, I have read the following document (which describes the ABI used by linux for powerpc64 arch): https://refspecs.linuxfoundation.org/ELF/ppc64/PPC-elf64abi.html
Specification introduces an additional segment called TOC. Also, this specification uses ELFv2 format to address these changes.
My first (and maybe unrelated questions is) is;
My actual question is, when compiling GCC, if I were to just change ABI to default powerpc ABI,
Thanks in advance.
Edit:
Clarification: I forgot to mention that I am not planning to run the programs compiled using modified gcc on existing linux targets. Rather, I want to simplify ABI for OS architecture support package (possibly using the same architecture support both platforms).
In this case, I want to run 64 bit code (without 4GB memory limit) using ELFv1 ABI on powerpc64 architecture using powerpc-linux (rather than powerpc64-linux).
TOC/GOT overheads: According to Bill's answer about GOT and TOC overheads, I compared the dumps of simple programs compiled powerpc32 and powerpc64 compilers. As he described GOT too uses extra level of indirection. TOC seems to intruduce 2 additional instructions (a load immediate followed by an add immediate - which are trivial).
Edit2: In the end, I opted to use standard ABI. Compiler and OS needs a handshake at this point.
But I did create a custom configuration of gcc by observing other OS (like linux, rtems) and following this tutorial: Structure of a gcc backend.
Short answer: No, you can't use powerpc-linux as your target for a 64-bit PowerPC target.
You need to cross compile for the target of the Linux distribution where your code is intended to run. For most modern distributions, the code will run in little-endian mode, so you need to target powerpc64le-linux. Some older distributions run in big-endian mode, with target powerpc64-linux. Generally speaking, powerpc64-linux uses the ELF v1 ABI, and powerpc64le-linux uses the ELF v2 ABI. Both use a TOC pointer.
PowerPC is a little unique in its use of a compiler-managed table-of-contents (TOC) and a linker-managed global offset table (GOT), as opposed to a single GOT that many targets use. But in practice the overhead is not that different, thanks to a variety of compiler and linker optimizations. In both systems, an extra level of indirection is necessary when accessing global shared variables because addresses of these are not known until run time, and are satisfied by the dynamic linker (except when using pure static linking, which is uncommon today).
In short, don't worry about the TOC, and set up your cross-compile for the environment in which your code is expected to run.