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

Linker issue with Xcode 15/Ada #116

Closed simonjwright closed 11 months ago

simonjwright commented 11 months ago

See GCC PR 111481.

We no longer (at least since gcc version 14.0.0 20230820) have the -macosx_version_min issue. We do have the ld crash with Ada (the -Wl,-ld_classic workaround works).

For both C and Ada, we now get ld: warning: ignoring duplicate libraries: '-lgcc', as below:

$ /opt/gcc-14.0.0-aarch64/bin/gcc hello.c -Wl,-v
collect2 version 14.0.0 20230820 (experimental)
/usr/bin/ld -demangle -syslibroot /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/ -dynamic -arch arm64 -platform_version macos 13.0.0 0.0 -o a.out -L/opt/homebrew/lib -L/opt/gcc-14.0.0-aarch64/lib/gcc/aarch64-apple-darwin21/14.0.0 -L/opt/gcc-14.0.0-aarch64/lib/gcc/aarch64-apple-darwin21/14.0.0/../../.. /var/folders/ch/k_zwspdx3qsfbt1_x21zld6m0000gn/T//ccv24cIu.o -v -lemutls_w -lgcc -lSystem -lgcc -no_compact_unwind
@(#)PROGRAM:ld  PROJECT:dyld-1015.7
BUILD 18:48:48 Aug 22 2023
configured to support archs: armv6 armv7 armv7s arm64 arm64e arm64_32 i386 x86_64 x86_64h armv6m armv7k armv7m armv7em
will use ld-classic for: armv6 armv7 armv7s arm64_32 i386 armv6m armv7k armv7m armv7em
LTO support using: LLVM version 15.0.0 (static support for 29, runtime is 29)
TAPI support using: Apple TAPI version 15.0.0 (tapi-1500.0.12.3)
Library search paths:
    /opt/homebrew/lib
    /opt/gcc-14.0.0-aarch64/lib/gcc/aarch64-apple-darwin21/14.0.0
    /opt/gcc-14.0.0-aarch64/lib/gcc/aarch64-apple-darwin21/14.0.0/../../..
Framework search paths:
ld: warning: ignoring duplicate libraries: '-lgcc'

What's the best approach for reporting the ld crash to Apple? (if they don't know about it already). I'd imagine they'd appreciate a set of binary objects to feed into ld?

If there's no timely response, we could update the specs?

iains commented 11 months ago

my understanding is that the linker crash has been fixed and will hopefully be in the next dot release.

I'll take a look at why we're getting the duplicate library warning (we might well be intentionally placing libgcc twice on the command line, since libraries are usually positional in terms of search order). I know that ld (ld64 as well as the new one) will re-visit libraries to satisfy dependencies, but I am not sure that means the order is no longer relevant. I take it that this is an inconvenience, not a show-stopper?

simonjwright commented 11 months ago

The duplicate library warning is definitely not a showstopper!

iains commented 11 months ago

The duplicate library warning is definitely not a showstopper!

I think I've a fix for this tho - and I do have a recipe for building Ada with a bootstrap compiler that was built against 14.3 but then using XC15 ld-classic for the new compiler. Although, given that we expect a fixed XC15.x, I would suggest just leaving 14.3 in place (or putting it back and just using the XC15 Somoma SDK) until there's a working 15

simonjwright commented 11 months ago

