Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

GNAT linking and macOS

180 views
Skip to first unread message

moi

unread,
Sep 27, 2023, 3:30:22 PM9/27/23
to
I installed 14.0, Sonoma, on my M1 Mac last night.

The good news:

Using GNAT 12.2.0, it all just works, *so long as* I REMOVE
'-largs -Wl,-ld_classic' from the linker options!

--
Bill F.

Simon Wright

unread,
Sep 28, 2023, 9:32:50 AM9/28/23
to
Likewise, but that didn't work for me.

It turns out there's an environment variable DEFAULT_LINKER, which with
the 15.0 CLT would be set to

export DEFAULT_LINKER=/Library/Developer/CommandLineTools/usr/bin/ld-classic

(the Xcode equivalent is much longer & more inscrutable)

I haven't tried this.

Simon Wright

unread,
Sep 28, 2023, 5:00:33 PM9/28/23
to
Simon Wright <si...@pushface.org> writes:

> moi <findl...@blueyonder.co.uk> writes:
>
>> I installed 14.0, Sonoma, on my M1 Mac last night.
>>
>> The good news:
>>
>> Using GNAT 12.2.0, it all just works, *so long as* I REMOVE
>> '-largs -Wl,-ld_classic' from the linker options!
>
> Likewise, but that didn't work for me.

You can't reinstall the 14.3 CLT under Sonoma (it's "too old"). I
reinstalled from a Time Machine backup, but if you don't have that set
up I'd recommend taking a copy of /Library/Developer/CommandLineTools
before updating to 15.0.

> It turns out there's an environment variable DEFAULT_LINKER, which with
[...]
> I haven't tried this.

This affects building the compiler, not using it.

hn...@yahoo.de

unread,
Sep 29, 2023, 4:19:08 PM9/29/23
to

hn...@yahoo.de

unread,
Sep 29, 2023, 4:26:21 PM9/29/23
to
On Thursday, September 28, 2023 at 11:00:33 PM UTC+2, Simon Wright wrote:
What exactly is meant by "Using GNAT 12.2.0"? I put gcc-13.2.0 in ~/.zshrc.
Then I got Could not locate executable on path: gprbuild.
What do i miss?

moi

unread,
Sep 29, 2023, 8:51:45 PM9/29/23
to
It means using the version that announces itself
at the head of the source listing as:

"GNAT 12.2.0
Copyright 1992-2022, Free Software Foundation, Inc."

What exactly is meant by "I put gcc-13.2.0 in ~/.zshrc"?

--
Bill F.

Kenneth Wolcott

unread,
Sep 29, 2023, 10:30:29 PM9/29/23
to
Hi Simon;

>I'd recommend taking a copy of /Library/Developer/CommandLineTools
> before updating to 15.0.

Well, I should have done this, but I didn't...

> > It turns out there's an environment variable DEFAULT_LINKER, which with

I tried this (xport DEFAULT_LINKER=/Library/Developer/CommandLineTools/usr/bin/ld-classic) and it did not help:

Using:

/opt/gcc-13.1.0-aarch64/bin/gnatmake --version
GNATMAKE 13.1.0

-- This is from Rosetta Code:

with Ada.Text_IO; use Ada.Text_IO;

