ld: Assertion failed: (resultIndex < sectData.atoms.size())

Hi, I wanted to compile a project (For the compilation I used gcc-13 from home-brew) and I got the following error from the linker:

0  0x100e0f648  __assert_rtn + 72
1  0x100d43fac  ld::AtomPlacement::findAtom(unsigned char, unsigned long long, ld::AtomPlacement::AtomLoc const*&, long long&) const + 1204
2  0x100d59924  ld::InputFiles::SliceParser::parseObjectFile(mach_o::Header const*) const + 15164
3  0x100d66e30  ld::InputFiles::parseAllFiles(void (ld::AtomFile const*) block_pointer)::$_7::operator()(unsigned long, ld::FileInfo const&) const + 420
4  0x1a95f0440  _dispatch_client_callout2 + 20
5  0x1a9603f1c  _dispatch_apply_invoke + 224
6  0x1a95f0400  _dispatch_client_callout + 20
7  0x1a9601fb8  _dispatch_root_queue_drain + 684
8  0x1a96026c0  _dispatch_worker_thread2 + 164
9  0x1a979c038  _pthread_wqthread + 228
ld: Assertion failed: (resultIndex < sectData.atoms.size()), function findAtom, file Relocations.cpp, line 1336.
collect2: error: ld returned 1 exit status

I am using a MacBook Pro M2 (Ventura 13.5.2 (22G91)) and the CommandLineTools version 15.0. I have read through some earlier posts about linker issues, which were solved by downgrading Xcode. After downgrading to 14.3.0 I was able to compile the code. Did anyone run into the same Problem? If so, is there a better solution for this?

Best regards

  • -lstdc++

  • if you use cmake, you can add "set(CMAKE_CXX_FLAGS "-no-pie")", and it works.

  • I am using VS Code for programming in c++, and I am using gcc/g++ 13.2.0 installed via homebrew. It was working perfectly fine. After update I am unable to compile or run any program.

    What should I do to solve this issue?

Add a Comment

Accepted Reply

Xcode 15, and its associated Command Line Tools package, includes a new linker implementation. See here.

I recommend that you temporarily switch to the old linker implementation. I suspect that’ll avoid this crash.

