simonjwright / distributing-gcc

Binary releases of GCC (native and cross) on macOS; also, the scripts/Makefiles used for producing them.
BSD 3-Clause "New" or "Revised" License
40 stars 0 forks source link

Linker Issues for Ada Code #3

Closed wiremoons closed 2 years ago

wiremoons commented 2 years ago

Hi @simonjwright

I have installed gcc-11.2.0-x86_64-apple-darwin15.pkg from your Releases page.

This completes ok, and I have updated my path too ensure the installed GNAT compiler and tools are the found first.

When I try to compile a simple Ada program with the command: gnatmake -g hello_world.adb such as:

-- hello_world.adb

with Ada.Text_IO;

procedure hello_world is
begin
   Ada.Text_IO.Put_Line ("Hello World!");
   Ada.Text_IO.Put ("It's a wonderful day");
   Ada.Text_IO.New_Line;
end hello_world;

I am getting the following error:

GNATMAKE 12.0.1 20220214 (experimental)
Copyright (C) 1992-2022, Free Software Foundation, Inc.
  "hello_world.ali" being checked ...
End of compilation
  "hello_world" missing.
gnatbind -x hello_world.ali
gnatlink hello_world.ali -g
ld: library not found for -lSystem
collect2: error: ld returned 1 exit status
gnatlink: error when calling /opt/gcc-12.0.1/bin/gcc
gnatmake: *** link failed.

The computer is a Mac mini M1 with the versions shown below installed. I have the Xcode Command Line Tools installed (ie not the full XCode suite) - just in case that makes a difference with the linker and the provided GNAT/gcc compiler perhaps?

Let me know if you need any further outputs to help debug the issue.

Thanks

Simon

% sw_vers 
ProductName:    macOS
ProductVersion: 12.3.1
BuildVersion:   21E258

% xcode-select -version
xcode-select version 2395.

% gcc -v                             
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/opt/gcc-12.0.1/libexec/gcc/x86_64-apple-darwin15/12.0.1/lto-wrapper
Target: x86_64-apple-darwin15
Configured with: /Volumes/Miscellaneous1/src/gcc/configure --prefix=/opt/gcc-12.0.1 --without-libiconv-prefix --disable-libmudflap --disable-libstdcxx-pch --disable-libsanitizer --disable-libcc1 --disable-libcilkrts --disable-multilib --disable-nls --enable-languages=c,c++,ada --host=x86_64-apple-darwin15 --target=x86_64-apple-darwin15 --build=x86_64-apple-darwin15 --without-isl --with-build-sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk --with-sysroot= --with-specs='%{!sysroot=*:--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk}' --with-build-config=no --disable-bootstrap
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.0.1 20220214 (experimental) (GCC)

% gnat -v      
GNAT 12.0.1 20220214 (experimental)
Copyright 1996-2022, Free Software Foundation, Inc.

To list Ada build switches use --help-ada

List of available commands

gnat bind               gnatbind
gnat chop               gnatchop
gnat clean              gnatclean
gnat compile            gnatmake -f -u -c
gnat check              gnatcheck
gnat elim               gnatelim
gnat find               gnatfind
gnat krunch             gnatkr
gnat link               gnatlink
gnat list               gnatls
gnat make               gnatmake
gnat metric             gnatmetric
gnat name               gnatname
gnat preprocess         gnatprep
gnat pretty             gnatpp
gnat stack              gnatstack
gnat stub               gnatstub
gnat test               gnattest
gnat xref               gnatxref

Report bugs to report@adacore.com

% clang -v
Apple clang version 13.1.6 (clang-1316.0.21.2)
Target: arm64-apple-darwin21.4.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin

