Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcc (g++): ld: Assertion failed: (resultIndex < sectData.atoms.size()) (Xcode 15) #145991

Closed
4 tasks done
osalbahr opened this issue Sep 26, 2023 · 12 comments
Closed
4 tasks done
Labels
bug Reproducible Homebrew/homebrew-core bug outdated PR was locked due to age upstream issue An upstream issue report is needed

Comments

@osalbahr
Copy link
Sponsor Contributor

osalbahr commented Sep 26, 2023

brew gist-logs <formula> link OR brew config AND brew doctor output

$ brew config
HOMEBREW_VERSION: 4.1.13-4-gf1d345a
ORIGIN: https://github.com/Homebrew/brew
HEAD: f1d345a60e2c02f7e5c1b7930601b1921432cfb6
Last commit: 12 hours ago
Core tap origin: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 05f8a448ff23501ac834c6d9ce5802ecb23bf520
Core tap last commit: 13 minutes ago
Core tap branch: master
Core tap JSON: 26 Sep 00:21 UTC
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_GITHUB_API_TOKEN: set
HOMEBREW_MAKE_JOBS: 4
HOMEBREW_SORBET_RUNTIME: set
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: quad-core 64-bit kabylake
Clang: 15.0.0 build 1500
Git: 2.42.0 => /usr/local/bin/git
Curl: 8.1.2 => /usr/bin/curl
macOS: 13.6-x86_64
CLT: 15.0.0.0.1.1694021235
Xcode: N/A
$ brew doctor
Your system is ready to brew.

Verification

  • My "brew doctor output" says Your system is ready to brew. and am still able to reproduce my issue.
  • I ran brew update and am still able to reproduce my issue.
  • I have resolved all warnings from brew doctor and that did not fix my problem.
  • I searched for recent similar issues at https://github.com/Homebrew/homebrew-core/issues?q=is%3Aissue and found no duplicates.

What were you trying to do (and why)?

Compile c++ program for https://open.kattis.com/problems/mancala.

What happened (include all command output)?

$ g++-13 -std=gnu++17 minimal.cpp -o minimal
0  0x10d7cef43  __assert_rtn + 64
1  0x10d6d0f43  ld::AtomPlacement::findAtom(unsigned char, unsigned long long, ld::AtomPlacement::AtomLoc const*&, long long&) const + 1411
2  0x10d6ed431  ld::InputFiles::SliceParser::parseObjectFile(mach_o::Header const*) const + 19745
3  0x10d6fdb71  ld::InputFiles::parseAllFiles(void (ld::AtomFile const*) block_pointer)::$_7::operator()(unsigned long, ld::FileInfo const&) const + 657
4  0x7ff80075e066  _dispatch_client_callout2 + 8
5  0x7ff80077118f  _dispatch_apply_invoke_and_wait + 213
6  0x7ff800770692  _dispatch_apply_with_attr_f + 1207
7  0x7ff800770847  dispatch_apply + 45
8  0x10d796972  ld::AtomFileConsolidator::parseFiles(bool) + 370
9  0x10d71dd67  main + 12263
ld: Assertion failed: (resultIndex < sectData.atoms.size()), function findAtom, file Relocations.cpp, line 1336.
collect2: error: ld returned 1 exit status
$ cat minimal.cpp                                          
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	vector<int> v;
	cout << v.size() << endl;
}

What did you expect to happen?

$ g++ -std=gnu++17 minimal.cpp -o minimal
$ ./minimal 
0

More info:

$ g++-13 --version
g++-13 (Homebrew GCC 13.2.0) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ g++ --version
Apple clang version 15.0.0 (clang-1500.0.40.1)
Target: x86_64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
$ which g++-13
/usr/local/bin/g++-13
$ which g++
/usr/bin/g++

Afaik, this issue started after upgrading Xcode command line tools. I did some digging, and there's an Apple forum from 6 days ago:
https://developer.apple.com/forums/thread/737707