If it does, please file a bug about this. My experience is that problems like this are usually caused by third-party tools generating incorrect Mach-O object files but:

  • The linker team needs to look at this, just to be sure.

  • Even if it is, the linker probably shouldn’t crash (-:

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • I downgraded to 14.3.1 and it fixes it, if someone files a bug I'd gladly upvote it.

  • IMPORTANT I have more info about this in the post below.

Add a Comment

Replies

Same problem after updating commandLineTools tonight. Unable to compile using g++

Same here. Using GCC12 from Macports. I'm using Macbook Pro Intel with Ventura 13.5.2.

Same here after updating command line tools this morning! Unable to compile some codes using GCC-13.

Me too, MacBook Pro M2 macOS Ventura Version 13.5.2 (22G91). Xcode 15.0 Build version 15A240d.

Xcode 15, and its associated Command Line Tools package, includes a new linker implementation. See here.

I recommend that you temporarily switch to the old linker implementation. I suspect that’ll avoid this crash.

If it does, please file a bug about this. My experience is that problems like this are usually caused by third-party tools generating incorrect Mach-O object files but:

  • The linker team needs to look at this, just to be sure.

  • Even if it is, the linker probably shouldn’t crash (-:

Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • I downgraded to 14.3.1 and it fixes it, if someone files a bug I'd gladly upvote it.

  • IMPORTANT I have more info about this in the post below.

Add a Comment

Same here, after updating Xcode Command Line Tools today MacBook Air M2 Ventura 13.5.2

Hello again, Thanks for the quick replies! As mentioned previously, after downgrading to Xcode 14.3.0 it worked just fine. Thus, I would recommend this as a temporary solution. I just file the bug report (FB13192247). Best regards

  • Thanks for filing FB13192247.

  • What if I don't have Xcode installed in my Mac ventura 13.6 but facing the same issue??

Add a Comment

I think I am seeing couple of other issues as well with this new linker:

  1. .loh AdrpAdd label1, label2 optimization hint is ignored.
  2. resulting binary is not adding FUNCTION_STARTS for some functions

Believe_it0215 wrote:

What if I don't have Xcode installed in my Mac ventura 13.6 but facing the same issue?

macOS doesn’t ship with a linker, so you must have installed one. If you don’t have Xcode, it’s likely that you installed the Command Line Tools package. There’s a separate Command Line Tools package associated with each Xcode version. So, for example, Xcode 15 is associated with Command Line Tools for Xcode 15.

The Command Line Tools for Xcode 15 package has the same linker as Xcode 15, and thus everything I say about Xcode 15 applies to it as well.


peterisledins1 you wrote:

I think I am seeing couple of other issues as well with this new linker:

OK. My advice is that you:

  1. Reproduce the problem with Xcode 15, or its associated Command Line Tools.

  2. Use the option documented in the release notes to switch to the old linker implementation.

  3. If that resolves your issues, it’s very likely that they’re tied to the new linker implementation. You can then file a bug on that basis.

  4. And using the old linker implementation is a reasonable temporary solution.

If you do file a bug, please post the number here, just for the record.


Oh, I wanna stress that not all of these problems are caused by bugs in the new linker implementation. The one that started this thread most definitely is, because the linker shouldn’t crash in the face of bad input. However, it’s quite possible that these failures are caused by other tools generating bad input that the linker now detects.

However, unless you’re a linker expert it’s hard to know what’s really going on, which is why I’m recommending that folks file bugs. Your bug may well come back as ‘behaves correctly’, with an explanation of what’s causing the problem. Or, in the case of the crash that started this thread, the fix might be for the linker to emit a diagnostic rather than crash, and then you need to talk to vendor of the tool that generate the bug input.

One universal truth about linkers is that no one cares about them until things go wrong (-:


If you file a bug against the linker, there are two things you can do to speed up the investigation. The first is to include a small set of steps to reproduce the problem. Ideally your steps shouldn’t rely on installing complex third-party tooling.

If that’s not feasible, attach a linker snapshot to your bug report. To generate this, pass the -debug_snapshot flag to the linker. That’ll create a directory with a name like /tmp/NNN-DDD-TTT.ld-snapshot, where NNN is the linked name and DDD-TTT is the time and day. Zip that up and attach it to your bug.

If you’re using a wrapper around the linker, you’ll need to arrange to pass the -debug_snapshot flag through to the linker:

  • In Xcode, add -Wl,-debug_snapshot to the Other Linker Flags build setting.

  • For the clang tool, pass in the options -Xlinker -debug_snapshot.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

@MichelHeinz @eskimo Could you guys mention how would I go about downgrading it to the previous version? I don't have the XCode Application installed on my Mac. But, have their command line tools installed? How should I go about it? I am not able to compile anything using g++ after the update

@sw0osh I had the same issue, you can go to apple dev portal and check out downloads tab in it.

Link - https://developer.apple.com/download/all/?q=command%20line%20tools

download the 14.3.1 version.

  • I am not able to install after downloading command line tools 14.3.1 in macOS Sonoma 14.0. The error message is the following "Command Line Tools can't be installed on this disk (Macintosh HD). The version of macOS is too new." What should I do to install it ? And what to do after that so that 14.3.1 version is used by Mac instead of 15.0 version of command line tools ?

Add a Comment

Could you guys mention how would I go about downgrading it to the previous version?

You shouldn’t need to downgrade your command-line tools setup to get around this issue. Rather, you can apply the workaround I referenced upthread.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Same failure under OSX 14 but command line tools 14.3 won't install on OSX 14.

  • Yes, OSX 14 won't allow command line tools 14.3 to be installed, Have you found a fix?

Add a Comment

Fixed by adding to gpr file: package Linker is for Default_Switches ("ada") use ("-Wl,-ld_classic"); end case;

My program now links and executes under OSX 14 Sobono and CLT15.

  • Hi, can you please guide me in more detail actually i am not able to find out where i have to add this -Wl,-ld_classic please guide it will really help me

Add a Comment

For command line use: -largs -Wl,-ld_classic