procedure Test_Short_Circuit is
function A (Value : Boolean) return Boolean is
begin
Put (" A=" & Boolean'Image (Value));
return Value;
end A;
function B (Value : Boolean) return Boolean is
begin
Put (" B=" & Boolean'Image (Value));
return Value;
end B;
begin
for I in Boolean'Range loop
for J in Boolean'Range loop
Put (" (A and then B)=" & Boolean'Image (A (I) and then B (J)));
New_Line;
end loop;
end loop;
for I in Boolean'Range loop
for J in Boolean'Range loop
Put (" (A or else B)=" & Boolean'Image (A (I) or else B (J)));
New_Line;
end loop;
end loop;
end Test_Short_Circuit;

gnatmake test_short_circuit.adb
gcc -c test_short_circuit.adb
gnatbind -x test_short_circuit.ali
gnatlink test_short_circuit.ali
-macosx_version_min has been renamed to -macos_version_min
ld: warning: ignoring duplicate libraries: '-lgcc'
0 0x10306b648 __assert_rtn + 72
1 0x102f9ffac ld::AtomPlacement::findAtom(unsigned char, unsigned long long, ld::AtomPlacement::AtomLoc const*&, long long&) const + 1204
2 0x102fb5924 ld::InputFiles::SliceParser::parseObjectFile(mach_o::Header const*) const + 15164
3 0x102fc304c ld::InputFiles::parseAllFiles(void (ld::AtomFile const*) block_pointer)::$_7::operator()(unsigned long, ld::FileInfo const&) const + 960
4 0x18e36d950 _dispatch_client_callout2 + 20
5 0x18e3821a4 _dispatch_apply_invoke_and_wait + 176
6 0x18e381464 _dispatch_apply_with_attr_f + 1176
7 0x18e381650 dispatch_apply + 96
8 0x10303d3b8 ld::AtomFileConsolidator::parseFiles(bool) + 292
9 0x102fde170 main + 9048
ld: Assertion failed: (resultIndex < sectData.atoms.size()), function findAtom, file Relocations.cpp, line 1336.
collect2: error: ld returned 1 exit status
gnatlink: error when calling /opt/gcc-13.1.0-aarch64/bin/gcc
gnatmake: *** link failed.

Are there any other workarounds to solve the inability to link? This does not only adversely affect Ada, but everything that uses a linker, BTW.

Thanks,
Ken Wolcott

Simon Wright

unread,
Sep 30, 2023, 9:55:14 AM9/30/23
to
Kenneth Wolcott <kenneth...@gmail.com> writes:

>> > It turns out there's an environment variable DEFAULT_LINKER, which with
>
> I tried this (xport
> DEFAULT_LINKER=/Library/Developer/CommandLineTools/usr/bin/ld-classic)
> and it did not help:

As I said above, this only affects building GCC, not using it. Sorry.

> Are there any other workarounds to solve the inability to link? This
> does not only adversely affect Ada, but everything that uses a linker,
> BTW.

I have some evidence that the issue only arises with static
libraries. Not much help.

We're hoping that the 15.1 release of Command Line Tools fixes this. In
the meantime,

(1) using gnatmake, or gprbuild without changing the GPR:

$ gnatmake foo.adb -largs -Wl,-ld_classic
or
$ gprbuild -P foo -largs -Wl,-ld_classic

(2) modifying the GPR by adding a new package Linker:

package Linker is
for Default_Switches ("ada") use ("-Wl,-ld_classic");
end Linker;

(3) if you already have a package Linker, modify as above.

Simon Wright

unread,
Sep 30, 2023, 10:20:27 AM9/30/23
to
"hn...@yahoo.de" <hn...@yahoo.de> writes:

> What exactly is meant by "Using GNAT 12.2.0"? I put gcc-13.2.0 in ~/.zshrc.
> Then I got Could not locate executable on path: gprbuild.
> What do i miss?

First, I asked above where you got GCC 13.2.0 from; you certainly didn't
get it from one of my builds.

If you got it via Homebrew, then be aware that homebrew's gcc *does*
*not* *support* *Ada* (or gprbuild).

There are two ways I know of for getting hold of GNAT and gprbuild:

(1) go to https://alire.ada.dev/docs/#introduction and follow the steps
at 'alr for macOS', then 'First steps' ... This provides GCC 12.2.0 for
x86_64 (intel), which runs on an M1/M2 mac under Rosetta.

(2) go to my release page at
https://github.com/simonjwright/distributing-gcc/releases and download

for Intel:
https://github.com/simonjwright/distributing-gcc/releases/tag/gcc-13.1.0-x86_64

for M1/M2:
https://github.com/simonjwright/distributing-gcc/releases/tag/gcc-13.1.0-aarch64-2

(in both cases, the actual download is found under Assets at the bottom
of the page; but please read the release notes for what's included and
how to install).

Kenneth Wolcott

unread,
Sep 30, 2023, 7:57:59 PM9/30/23
to
Hi Simon;

> We're hoping that the 15.1 release of Command Line Tools fixes this.

+1

> In the meantime,
>
> (1) using gnatmake, or gprbuild without changing the GPR:
>
> $ gnatmake foo.adb -largs -Wl,-ld_classic
> or
> $ gprbuild -P foo -largs -Wl,-ld_classic
>
> (2) modifying the GPR by adding a new package Linker:
>
> package Linker is
> for Default_Switches ("ada") use ("-Wl,-ld_classic");
> end Linker;
>
> (3) if you already have a package Linker, modify as above.

I chose option #1a...

Using the Turtle Graphics Rosetta Code example for Ada, I was able to get a successful compile+link:

gnatmake main.adb -largs -Wl,-ld_classic
gcc -c main.adb
gnatbind -x main.ali
gnatlink main.ali -Wl,-ld_classic
-macosx_version_min has been renamed to -macos_version_min

Appreciate the suggestions...

Thanks,
Ken

Simon Wright

unread,
Oct 1, 2023, 3:57:38 AM10/1/23
to
Kenneth Wolcott <kenneth...@gmail.com> writes:

> -macosx_version_min has been renamed to -macos_version_min

This will be fixed in GCC 14.
0 new messages