I think staying with/reverting to 14.3 is the best option (I hope that'll stop Software Update pestering me to upgrade!)

simonjwright commented 11 months ago

For info. The listings below are for GCC 13.1.0/aarch64, but the same behaviour happens with 12.2.0/x86_64 and 13.1.0/x86_64 (under Rosetta, I don't have an x86_64 machine that can run Ventura/CLT15.0)

Linking a C program doesn't crash; these are the ld switches:

/usr/bin/ld \
-syslibroot \
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/ \
-dynamic \
-arch \
arm64 \
-macosx_version_min \
13.0.0 \
-o \
a.out \
-L/opt/homebrew/lib \
-L/opt/gcc-13.1.0-aarch64/lib/gcc/aarch64-apple-darwin21/13.1.0 \
-L/opt/gcc-13.1.0-aarch64/lib/gcc/aarch64-apple-darwin21/13.1.0/../../.. \
/var/folders/ch/k_zwspdx3qsfbt1_x21zld6m0000gn/T//ccto2eQX.o \
-v \
-lemutls_w \
-lgcc \
-lSystem \
-lgcc \
-no_compact_unwind

Linking an Ada program against the static Ada runtime (the default, -bargs -static) crashes:

/usr/bin/ld \
-syslibroot \
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/ \
-dynamic \
-arch \
arm64 \
-macosx_version_min \
13.0.0 \
-o \
hello \
-L./ \
-L/opt/gcc-13.1.0-aarch64/lib/gcc/aarch64-apple-darwin21/13.1.0/adalib/ \
-L/opt/homebrew/lib \
-L/opt/gcc-13.1.0-aarch64/lib/gcc/aarch64-apple-darwin21/13.1.0 \
-L/opt/gcc-13.1.0-aarch64/lib/gcc/aarch64-apple-darwin21/13.1.0/../../.. \
b~hello.o \
./hello.o \
-v \
/opt/gcc-13.1.0-aarch64/lib/gcc/aarch64-apple-darwin21/13.1.0/adalib/libgnat.a \
-lemutls_w \
-lgcc \
-lSystem \
-lgcc \
-no_compact_unwind

Linking an Ada program against the shared Ada runtime (-bargs -shared) succeeds!

/usr/bin/ld \
-syslibroot \
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/ \
-dynamic \
-arch \
arm64 \
-macosx_version_min \
13.0.0 \
-o \
hello \
-L./ \
-L/opt/gcc-13.1.0-aarch64/lib/gcc/aarch64-apple-darwin21/13.1.0/adalib/ \
-L/opt/homebrew/lib \
-L/opt/gcc-13.1.0-aarch64/lib/gcc/aarch64-apple-darwin21/13.1.0 \
-L/opt/gcc-13.1.0-aarch64/lib/gcc/aarch64-apple-darwin21/13.1.0/../../.. \
b~hello.o \
./hello.o \
-v \
-rpath \
/opt/gcc-13.1.0-aarch64/lib/gcc/aarch64-apple-darwin21/13.1.0/adalib/ \
-rpath \
/opt/gcc-13.1.0-aarch64/lib \
-lgnat-13 \
-lemutls_w \
-lgcc \
-lSystem \
-lgcc \
-no_compact_unwind
simonjwright commented 11 months ago

Oh dear, it looks as though any static library triggers the crash.

iains commented 11 months ago

I'm not entirely sure what the second part of this is reporting - i.e. is it something new or another manifestation of the xc15 linker's issues (I believe HB have reported more issues than the original crash)

iains commented 11 months ago

So I just pushed a rebase that should fix the duplicate library issue, and the linker issue is not actually "our bug", so the question is can you identify what you are reporting in the other crash (and with which tools?)

simonjwright commented 11 months ago

I'm not entirely sure what the second part of this is reporting - i.e. is it something new or another manifestation of the xc15 linker's issues (I believe HB have reported more issues than the original crash)

I’m sorry, it’s just a more detailed report of the same 15.0 linker issues.

I was hoping that using the shared GNAT runtime would be a (temporary) fix for users, but no, it seems that any static library triggers the issue.

iains commented 11 months ago

OK - so, as far as this issue goes;

  1. the linker bug is not fixable by us - but there's a work-around (which should allow Ada to work 'normally' - if not then please report). IFF you need to use an older gnatmake which was built against 14.3, I do have a horrible configure line that allows for this (but you need to re-install the 14.3 Xcode CLT somewhere to use it).

  2. I have pushed a fix for the duplicate library warning.

So, unless there's any remaining fallout from (1) we should be done here?

simonjwright commented 11 months ago

Agreed, thanks