(also a Discussion https://discussions.apple.com/thread/255137447)

I am not sure if this is just a bug in Xcode, so I am opening this issue to track it.

See also:

Step-by-step reproduction instructions (by running brew commands)

g++-13 -std=gnu++17 minimal.cpp -o minimal
@osalbahr osalbahr added the bug Reproducible Homebrew/homebrew-core bug label Sep 26, 2023
@Bo98
Copy link
Member

Bo98 commented Sep 26, 2023

This is indeed an Xcode bug (FB13038083).

Workaround is -Wl,-ld_classic. We may look into making that passed by default, if we can make it work in a backwards compatible fashion for those still on Xcode 14.

@osalbahr
Copy link
Sponsor Contributor Author

osalbahr commented Sep 26, 2023

@Bo98 compiling with -Wl,-ld_classic seems to fix the issue. Are you suggesting rebuilding the g++-* bottles so the compiler adds this flag by default, or that rebuilding the bottles with this flag might fix the issue?

$ CXX='g++-13' make minimal
g++-13     minimal.cpp   -o minimal
0  0x1019aef43  __assert_rtn + 64
1  0x1018b0f43  ld::AtomPlacement::findAtom(unsigned char, unsigned long long, ld::AtomPlacement::AtomLoc const*&, long long&) const + 1411
2  0x1018cd431  ld::InputFiles::SliceParser::parseObjectFile(mach_o::Header const*) const + 19745
3  0x1018ddb71  ld::InputFiles::parseAllFiles(void (ld::AtomFile const*) block_pointer)::$_7::operator()(unsigned long, ld::FileInfo const&) const + 657
4  0x7ff80075e066  _dispatch_client_callout2 + 8
5  0x7ff80077118f  _dispatch_apply_invoke_and_wait + 213
6  0x7ff800770692  _dispatch_apply_with_attr_f + 1207
7  0x7ff800770847  dispatch_apply + 45
8  0x101976972  ld::AtomFileConsolidator::parseFiles(bool) + 370
9  0x1018fdd67  main + 12263
ld: Assertion failed: (resultIndex < sectData.atoms.size()), function findAtom, file Relocations.cpp, line 1336.
collect2: error: ld returned 1 exit status
make: *** [minimal] Error 1
$ CXX='g++-13' CXXFLAGS='-Wl,-ld_classic' make minimal
g++-13 -Wl,-ld_classic    minimal.cpp   -o minimal
$ ./minimal 
0

@osalbahr
Copy link
Sponsor Contributor Author

osalbahr commented Sep 26, 2023

It seems that simply brew reinstall -sv gcc fixed the issue for me, without modifying flags or anything:

$ CXX='g++-13' make minimal
g++-13     minimal.cpp   -o minimal
$ ./minimal 
0
$ g++-13 --version
g++-13 (Homebrew GCC 13.2.0) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ brew config
HOMEBREW_VERSION: 4.1.13-16-g39f76d6
ORIGIN: https://github.com/Homebrew/brew
HEAD: 39f76d635105aef18041f2eb1236945face1c6bf
Last commit: 9 hours ago
Core tap origin: https://github.com/Homebrew/homebrew-core
Core tap HEAD: 05f8a448ff23501ac834c6d9ce5802ecb23bf520
Core tap last commit: 21 hours ago
Core tap branch: master
Core tap JSON: 26 Sep 18:43 UTC
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_GITHUB_API_TOKEN: set
HOMEBREW_MAKE_JOBS: 4
HOMEBREW_SORBET_RUNTIME: set
Homebrew Ruby: 2.6.10 => /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
CPU: quad-core 64-bit kabylake
Clang: 15.0.0 build 1500
Git: 2.42.0 => /usr/local/bin/git
Curl: 8.1.2 => /usr/bin/curl
macOS: 13.6-x86_64
CLT: 15.0.0.0.1.1694021235
Xcode: N/A

Would it be possible to rebuild the gcc bottles(s) using the latest Xcode on Homebrew's CI, for testing purposes?


Note: in case you want to try it locally, it took me 15391.05s user 2348.71s system 267% cpu 1:50:26.62 total.

@osalbahr osalbahr changed the title g++: ld: Assertion failed: (resultIndex < sectData.atoms.size()) (Xcode 15) gcc (g++): ld: Assertion failed: (resultIndex < sectData.atoms.size()) (Xcode 15) Sep 26, 2023
@Bo98
Copy link
Member

Bo98 commented Sep 27, 2023

Yeah, we already have a conditional where if Xcode 15 is detected then the build from source will use ld-classic as a linker

What we need to test however is whether that GCC built under Xcode 15 still works under Xcode 14. It might well do, but that needs to be confirmed.

@fxcoudert
Copy link
Member

fxcoudert commented Oct 7, 2023

For the record, this appears to be fixed in the Xcode 15.1 beta

Copy link
Contributor

github-actions bot commented Nov 8, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@github-actions github-actions bot added the stale No recent activity label Nov 8, 2023
@osalbahr
Copy link
Sponsor Contributor Author

osalbahr commented Nov 9, 2023

Unstale

@github-actions github-actions bot removed the stale No recent activity label Nov 9, 2023
@SMillerDev
Copy link
Member

It's definitely stale, and fixed in the next XCode release. Nothing to do for brew.

@SMillerDev SMillerDev closed this as not planned Won't fix, can't repro, duplicate, stale Nov 9, 2023
@osalbahr
Copy link
Sponsor Contributor Author

osalbahr commented Dec 1, 2023

It's definitely stale, and fixed in the next XCode release. Nothing to do for brew.

Which release is it fixed in? The issue still persists in Command Line Tools for Xcode 15.1 beta 3.

% CXX='gcc-13' make minimal
gcc-13     minimal.cpp   -o minimal
ld: Undefined symbols:
  __ZNSolsEPFRSoS_E, referenced from:
      _main in cctbM3mR.o
  __ZNSolsEm, referenced from:
      _main in cctbM3mR.o
  __ZNSt8ios_base4InitC1Ev, referenced from:
      __Z41__static_initialization_and_destruction_0v in cctbM3mR.o
  __ZNSt8ios_base4InitD1Ev, referenced from:
      __Z41__static_initialization_and_destruction_0v in cctbM3mR.o
  __ZSt4cout, referenced from:
      _main in cctbM3mR.o
  __ZSt4endlIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_, referenced from:
      _main in cctbM3mR.o
  __ZdlPvm, referenced from:
      __ZNSt15__new_allocatorIiE10deallocateEPim in cctbM3mR.o
  ___gxx_personality_v0, referenced from:
      /private/var/folders/d2/9dxqbydd5796hb7j623rk97w0000gn/T/cctbM3mR.o
collect2: error: ld returned 1 exit status
make: *** [minimal] Error 1
% brew config
HOMEBREW_VERSION: 4.1.22-57-g1130070
ORIGIN: https://github.com/Homebrew/brew
HEAD: 11300707964d85f9011bc8f7b418dfe23e1a8862
Last commit: 48 minutes ago
Core tap origin: https://github.com/Homebrew/homebrew-core
Core tap HEAD: a85b622e488448c5ec12668f08a3a2d6e0170a86
Core tap last commit: 2 days ago
Core tap branch: bump-vulkan-headers-1.3.271
Core tap JSON: 01 Dec 14:00 UTC
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_DISPLAY: /private/tmp/com.apple.launchd.m0f0vLisHl/org.xquartz:0
HOMEBREW_MAKE_JOBS: 4
HOMEBREW_SORBET_RUNTIME: set
Homebrew Ruby: 3.1.4 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/3.1.4/bin/ruby
CPU: quad-core 64-bit kabylake
Clang: 15.0.0 build 1500
Git: 2.43.0 => /usr/local/bin/git
Curl: 8.1.2 => /usr/bin/curl
macOS: 13.6.1-x86_64
CLT: 15.1.0.0.1.1699597245
Xcode: N/A

@Bo98
Copy link
Member

Bo98 commented Dec 1, 2023

That doesn't seem to be the same issue. Is that from the same example code as the original report?

@fxcoudert
Copy link
Member

This issue is about the bug ld: Assertion failed: (resultIndex < sectData.atoms.size()) in Apple linker. That is confirmed fixed in Xcode 15.1 beta 3 (and CLT).

Your latest error message seems to be because libstdc++ is missing, probably because CXX should be g++-13 instead of gcc-13.

@osalbahr
Copy link
Sponsor Contributor Author

osalbahr commented Dec 5, 2023

Yes, that was it.... can confirm now it is fixed in the beta release. Thx for catching it!

tlyu added a commit to tlyu/Kaleidoscope-Bundle-Keyboardio that referenced this issue Dec 10, 2023
Use `-Wl,-ld_classic` on macOS, to work around a bug in recent versions
of XCode when trying to link object files created by GCC. This change
has to be coordinated with the Kaleidoscope testing Makefiles, but is
safe to apply first.

References:

Homebrew/homebrew-core#145991
https://developer.apple.com/forums/thread/737707
Signed-off-by: Taylor Yu <code@argon.blue>
@github-actions github-actions bot added the outdated PR was locked due to age label Jan 5, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 5, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Reproducible Homebrew/homebrew-core bug outdated PR was locked due to age upstream issue An upstream issue report is needed
Projects
None yet
Development

No branches or pull requests

4 participants