% env
HOME=/Users/simon
HOMEBREW_CELLAR=/opt/homebrew/Cellar
HOMEBREW_NO_ANALYTICS=1
HOMEBREW_PREFIX=/opt/homebrew
HOMEBREW_REPOSITORY=/opt/homebrew
HOSTNAME=minimoons.local
INFOPATH=/opt/homebrew/share/info:
LANG=en_GB.UTF-8
LOCALE=en_GB.utf8
LOGNAME=simon
LaunchInstanceID=EC051FE3-FCBC-42A0-8858-EC1213585C4C
MANPATH=/opt/homebrew/share/man:/usr/local/share/man:/usr/share/man:/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/share/man:
OLDPWD=/opt
PATH=/Users/simon/GenIsys-macOS/assets:/opt/gcc-12.0.1/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/Developer/CommandLineTools/usr/bin:/Users/simon/Library/Python/3.8/bin
PKG_CONFIG_PATH=/opt/homebrew/lib/pkgconfig
PWD=/Users/simon/projects/ada/starter-code
SHELL=/bin/zsh
SHLVL=1
TERM=xterm-256color
TERM_PROGRAM=Apple_Terminal
TERM_PROGRAM_VERSION=444
TMPDIR=/var/folders/dv/nf3vf1xj46lckqgbjm12l9yw0000gn/T/
TZ=:Europe/London
USER=simon
XPC_FLAGS=0x0
XPC_SERVICE_NAME=0
_=/usr/bin/env
__CFBundleIdentifier=com.apple.Terminal
simonjwright commented 2 years ago

This is because of issue #2 -- you’ll see the giveaway x86_64 in your comments.

I’m so sorry to have put you to this trouble.

I guess you’d prefer to wait for a proper release, but for the moment you could build with the added switches

-largs -L$(xcrun --show-sdk-path)/usr/lib

to pick up the Command Line Tools version of the system libraries.

When I do make the proper release, it’ll automatically recognise when you have the CLTs installed and not just the full Xcode.

wiremoons commented 2 years ago

Hi @simonjwright

Thanks for getting back to me.

This is because of issue #2 -- you’ll see the giveaway x86_64 in your comments.

Well spotted - I missed that! I assume it is the Target: x86_64-apple-darwin15 part of the output from the gcc -v command you have noticed?

I’m so sorry to have put you to this trouble.

It is no trouble at all - I am grateful you have put this together, so anything I can help with is the least I can do.

I guess you’d prefer to wait for a proper release, but for the moment you could build with the added switches

-largs -L$(xcrun --show-sdk-path)/usr/lib

Thanks for the fix for the linker part 👍 I have now re-run with the command:

% gnatmake -g hello_world.adb -largs -L$(xcrun --show-sdk-path)/usr/lib 
gcc -c -g hello_world.adb
gnatbind -x hello_world.ali
gnatlink hello_world.ali -g -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib

and that works well, and the program compiles and runs too now.

As you have pointed out is it is building x86:

% otool -L ./hello_world
./hello_world:
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.100.3)

% file hello_world
hello_world: Mach-O 64-bit executable x86_64

When I do make the proper release, it’ll automatically recognise when you have the CLTs installed and not just the full Xcode.

For the release you have made, it is clearly designated as 'pre-release' so this is a good time to iron out any issues that can be found, so is worth it I think to do some test installs, get feedback, etc.

If you want me to test anything else just let me know. I was considering trying to do a build using your Github scripts — but I expect I would be getting way ahead of myself knowledge and experience wise, as it all looks quite involved! I guess the hardest part is getting the first native GNAT version for arm64 (Apple Silicon), to build everything that follows!

Anyway - thanks again, just let me know if you want me to check anything else that would help to test things out.

Cheers

Simon

wiremoons commented 2 years ago

Hi @simonjwright

Just to let you know I have installed the new pre-release aarch64-apple-darwin21-2 and it works fine now 👍

Install is to the stated installer directory, and it alls works fine still if you change it to a new directory name (only if needed of course).

I have recompiled the same code as above, and it produces native arm64 binary files, and no linker issues either:

% gnatmake -g hello_world.adb
gcc -c -g hello_world.adb
gnatbind -x hello_world.ali
gnatlink hello_world.ali -g

% ./hello_world 
Hello World!
It's a wonderful day

% file hello_world
hello_world: Mach-O 64-bit executable arm64

% otool -L hello_world
hello_world:
    @rpath/libgcc_s.1.1.dylib (compatibility version 1.0.0, current version 1.1.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1311.100.3)

Thank you again for your help, and for building this native Apple Silicon version!

Simon

simonjwright commented 2 years ago

Thanks very much for the feedback!

I guess the hardest part is getting the first native GNAT version for arm64 (Apple Silicon), to build everything that follows!

Yes. I’m going to write it up (RSN). You can see some of the saga here.

Fixed in b9b013b.