AdaCore / ada_language_server

Server implementing the Microsoft Language Protocol for Ada and SPARK
GNU General Public License v3.0
240 stars 55 forks source link

hello world - linker failure - osx #1172

Closed kalaracey closed 12 months ago

kalaracey commented 12 months ago

In case anyone else has this issue.

-- hello_world.adb
with Ada.Text_IO;

procedure Hello is
begin
    Ada.Text_IO.Put_Line ("Hello, world!");
end Hello;
-- hello_world.gpr
project Hello_World is
   for Main use ("hello_world.adb");
   for Object_Dir use ".objs";

   package Compiler is
      for Default_Switches ("Ada") use ("-g");
   end Compiler;
end Hello_World;
$  gprbuild -P hello_world.gpr -cargs -gnatef 
Link
   [link]         hello_world.adb
-macosx_version_min has been renamed to -macos_version_min
ld: warning: ignoring duplicate libraries: '-lSystem'
0  0x101beaf43  __assert_rtn + 64
1  0x101aecf43  ld::AtomPlacement::findAtom(unsigned char, unsigned long long, ld::AtomPlacement::AtomLoc const*&, long long&) const + 1411
2  0x101b09431  ld::InputFiles::SliceParser::parseObjectFile(mach_o::Header const*) const + 19745
3  0x101b19e44  ld::InputFiles::parseAllFiles(void (ld::AtomFile const*) block_pointer)::$_7::operator()(unsigned long, ld::FileInfo const&) const + 1380
4  0x7ff81c6e8066  _dispatch_client_callout2 + 8
5  0x7ff81c6f9e09  _dispatch_apply_invoke + 213
6  0x7ff81c6e8033  _dispatch_client_callout + 8
7  0x7ff81c6f80f6  _dispatch_root_queue_drain + 683
8  0x7ff81c6f8768  _dispatch_worker_thread2 + 170
9  0x7ff81c885c0f  _pthread_wqthread + 257
ld: Assertion failed: (resultIndex < sectData.atoms.size()), function findAtom, file Relocations.cpp, line 1336.
collect2: error: ld returned 1 exit status
gprbuild: link of hello_world.adb failed
gprbuild: failed command was: /users/kal/opt/gnat/2020/bin/gcc hello_world.o b__hello_world.o -L/Users/kal/Code/ada/.objs/ -L/Users/kal/Code/ada/.objs/ -L/users/kal/opt/gnat/2020/lib/gcc/x86_64-apple-darwin17.7.0/8.4.1/adalib/ /users/kal/opt/gnat/2020/lib/gcc/x86_64-apple-darwin17.7.0/8.4.1/adalib/libgnat.a -Wl,-rpath,@executable_path/ -Wl,-rpath,@executable_path/../../..//opt/gnat/2020/lib/gcc/x86_64-apple-darwin17.7.0/8.4.1/adalib -o hello_world

From https://developer.apple.com/forums/thread/737707, it sounds like the issue is with the new xcode tools.

I found that building on the command line with -largs -no-pie works:

$  gprbuild -P hello_world.gpr -cargs -gnatef -largs -no-pie
Compile
   [Ada]          hello_world.adb
/Users/kal/Code/ada/hello_world.adb:3:11: warning: file name does not match unit name, should be "hello.adb"
Bind
   [gprbind]      hello_world.bexch
   [Ada]          hello_world.ali
Link
   [link]         hello_world.adb
-macosx_version_min has been renamed to -macos_version_min
$ echo $?
0
$ .objs/hello_world 
Hello, world!

Alternatively, you can modify hello_world.gpr:

project Hello_World is
   -- ...snip...
   package Linker is
      -- https://docs.adacore.com/gprbuild-docs/html/gprbuild_ug/gnat_project_manager.html
      -- https://developer.apple.com/forums/thread/737707
      for Default_Switches ("Ada") use ("-no-pie");
   end Linker;
end Hello_World;
reznikmm commented 12 months ago

This is a known issue. Try to add -Wl,-ld_classic to linker options or update of the developer toolkit (Xcode, or the much smaller Command Line Tools) to beta version of 15.