iains / gcc-darwin-arm64

GCC master branch for Darwin with experimental support for Arm64. Currently GCC-15.0.0 [September 2024]
GNU General Public License v2.0
268 stars 33 forks source link

Error when building this project on Linux with osxcross #102

Closed shepherdjerred closed 1 year ago

shepherdjerred commented 1 year ago

Hello! To start out, thanks for the work you've done on this project.

Sorry that I can't be more detailed/precise. I have very little knowledge of GCC/compilers.

I'm using the osxcross project to build binaries targeting macOS on Linux. The project builds cctools, which are then used when compiling GCC. I'm trying to modify the project to support building binaries for macOS arm64 using this branch of GCC. I've modified the project to clone this repository and run the following commands to build GCC:

LANGS="c,c++,objc,obj-c++,fortran"

EXTRACONFFLAGS=""
# this should tell GCC to use the copies of `ld` and `as` we've built that run on linux
EXTRACONFFLAGS+="--with-ld=$TARGET_DIR/bin/aarch64-apple-darwin22-ld "
EXTRACONFFLAGS+="--with-as=$TARGET_DIR/bin/aarch64-apple-darwin22-as "
EXTRACONFFLAGS+="--disable-multilib "

../configure \
  --target=aarch64-apple-darwin22 \
  --with-sysroot=$SDK \ # this points to an extract xcode sdk
  --disable-nls \
  --enable-languages=$LANGS \
  --without-headers \
  --enable-lto \
  --enable-checking=release \
  --disable-libstdcxx-pch \
  --prefix=$TARGET_DIR \
  --with-system-zlib \
  $EXTRACONFFLAGS

$MAKE -j$JOBS
$MAKE install

GCC fails with the following error:

ld: building for macOS, but linking in object file built for iOS, file '_muldi3_s.o' for architecture arm64

I believe this may be related to this statement in darwinpcs.md:

[2] Refers to the darwinpcs as "iOS" which was the first Darwin OS variant implementing it, however it is stated (albeit unofficially?) that Arm64 macOS will adopt the same ABI and is expected to be able to execute iOS executables. So, for the present, 'iOS' is considered to be equivalent to 'macOS' (generically 'Darwin').

I know that this project is completely unrelated from the osxcross project. I was hoping there would be an easy way to change the objects that GCC is outputting, so that they are identified as macOS rather than iOS, so that ld correctly links.

shepherdjerred commented 1 year ago

Managed to get this working: https://github.com/tpoechtrager/osxcross/pull/376

There are a ton of warnings about linking to iOS, but the binaries seem to work fine. @iains if you have a little bit of time, could you give me some advice on how to resolve this warning? It'd make it much nicer when using this project as a cross-compiler on Linux :)

ld: building for macOS, but linking in object file built for iOS, file '_muldi3_s.o' for architecture arm64

I've changed that error to a warning in the ld source with this patch:

diff --git a/cctools/ld64/src/ld/PlatformSupport.cpp b/cctools/ld64/src/ld/PlatformSupport.cpp
index 4869542..e081478 100644
--- a/cctools/ld64/src/ld/PlatformSupport.cpp
+++ b/cctools/ld64/src/ld/PlatformSupport.cpp
@@ -105,7 +105,7 @@ void VersionSet::checkObjectCrosslink(const VersionSet& objectPlatforms, const s
                 if (enforce == PlatEnforce::warnInternalErrorExternal) {
                     enforce = (internalSDK ? PlatEnforce::warning : PlatEnforce::error);
                 }
-                if ( platformMismatchesAreWarning && (enforce == PlatEnforce::error) )
+                if ( true && (enforce == PlatEnforce::error) )
                     enforce = PlatEnforce::warning;
                 switch (enforce) {
                     case PlatEnforce::allow:
shepherdjerred commented 1 year ago

Managed to get this working. I needed to set MACOSX_DEPLOYMENT_TARGET before configuring/building GCC. Proof-of-concept here: https://github.com/shepherdjerred/macos-cross-compiler