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

the ECM patch breaks some macOS installations #39040

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

dimpase
Copy link
Member

@dimpase dimpase commented Nov 26, 2024

The ECM patch added in #38905 breaks some macOS installations.

As it was added in order to support building ECM with gcc 14, which is a rather hypothetical situation, it's OK to drop it.

This will fix #39039

📝 Checklist

  • The title is concise and informative.
  • The description explains in detail what this PR is about.
  • I have linked a relevant issue or discussion.
  • I have created tests covering the changes.
  • I have updated the documentation and checked the documentation preview.

⌛ Dependencies

Copy link

Documentation preview for this PR (built with commit 7ce1877; changes) is ready! 🎉
This preview will update shortly after each push to this PR.

@kwankyu
Copy link
Collaborator

kwankyu commented Nov 27, 2024

As it was added in order to support building ECM with gcc 14, which is a rather hypothetical situation, it's OK to drop it.

So the patch is for building sage with gcc 14 (installed by homebrew) on macOS, but apparently it conflicts with building sage with system clang on macOS with an intel chip.

If we drop it, we should warn users not to attempt the configuration (homebrew gcc 14 + macOS with an intel chip). Does this configuration imply that homebrew gcc overrides xcode clang? If so, that is really unusual.

@kwankyu
Copy link
Collaborator

kwankyu commented Nov 27, 2024

@culler Do you agree?

@culler
Copy link
Contributor

culler commented Nov 27, 2024 via email

@dimpase
Copy link
Member Author

dimpase commented Nov 27, 2024

As it was added in order to support building ECM with gcc 14, which is a rather hypothetical situation, it's OK to drop it.

So the patch is for building sage with gcc 14 (installed by homebrew) on macOS, but apparently it conflicts with building sage with system clang on macOS with an intel chip.

If we drop it, we should warn users not to attempt the configuration (homebrew gcc 14 + macOS with an intel chip). Does this configuration imply that homebrew gcc overrides xcode clang? If so, that is really unusual.

Since when is it even possible (again) to build Sage with "real" gcc on macOS? This has been broken for years. Do you know any user who does this?
For what's worth, "real" gcc has been unable to compile C/C++ using macOS headers in a nontrivial way due to
https://en.wikipedia.org/wiki/Blocks_(C_language_extension)

@kwankyu
Copy link
Collaborator

kwankyu commented Nov 27, 2024

We are in release candidate stage. I think there is not enough time left to investigate the issue and prepare a proper fix that works for all platforms.

Let's get this in.

@culler
Copy link
Contributor

culler commented Nov 27, 2024 via email

@dimpase
Copy link
Member Author

dimpase commented Nov 27, 2024

Marc, it's not possible to build Sage on macOS with "real" gcc. Maybe it is possible to build parts of Sage with "real" gcc and other parts with clang, but we don't support this.
So I don't know what this patch is about in the 1st place. Let's not try to solve nonexisting in Sage problems here.

@dimpase
Copy link
Member Author

dimpase commented Nov 27, 2024

If the patch in question was needed for XCode's clang then putting it in the PR upgrading gcc was a rather inappropriate place.

@dimpase
Copy link
Member Author

dimpase commented Nov 27, 2024

I think we know for a fact that the build can fail if the patch is used with an older Intel XCode compiler, and I know for a fact that I have built ECM successfully with the patch installed using the latest Intel XCode compiler. But do you know for sure that the build succeeds with a new Intel XCode compiler if the patch is removed? I don't.

Marc, your #38905 claims that this patch isn't needed for XCode (namely, you wrote No patches are needed for building on macOS with either CPU or on Ubuntu. (cf PR https://github.com/sagemath/sage/pull/38855)).
Do you say it's not the case, or you don't know in fact?

Besides, XCode 16.1 was released less that a month ago. We are not obliged to support it in the coming release, it's way too late.
@vbraun - what do you think?

@culler
Copy link
Contributor

culler commented Nov 27, 2024 via email

@dimpase
Copy link
Member Author

dimpase commented Nov 27, 2024

