[bug] ld doesn't support ppc #119
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
When cctools is configured to target powerpc-apple-darwin, as assembles powerpc assembly without issue, but ld will not link it.
ld64-127 was the last version from Apple to support ppc
Recently I attempted to review the difference between the current ld64 and the ld64-127.2, and I attempted to backport PowerPC-related parts but hadn't completed that yet. On another side, I want to get a shot to make the ld64-127 work here. How much the modded ld64 is different from the official ld64?
P.S. I attempting to make a cross-compiler toolchain to run my experimental stuff on my Mac Mini G4, however, it's a pain to build the code on it because of a very weak processor, and therefore a cross-compiler for modern Linux should simplify this. I built everything except GCC: it fails to build the thing because of the ld64...
I made the first attempt here: https://github.com/tpoechtrager/cctools-port/compare/master...Wohlstand:cctools-port:ppc-revive
I had to compare two versions: 127.2 and 128.2 to see what parts of the code were changed in order to remove PowerPC support. So, I attempted to restore that code to the latest version (which appears in this repository here). Trying some to verify its work and make the thing work...
@Wohlstand , it's two years later, but I did try your branch and was able to successfully build cctools for powerpc-apple-darwin8, but if I try to use this to build something like 'gcc' seems to fail to actually link against anything in the 10.4 SDK (
ld can t map file errno 22 dylib1.o for architecture ppc). Were you ever able to get a cross-compiler targeting powerpc-apple-darwin8 working?Edit: Ah, actually, it seems like by simply using
lipoto extract the mach-o ppc binaries out, ld can use them, this can work!Hello!
I didn't yet finished my experiment, and the other problem that GCC is tricky to build. I did all the work on Ubuntu 20.04, and it was close to work, but on Ubuntu 22.04 it now fails (gcc itself) to build even worse for unknown reasons, even I trying to build the same version (Maybe I should build older GCC version for native Linux then? 🤔).
I built the custom Apple's LD thing, and backported support for PPC from old version of ld to new. And even more tricky thing, that when I building GCC cross-compiler to macOS on Linux host, it gets confused how LD should behave (I mean build scripts of GCC itself).
For testing I would recommend using Clang 7.1.0 (the last version to support ppc darwin). The build process is much simpler than GCC's. They also have prebuilt binaries on llvm.org for it, they require ncurses 5 though so you'll need to build that.
I actually have your cctools ppc-review branch and GCC 13.3 building and compiling/linking target binaries, as mentioned I needed to forcibly extract the ppc binaries out of the SDK with the cctools lipo (you do have to rebuild crt1.o if you're using the 10.4 SDK but the 10.5 SDK should work fine if you target 10.4 specifically):
Now I'm trying to figure out why ld crashes when debug information is requested (
-gpassed by the driver). My current theory is that it's this issue with ld not having sufficient stack size by default, but I'll need to dig in when I have time, maybe later tonight.vs
conftest.c (from libpng) is just:
It seems to work if I use the old XCode PPC ld from 3.2, but that locks me into using a Mac instead of like... a Linux docker image running on GHA :P.
If we can figure this last bit out, then it means we'll have a modern-enough cross-compiler for powerpc-apple-darwin8 (Mac OS X Tiger on PPC).
Once LLVM 20 rc1 is out I'll try to add back support for PPC darwin into LLVM 20, no promises though, I'm not that experienced with the LLVM codebase yet or compilers in general, but being able to use Clang instead of GCC would be great for me personally.
I probably shouldn't announce projects that I have no idea if I can complete but oh well.
This guy seems to have made powerpc darwin work in LLVM 8, that's the newest I can find online https://github.com/iains/LLVM-8-Branch
Yeah, I'm using his gcc 13.3 branch as well.
Anyway, built dsymutil with llvm-7 and it seemed to do the trick.
Anyway, for anyone who might benefit, I created a Dockerfile to create the cross compiler: https://github.com/VariantXYZ/gcc-powerpc-apple-darwin8/blob/main/.github/workflows/Dockerfile
Unfortunately, I'm struggling to build it in GHA 🥲
Is there a reason to not use GCC 14? Also why do you rebuild the Csu when you can just use the one in the SDK?
The build finally succeeded: https://github.com/VariantXYZ/gcc-powerpc-apple-darwin8/pkgs/container/gcc-powerpc-apple-darwin8
I just started with 13.3 and forgot 14 existed, actually.
We're using the 10.4u SDK which has this issue https://github.com/tpoechtrager/osxcross/issues/50#issuecomment-149013354
10.5 works too, but I was stubbornly trying to see if I could get just 10.4u working.
For reference, I documented the general reasoning for everything here: https://vxyz.me/00003.html
I think this is definitely the 'cleanest' solution that will probably allow for keeping everything as modern as can be, but for the interim, I think GCC 14.2 + 10.5 SDK targeting 10.4 works (I'm trying to fix my iBook so I can actually test things...). Images for both are here: https://github.com/VariantXYZ/gcc-powerpc-apple-darwin8/pkgs/container/gcc-powerpc-apple-darwin8/versions
I have some workflows here that show how to use them: https://github.com/VariantXYZ/gbdev-powerpc-apple-darwin8/tree/main/.github/workflows
I'm trying to setup QEMU for now to properly test things...
I saw that ppc64 with LLVM 7 doesn't work, there will probably be a lot of issues beyond that since the LLVM code for ppc darwin hasn't been updated in like 6 years and my only experience with the LLVM codebase is a few extremely minor patches. Plus I've had serious issues with compiling for OSX 10.5 x86 and iOS 2 with Clang. I imagine GCC will probably be the best option for a while.
Rather use his llvm-7.1.1 (or my port of it for MacPorts). It is better tested than llvm-8, and no advantages with the latter.
Notice, it has its own assembler which Iain written, and I can confirm it works perfectly fine.
I have switched my fork to
llasby default.Iain’s LLVM 7.1.1 does support ppc64, AFAIK, though personally I only tested using llas for ppc32. I did build his LLVM for ppc64 though, so that works for sure.
Clang is broken for Darwin ppc, do not use it. Until Iain releases his llvm/clang 11.
It was a regression from ld64-97 though. I would advise avoiding v127, it has bugs, especially for ppc64.
Iain’s
darwin-xtoolshave much newer ld64 with restored ppc/ppc64 support. You may want to try those.@iains @catap Tagging you for clang and cctools.
@Jazzzny @glebm Re cross-compiler.
Huh, interesting... And I am not sure which version was on my Tiger Mac where I successfully built everything locally with GCC-7. And I attempted to build the cross compiling toolchain, but failed. First attempt resulted semi-working toolchain, but I had or LD crashed on attempt to build with shared links, or produced build was broken, or attempting to build CMake project by that toolchain resulted lots of missing heads and libs even I explicitly pointed the sysroot...
@Wohlstand I can’t say much about cross-compiling, on that @Jazzzny can respond, perhaps, but natively on Darwin v97 was the best of Apple ones.
Iain has a much newer ld64, which does work on 10.6.8 ppc (and should work on 10.5.8), but I am not sure what its status on 10.4.
The 10.4u SDK works fine to make a modern GCC and xtools 2.2.0 cross compiling environment (powerpc-apple-darwin8.11.0), though LD needs a patch to comment out a non-fatal "error". In fact, the 10.3 SDK also works to make a powerpc-apple-darwin7.9.0 GCC compiler. With the 10.4 and 10.3 SDKs, GCC can target 10.0 for standard C code (with -lSystemStubs) and 10.3 for C++ code, as thats the minimum that libstdc++ will compile for.
These assume native Darwin, but may still be useful to be tweaked for Linux.
github.com/macos-powerpc/powerpc-ports@ccd819bc18/devel/darwin-xtools(three versions via port variants, optional support for tapi)github.com/macos-powerpc/powerpc-ports@ccd819bc18/devel/cctools(variants +llvmppc +llas use LLVM 7.1.1)github.com/macos-powerpc/powerpc-ports@ccd819bc18/devel/ld64(use eitherld64-97 +llvmppcwithld64 +ld64_97, orld64 +ld64_xtools)github.com/macos-powerpc/powerpc-ports@ccd819bc18/devel/libtapi(tapi based on LLVM 7.1.1; newer version is moved tolibtapi-devel)github.com/macos-powerpc/powerpc-ports@ccd819bc18/lang/llvm-powerpc(LLVM 7.1.1)Thanks @barracuda156 , @Jazzzny . That's a lot of useful information. 10.4.x support seems to be pretty low-priority given its age, so it's difficult to find what works and what doesn't without experimentation...
I was just using llvm 7.1.1 upstream for dsymutil and falling back on @Wohlstand 's forward-ported changes for the remaining cctools with iains' gcc-13 and gcc-14 forks, but it seems like actually testing this on 10.4.11 PPC on qemu, applications throw a Bus Error with EXC_BAD_ACCESS / KERN_PROTECTION_FAILURE. I'll give darwin-xtools a shot and update my Dockerfile accordingly when I get everything working.
@VariantXYZ If everything crashes with Bus error, then certainly something is very wrong in the set-up. (Some apps will crash with this because they have bugs in their code, so just getting this with something does not yet mean that toolchain is broken.)
BTW, standard MacPorts’ cctools and ld in their present default variants should work normally on
ppcas well (not onppc64). Ifxtoolslinker won’t work in your set-up, revert told64-97, it is old, but robust.Sorry if I made it seem like the issue was related to the tools, this is definitely an issue with my setup. I think this is a given, since I'm using a fork of cctools that was mostly created as an experiment and not fully tested.
Will give cross-compiling these a shot.
I wonder though, wouldn't the upstream llvm-7.1.1 tools or iains' llvm-7 branch work just as well for a cross-compiled cctools for ppc?
Edit: Woops, never mind, that doesn't include ld.
@Jazzzny , in your example, where did you build
ldfrom? It doesn't seem like darwin-xtools is setup to build for a linux host targeting powerpc-apple-darwin8... or maybe I'm misunderstanding.My apologies - this cross compiler is set up on a macOS 15 ARM64 host. xtools itself doesn't need a special target, and it should be built for the host, but I'm not sure if it is set up to compile on Linux.
Edit: by the way, GCC's libraries (libstdc++, libfortran, etc.) should be compiled with mmacosx-version-min set if you are using an SDK newer than the desired minimum target - otherwise the libraries will build with incorrect assumptions, like symbol and load command availability.
Ah, understood... building on Linux seems to hit a lot of issues with missing headers, but that might be something I can open up a ticket for in the darwin-xtools repo itself after I sanity check a bit more.
Right, I do configure that flag here: https://github.com/VariantXYZ/gcc-powerpc-apple-darwin8/blob/main/.github/workflows/Dockerfile#L111
https://github.com/tpoechtrager/cctools-port/tree/877.8-ld64-253.9-ppc
This is I think the same ld64 version as darwin-xtools, but it runs on Linux. The whole thing doesnt build though, since it tries to build ld_classic and that doesn't work, but you can build just ld64 by running configure and then cd to the ld64 directory and run make, ld will be in cctools/ld64/src/ld/ld.
I haven't used the old ld-97, I might try later to see if it's more stable.
I wasn't aware that Iain was working on backporting ppc darwin support to llvm 11, I might wait until that's finished to try the LLVM 20 port, since it would probably save me some work.
-DCCTOOLS_LD_CLASSIC=OFFfordarwin-xtoolsbuild (or a corresponding in makefiles-based build system).According to that one comment from tpoechtrager upstream only works for simple sources. I haven't tested Iain's forks yet.
He works on that, but there is no timeline (or at least I am not aware of it). I had an impression that it is not to be expected very soon, though better ask him directly.
Upstream LLVM never generated correct code, AFAIK, even if the thing itself builds.
Interestingly enough, it seems to build fine without any changes:
Though, it seems to not play well with GCC 13.3, since the driver seems to pass it
-platform_versionand it has no idea how to interpret it:Clang has a command line argument
-mlinker-version=253.9, try that with GCC.You need to delete a few lines from GCC's configure script by following https://github.com/macos-powerpc/macos-powerpc-cross-compiler/blob/main/patches/gcc-patch-configure.patch
This is because GCC seemingly assumes that these are available based on the linker that was used to link GCC, rather than the specified linker.
No such luck.
Will try this. As an aside, it should just be possible to forcibly override these with CONFIG_SITE, I think?
Horray, it seems to all work. Here's GCC13.3 + SDK 10.4u: https://github.com/VariantXYZ/gcc-powerpc-apple-darwin8/blob/build/gcc-13.3%2BMacOSXSDK10.4u/.github/workflows/Dockerfile
The rgbds toolchain seems to work with that, I'm testing cpython 3.12 against GCC14.2 + 10.5 now.
Now someone should make a cross-compiler from macOS PowerPC to Linux RISC-V :)
P. S. I could actually even use it sensibly, since PineTab-V is pretty slow, and at least in some cases G5 will be faster.
Well, it builds and doesn't immediately bus error, so that's a start. It's failing due to expecting some things that just aren't in the 10.4 SDK, but this is sufficient for now to verify things can build and seemingly run correctly, at least.
Macports has gcc 14 builds for ppc so you could probably modify those to cross compile to riscv linux
@Un1q32 Given that I had the current gcc (from gcc11 every version onwards, currently incl. gcc15) on powerpc via MacPorts two years before MacPorts upstream finally did that, I know :)
LLVM 20 branch is scheduled to be created tomorrow IIRC, I have school stuff so I won't be able to do much right away, in the mean time can someone tell me where I can get source code for ld-97.
Original: https://github.com/apple-oss-distributions/ld64/tree/ld64-97.17
Patches: https://github.com/macports/macports-ports/tree/master/devel/ld64
No linux port? I guess I'll make it myself
I am not sure it is needed. Usually whatever important (for development, at least) from MacPorts does not build from default portfiles on Linux, it is found fixed here: https://github.com/RJVB/lnxports
@RJVB will know better. My exposure to Linux is extremely limited.
The project claims to support Linux, but not why. Cross-building would be the only reason I can see.
My
lnxportsrepo basically only contains ports for which I have or had a need and that were too complex and/or different from the Mac implementation to make a single multi-platform port, or simply cannot be supported on Mac.Yes I intend to cross build, I have a whole repo of build scripts for modern unix software that builds for iOS 3, OSX 10.6 for x86, and hopefully soon OSX 10.5 for PowerPC.
I tried diffing iains llvm 8 repo with upstream and merging the changes into llvm 20, but there seems to be a lot of powerpc darwin stuff that hadn't been removed by llvm 8 but was removed since, so I'll probobly wait for the llvm 11 release from iains or maybe try to step up versions one at a time (get it working in llvm 9, then 10, etc).
@Un1q32 It is probably not hard to find commits removing Darwin support:
https://reviews.llvm.org/D75494
https://reviews.llvm.org/D146459
https://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20200120/732917.html
Or perhaps pick LLVM prior to that being removed.
P. S. Would be cool to convince upstream to restore it, but we have to do the work, if they agree.
there's more needed than just bringing the patches forward (although that should work as far as the MC layer is concerned - so to provide the assembler etc.). It is better to go one patch at a time and make sure you understand what the patch is supposed to do and that it still works when applied to the later version.
re-instating powerpc-darwin upstream has two large obstacles (which is why it was removed in the first place)
2a) they want a guarantee that someone works actively on it to fix problems (which is fine if it's $dayjob but not viable for $hobby)
2b) they want a usable build-bot .. which is extremely hard to arrange given how little hardware is available and how slow it is.
Given the discussions on cross-compilation that've been happening:
Regarding this, the issue is primarily testing right? This could be a "target, but not host" scenario where the toolchain is built on a linux host and testing could be done against a QEMU implementation of the device, maybe? Or is this an unacceptable solution to this obstacle?
Of course, the maintenance task is undoubtedly the bigger hurdle...
On my end, I have real hardware, the Mac Mini G4, and so, I want to debug on it easier. Development on itself is not so comfortable because of long build (just one single core CPU and low tact frequency, my project that builds on my main PC in 2-3 minutes, on Mac Mini the complete build takes half of hour 👀)
If for some reason we're required to run a toolchain on-device my previously mentioned repo of cross build scripts has ones for libc++, llvm, and clang (all latest versions), so you won't have to wait multiple days to get a toolchain built.
I plan to eventually provide prebuilt binaries for OSX (currently only iOS has them) and maybe even automate builds somehow.
@iains Yeah, forward-porting patches did not work for
libc++[abi](from 7.x to 11.x) for me. I did not have time to look into the issue yet (so maybe it is something totally trivial), but looks like changes since 7.x were significant.Darwin ppc doesn’t change much (maximum what might happen is restoring ppc64 into 10.6), so once it is fixed once, it probably will not require constant fix-ups. At what rate the upstream wants to break things, after all.
Shouldn’t 10.5 or/and 10.6 with Rosetta work for that? On a reasonably fast Intel machine Rosetta works decently (and something like MacMini suffices). And perhaps it is not necessary to run the builds per-commit.
This would be awesome.
I can work on some components then (not codegen but something less esoteric), and maybe Kirill @catap extends his fixes for
compiler-rtto PowerPC (on which I can work together with him).