Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 905131 - sys-devel/binutils-apple-8.2.1-r101: objc/runtime.h:373:29: error: expected ')' before '^' token
Summary: sys-devel/binutils-apple-8.2.1-r101: objc/runtime.h:373:29: error: expected '...
Status: RESOLVED FIXED
Alias: None
Product: Gentoo/Alt
Classification: Unclassified
Component: Prefix Support (show other bugs)
Hardware: All OS X
: Normal normal (vote)
Assignee: Gentoo Prefix
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 886491
  Show dependency tree
 
Reported: 2023-04-26 19:34 UTC by Tom Li
Modified: 2023-06-04 11:29 UTC (History)
2 users (show)

See Also:
Package list:
Runtime testing required: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Tom Li 2023-04-26 19:34:08 UTC
On macOS 13, Gentoo Prefix fails to compile sys-devel/binutils-apple-8.2.1-r101:  due to missing Blocks support in GCC, creating the following error:

> /Users/ec2-user/gentoo/MacOSX.sdk/usr/include/objc/runtime.h:373:29:
> error: expected ')' before '^' token
> 373 |                       void (^ _Nonnull block)(Class _Nonnull aClass, BOOL * _Nonnull stop)
>      |                             ^
>      |                             )

The likely solution has already been identified and the patch is currently being tested. 

Originally reported in Bug 898610, it's now created as a dedicated issue for clarity.
Comment 1 Fabian Groffen gentoo-dev 2023-04-26 19:42:01 UTC
Interestingly, it broke (gcc-12.2?) in another way on darwin17

In file included from /Scratch-Local/Gentoo/bootstrap64-20230426/var/tmp/portage
/sys-devel/binutils-apple-8.2.1-r101/work/darwin-xtools-gentoo-8.2.1-r101/ld64/s
rc/ld/parsers/macho_relocatable_file.cpp:37:
/Scratch-Local/Gentoo/bootstrap64-20230426/var/tmp/portage/sys-devel/binutils-ap
ple-8.2.1-r101/work/darwin-xtools-gentoo-8.2.1-r101/ld64/src/ld/parsers/libunwin
d/DwarfInstructions.hpp:36:10: fatal error: algorithm: No such file or directory
   36 | #include <algorithm>
      |          ^~~~~~~~~~~
compilation terminated.