I don't think you read my message.

Well, you put a patch which has nothing to do with gcc (as you say now) to a PR with the title Update the gcc spkg to version 14.2.0 using iains/gcc-14-branch. There is nothing about the ECM patch in the PR description. The PR description talks at length about "real" gcc for Darwin. All this leads one to believe that the patch is needed for gcc (C compiler!) support for Darwin. However, as we don't use gcc's C compiler on Darwin, it appears to make no sense.

By right, there should have been a totally separate PR dealing with the ECM issue.

@kwankyu
Copy link
Collaborator

kwankyu commented Nov 27, 2024

... I think that with the patch ECM will build with newer XCode versions and without the patch ECM will build with older XCode versions. Please prove me wrong. I would be much happier being wrong about that.

My mac has Intel Xeon E5 processor, and has

$ gcc --version
Apple clang version 16.0.0 (clang-1600.0.26.4)
Target: x86_64-apple-darwin24.1.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Building ecm fails with the patch but succeeds without the patch. With the patch, I get

...
[ecm-7.0.6] [spkg-install] Building ecm-7.0.6
[ecm-7.0.6] [spkg-install] make  all-recursive
[ecm-7.0.6] [spkg-install] Making all in x86_64
[ecm-7.0.6] [spkg-install] m4 -I../ -DOPERATION_mulredc1 `test -f mulredc1.asm || echo './'`mulredc1.asm >mulredc1.sx
[ecm-7.0.6] [spkg-install] /usr/local/bin/bash ../libtool    --mode=compile gcc  -march=native -g -O2 -fPIC -c -o mulredc1.lo mulredc1.sx
[ecm-7.0.6] [spkg-install] libtool: compile:  gcc -march=native -g -O2 -fPIC -c mulredc1.sx -o mulredc1.o
[ecm-7.0.6] [spkg-install] clang: warning: mulredc1.sx: 'linker' input unused [-Wunused-command-line-argument]
[ecm-7.0.6] [spkg-install] clang: error: unsupported option '-march=' for target 'x86_64-apple-darwin24.1.0'
[ecm-7.0.6] [spkg-install] clang: warning: argument unused during compilation: '-g' [-Wunused-command-line-argument]
[ecm-7.0.6] [spkg-install] clang: warning: argument unused during compilation: '-O2' [-Wunused-command-line-argument]
[ecm-7.0.6] [spkg-install] clang: warning: argument unused during compilation: '-fPIC' [-Wunused-command-line-argument]
[ecm-7.0.6] [spkg-install] make[5]: *** [mulredc1.lo] Error 1
[ecm-7.0.6] [spkg-install] rm mulredc1.sx
[ecm-7.0.6] [spkg-install] make[4]: *** [all-recursive] Error 1
[ecm-7.0.6] [spkg-install] make[3]: *** [all] Error 2
[ecm-7.0.6] [spkg-install] ********************************************************************************
[ecm-7.0.6] [spkg-install] Error building ecm-7.0.6

My machine is an old mac pro, but I managed to install the latest macOS. So my system does not have an official configuration.

@kwankyu
Copy link
Collaborator

kwankyu commented Nov 27, 2024

... and I know for a fact that I have built ECM successfully with the patch installed using the latest Intel XCode compiler.

is the compiler Apple clang version 16.0.0?

@dimpase
Copy link
Member Author

dimpase commented Nov 27, 2024

is it xcode 16.0? 16.1?

one way or another, an alternative fix would be, on macOS, to try first to build without the patch, and if it fails, build with the patch.

@kwankyu
Copy link
Collaborator

kwankyu commented Nov 27, 2024

I also have a macbook pro with an intel chip and official macOS, with which I failed to build ecm with the patch but removing the patch, it was a breeze to build ecm.

@kwankyu
Copy link
Collaborator

kwankyu commented Nov 27, 2024

is it xcode 16.0? 16.1?

On my mac pro, it is xcode 16.1.

@kwankyu
Copy link
Collaborator

kwankyu commented Nov 27, 2024

