freebasic / fbc

FreeBASIC is a completely free, open-source, multi-platform BASIC compiler, with syntax similar to MS-QuickBASIC, that adds new features such as pointers, object orientation, unsigned data types, inline assembly, and many others.
https://www.freebasic.net
905 stars 139 forks source link

FreeBASIC support for Linux on PowerPC and PowerPC64? #383

Open jeffgazso opened 2 years ago

jeffgazso commented 2 years ago

It looks like FreeBSD PowerPC 64 support was recently added to FreeBASIC by @lenoil98 via #290 and a lot of effort went towards solving endianness issues. Would it be possible to extend support to Linux on PowerPC and PowerPC64 as well? PPC/PPC64 architectures still see use in the Linux space, especially for source-based Linux distributions such as Gentoo.

rversteegen commented 2 years ago

Do you have a Linux PPC64 machine to test on? If so, try it out, that's the only way to find and solve issues. fbc recognises ppc, ppc64 and ppc64le as targets and it's not FreeBSD-specific. You'll likely want to bootstrap from x86 by editing and running the bootstrap-dist target in makefile.

One predictable issue is that parts of Linux system headers (bindings provided by crt.bi) are arch-specific, but few FB programs would use any that are affected.

Actually, almost all big-endian issues remain unresolved. I made some more progress on the file I/O and w/string ones and then got distracted again... Intending to get back it it soon.

jeffgazso commented 2 years ago

Do you have a Linux PPC64 machine to test on?

I will have reasonably soon.

You'll likely want to bootstrap from x86 by editing and running the bootstrap-dist target in makefile. Are you saying I should cross-compile it? Compile on x86_64 but build it for PPC64?

Actually, almost all big-endian issues remain unresolved.

Oh, I misunderstood some of the comments in #290 — my mistake. Are the endian issues primarily located in the bootstrapper code written in C, or are they located within the code written in BASIC? Are there unit tests I can run (when my hardware arrives) that can help ferret out the issues?

rversteegen commented 2 years ago

Yes, there are lots of tests. Run make unit-tests and make log-tests.

The endian issues won't prevent you from compiling fbc or any other FB program (with the exception of UTF-8/16/32-encoded .bas source files). They're primarily in the runtime library (written in C) plus one or two in reading UTF source files (written in FB).

OPNA2608 commented 2 years ago

Tried this today on a PowerMac G5 (ppc64, big-endian) running Linux, with both the native tools and a Nix stdenv.

  1. Ran make bootstrap from 1.09.0 on linux-x86_64.
  2. Ran make at 358c7f866c44ad8075b06432d59ad20fa447a2db with the bootstrapped fbc, just in case there were any relevant changes since 1.09.0.
  3. Modified bootstrap-dist target to generate bootstrap files for linux-powerpc64.
  4. Ran make bootstrap-dist and copied the resulting tarball to the G5.
  5. Ran make bootstrap-minimal on linux-powerpc64, which completed without errors.

When I tried to make compiler with the bootstrapped compiler next, it errored out at the linking step.

FBC src/compiler/obj/linux-powerpc64/symb-typedef.o
FBC src/compiler/obj/linux-powerpc64/symb-var.o
FBC src/compiler/obj/linux-powerpc64/symb.o
LINK bin/fbc
error 23: File not found, crt1.o
error 133: Too many errors, exiting
ld: cannot find -lgcc: No such file or directory
make: *** [makefile:722: bin/fbc] Error 1

gcc itself has no problem finding crt1.o in the build environment, both the native one and the Nix one.

$ gcc -print-file-name=crt1.o
/usr/lib64/gcc/powerpc64-linux-gnu/10.2.1/../../../../lib64/crt1.o

$ file /usr/lib64/gcc/powerpc64-linux-gnu/10.2.1/../../../../lib64/crt1.o
/usr/lib64/gcc/powerpc64-linux-gnu/10.2.1/../../../../lib64/crt1.o: ELF 64-bit MSB relocatable, 64-bit PowerPC or cisco 7500, OpenPOWER ELF V2 ABI, version 1 (SYSV), for GNU/Linux 3.2.0, with debug_info, not stripped
$ gcc -print-file-name=crt1.o
/nix/store/k8q4alpfxry55lb5gsf2bs4r67h8ypyc-glibc-2.35-163/lib/crt1.o

$ file /nix/store/k8q4alpfxry55lb5gsf2bs4r67h8ypyc-glibc-2.35-163/lib/crt1.o
/nix/store/k8q4alpfxry55lb5gsf2bs4r67h8ypyc-glibc-2.35-163/lib/crt1.o: ELF 64-bit MSB relocatable, 64-bit PowerPC or cisco 7500, OpenPOWER ELF V2 ABI, version 1 (SYSV), for GNU/Linux 2.6.32, not stripped