The same code surely worked before.
Comment 2 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-04-27 03:59:57 UTC
<algorithm> is new in C++17, so might be related to that (either before it was using -std=c++14 or similar, or the code conditionally uses stuff if building w/ >= c++17 but for some reason the header is missing).
Comment 3 Tom Li 2023-04-27 09:07:20 UTC
(In reply to Sam James from comment #2)
> <algorithm> is new in C++17, so might be related to that (either before it
> was using -std=c++14 or similar, or the code conditionally uses stuff if
> building w/ >= c++17 but for some reason the header is missing).

No, algorithm is not new in C++17. std::algorithm has been an integral part of the C++ programming language since decades ago. Not only that, it cannot even find std::vector!

> /Users/ec2-user/gentoo/var/tmp/portage/sys-devel/binutils-apple-8.2.1-r101/work
> /darwin-xtools-gentoo-8.2.1-r101/ld64/src/other/PruneTrie.cpp:24:10: fatal
> error: vector: No such file or directory
>   24 | #include <vector>
>      |          ^~~~~~~~
>compilation terminated.

The problem appears to be the side-effect of the flag "-stdlib=libc++". This flag is only valid for clang, not GCC. Normally the error should simply be "unknown option", but for some reason, in this instance, it prevents GCC from recognizing the C++ standard library header altogether. Manually removing the flag allows the build to continue. 

Note: this is a preliminary result and the fix is still untested, I'm still working on troubleshooting and testing.
Comment 4 Tom Li 2023-04-27 09:22:36 UTC
It seems that GCC 12.2 no longer rejects "-stdlib=libc++" as an invalid flag, instead, it prevents GCC from locating the C++ standard library.

bash-3.2$ cat main.cpp 
#include <vector>

int main(void)
{
}
bash-3.2$ g++ main.cpp  -o main -stdlib=libc++
main.cpp:1:10: fatal error: vector: No such file or directory
    1 | #include <vector>
      |          ^~~~~~~~
compilation terminated.

The side-effect of this change is significant - most ./configure scripts attempts to check whether "-stdlib=libc++" is a valid option using a dummy program. It's suppose to fail and the build system knows it's GCC. But now it escapes detection until the dummy program contains "include" statement.

This is strange. I suspect it's a regression GCC 12.2 (or GCC on x64) as an attempt to improve compatibility, but the unintended consequence is instead breaking compatibility.
Comment 5 Fabian Groffen gentoo-dev 2023-04-27 09:54:00 UTC
feels like, we should mask GCC 12.2 again until this gets fixed?
Comment 6 Tom Li 2023-04-27 10:10:39 UTC
(In reply to Fabian Groffen from comment #5)
> feels like, we should mask GCC 12.2 again until this gets fixed?

I'm still testing it. I haven't yet verified whether GCC 12.1 is unaffected.
Comment 7 Tom Li 2023-04-27 10:12:22 UTC
Let's open a new issue for the second GCC problem, it's clearly independent from the previous Blocks issue in binutils-apple.
Comment 8 Tom Li 2023-04-27 10:16:44 UTC
I opened Bug 905152.
Comment 9 Tom Li 2023-04-27 10:33:34 UTC
With GCC 12.2 masked, let's return to this binutils-apple bug for now. I plan to submit and test a patch today to fix it. After it's fixed, let's bump the snapshot version again for macOS so we can get bootstrapping working again as soon as possible.
Comment 10 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-04-27 13:23:34 UTC
(In reply to Tom Li from comment #3)
> (In reply to Sam James from comment #2)
> > <algorithm> is new in C++17, so might be related to that (either before it
> > was using -std=c++14 or similar, or the code conditionally uses stuff if
> > building w/ >= c++17 but for some reason the header is missing).
> 
> No, algorithm is not new in C++17. std::algorithm has been an integral part
> of the C++ programming language since decades ago. Not only that, it cannot
> even find std::vector!
>

Sorry, you are right, oops.

> > /Users/ec2-user/gentoo/var/tmp/portage/sys-devel/binutils-apple-8.2.1-r101/work
> > /darwin-xtools-gentoo-8.2.1-r101/ld64/src/other/PruneTrie.cpp:24:10: fatal
> > error: vector: No such file or directory
> >   24 | #include <vector>
> >      |          ^~~~~~~~
> >compilation terminated.
> 
> The problem appears to be the side-effect of the flag "-stdlib=libc++". This
> flag is only valid for clang, not GCC. Normally the error should simply be
> "unknown option", but for some reason, in this instance, it prevents GCC
> from recognizing the C++ standard library header altogether. Manually
> removing the flag allows the build to continue. 
> 

It's valid for gcc if you configure it to be: https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=662b9c55cf06d3df6682ef865fb2b685820317a9

> Note: this is a preliminary result and the fix is still untested, I'm still
> working on troubleshooting and testing.
Comment 11 Tom Li 2023-04-27 17:07:43 UTC
(In reply to Sam James from comment #10)
> It's valid for gcc if you configure it to be:
> https://gcc.gnu.org/git/?p=gcc.git;a=commit;
> h=662b9c55cf06d3df6682ef865fb2b685820317a9

First, please, when a separate bug report has been created, please continue the discussion in the new report instead of following the original thread. I thought you and I have already learned this lesson after yesterday's mishaps.

But for completeness: It's not valid, it's questionable. The GCC Darwin fork forces this option regardless of whether it's configured or not, unlike mainline GCC. And without explicit configuration, the default search path for libc++ is totally invalid, making it unusable. This seemingly harmless change also has far-reaching unintended consequences of breaking the assumption of many ./configure scripts. I already published a detailed report in Bug 905152, and it shall NOT be repeated here.
Comment 12 Sam James archtester Gentoo Infrastructure gentoo-dev Security 2023-04-27 18:54:30 UTC
Your comment comes across a bit lecturing, keep in mind that people might read their emails in order and reply accordingly.
Comment 13 Tom Li 2023-04-27 20:56:42 UTC
I just opened a Pull Request at https://github.com/gentoo/gentoo/pull/30781 to fix this problem for macOS 13 (both Intel and ARM64), along with two other problems on ARM64.
Comment 14 Tom Li 2023-05-02 19:10:07 UTC
I'm still waiting for Pull Request #2 "[cctools] fix ar(1) crash without argument" to be merged into grobian/darwin-xtools, so that a new release can be made for binutils-apple to fix Bug 905131.
Comment 15 Fabian Groffen gentoo-dev 2023-05-30 13:11:32 UTC
with these changes I can compile, but still get:

configure:3335: checking whether we are cross compiling
configure:3343: arm64-apple-darwin22-gcc -o conftest  -O2 -pipe  -              D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE -Wl,-           dead_strip_dylibs conftest.c  >&5
ld: warning: URGENT: building for OSX, but linking in object file (/Users/Gentoo-13/var/tmp/portage/sys-devel/bc-1.07.1-r6/temp/ccsokQgL.o) built for     iOS. Note: This will be an error in the future.
configure:3347: $? = 0
configure:3354: ./conftest
./configure: line 3356: 73346 Killed: 9               ./conftest$ac_cv_exeext
configure:3358: $? = 137
configure:3365: error: in `/Users/Gentoo-13/var/tmp/portage/sys-devel/bc- 1.07.1-r6/work/bc-1.07.1':

The urgent warning we can fix in the code to make it iOS, but that doesn't solve the problem either IIRC.
Comment 16 Tom Li 2023-06-03 11:53:36 UTC
(In reply to Fabian Groffen from comment #15)
> The urgent warning we can fix in the code to make it iOS, but that doesn't
> solve the problem either IIRC.

I see.

The original bug affects both x64 and ARM64 bootstrap. In binutils-apple-8.2.1-r102, at least x64 bootstrap is now fixed. Meanwhile on ARM64, binutils-apple remains masked, so let's keep it as-is.

So this bug can probably be closed as RESOLVED FIXED. I'll retest it soon and close this bug myself.
Comment 17 Fabian Groffen gentoo-dev 2023-06-04 10:26:53 UTC
Slightly off-topic here: I verified on two boxes running 13.3/13.4 that bootstrap now works on arm64-macos.  arm uses native-cctools, indeed.

Compiling binutils-apple now works, so we can close this particular bug.  Ok, let's do that and revisit the issue later.
Comment 18 Tom Li 2023-06-04 11:29:54 UTC
(In reply to Fabian Groffen from comment #17)
> bootstrap now works on arm64-macos.  arm uses native-cctools, indeed.

Retested on x64-macos, I confirm it works.