I also have a macbook pro with an intel chip and official macOS, with which I failed to build ecm with the patch but removing the patch, it was a breeze to build ecm.

The machine has Intel Core i9 chip, and xcode 16.1

Copy link
Collaborator

@kwankyu kwankyu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, either keeping or removing the patch is not a complete solution. I think we may remove the patch now to cover the reported cases. Later if we get failure reports from the other side, then we may conceive a better solution based on more data. So I approve the PR, but I leave the decision to Marc.

@culler
Copy link
Contributor

culler commented Nov 27, 2024

I am OK with removing the patch. If it turns out that some people need it and some don't, that means that the implementation is wrong and it should be redone, adding code which decides when the Makefile.in should be changed.

For the record, I would like to post the comment from the ECM Makefile which is clearly wrong:

# Nothing here needs the C preprocessor, and including this rule causes
  # "make" to build .S, then .s files which fails on case-insensitive 
  # filesystems

The statement that "Nothing here needs the C preprocessor" is being applied to files which contain preprocessor directives and therefore do need the C preprocessor. The mystery is why the C preprocessor sometimes gets used in cases (namely when the file has a .s extension) where the gcc rules say it should not be used. Of course the compiler being used is clang, not gcc, but clang claims to be providing a gcc emulator.

I expect that this issue will arise again. But at least we now know something (not much, but something) about it and can keep an eye out for it. Maybe in the meantime ECM will address it.

@culler
Copy link
Contributor

culler commented Nov 27, 2024

I remembered something which might explain the mysterious changes in XCode behavior. When I encountered my failure building ECM, which the patch fixed, I was using XCode 16.1beta. I am guessing that Apple decided that making clang consistent with gcc in this way was causing more problems than it was solving, so they reverted that change.

@culler
Copy link
Contributor

culler commented Nov 27, 2024

I did some testing with XCode which convinced me that Dima is correct - this patch was created to allow building ECM with gcc 14.2.0 and was based on my false assumption that XCode's gcc emulator followed the gcc convention regarding assembly language file extensions.

This is what my testing shows:

  • If the clang assembler is invoked as gcc then (1) it always uses the C preprocessor; and (2) it will not accept the .sx filename extension.
  • If the clang assembler is invoked as as then (1) it never uses the C preprocessor; and (2( it accepts any file extension.

I tested by writing a "hello world" in C; compiling it to assembly language with gcc -S;
and editing the assembly language program to add #if 0 and '#endif` directives enclosing the call to printf. I could then tell whether the C preprocessor was used by compiling the assembly language program and seeing if it printed anything.

So, given that nobody can and nobody should try building Sage with gcc on macOS, I am now convinced that removing the patch is the correct thing to do. My apologies for assuming that a gcc emulator would emulate gcc without checking if that were true. I also apologize for forgetting the exact chain of events which, fortunately, I had written down in the PR where Dima could read them.

@dimpase
Copy link
Member Author

dimpase commented Nov 27, 2024

Marc, thanks - would you propose your patch to the ECM upstream?

vbraun pushed a commit to vbraun/sage that referenced this pull request Nov 28, 2024
The ECM patch added in  sagemath#38905 breaks some macOS installations.

As it was added in order to support building ECM with gcc 14, which is a
rather hypothetical situation, it's OK to drop it.

This will fix sagemath#39039

### 📝 Checklist

<!-- Put an `x` in all the boxes that apply. -->

- [x] The title is concise and informative.
- [x] The description explains in detail what this PR is about.
- [x] I have linked a relevant issue or discussion.
- [ ] I have created tests covering the changes.
- [ ] I have updated the documentation and checked the documentation
preview.

### ⌛ Dependencies

<!-- List all open PRs that this PR logically depends on. For example,
-->
<!-- - sagemath#12345: short description why this is a dependency -->
<!-- - sagemath#34567: ... -->

URL: sagemath#39040
Reported by: Dima Pasechnik
Reviewer(s): Kwankyu Lee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The ecm patch is causing trouble for some X86_64 macOS machines, see
3 participants