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

Questions about architecture detection #1313

Open
longnguyen2004 opened this issue Jul 3, 2022 · 9 comments
Open

Questions about architecture detection #1313

longnguyen2004 opened this issue Jul 3, 2022 · 9 comments
Labels
Architecture Architecture specific question

Comments

@longnguyen2004
Copy link
Contributor

Why is the arch detection the way that it is, instead of relying on the already existing CMAKE_SYSTEM_PROCESSOR variable?

@mtl1979
Copy link
Collaborator

mtl1979 commented Jul 3, 2022

When cross-compiling, CMAKE_SYSTEM_PROCESSOR must be manually defined. It is currently also possible to target older, but compatible processor.

@nmoinvaz
Copy link
Member

nmoinvaz commented Jul 9, 2022

We could potentially use detect-arch.c for configure script too.

@mtl1979
Copy link
Collaborator

mtl1979 commented Jul 9, 2022

To use detect-arch.c we would also need to "port" detect-arch.cmake for bash which would not save any lines compared to the current test we have in configure.

@nmoinvaz
Copy link
Member

Some of the logic from detect-arch.cmake could be put into detect-arch.c. It could print out both the arch and the base arch.

@nmoinvaz
Copy link
Member

When cross-compiling, CMAKE_SYSTEM_PROCESSOR must be manually defined.

We don't do any cross-compiling scenarios without a toolchain file that defines CMAKE_SYSTEM_PROCESSOR. And even in the cross-compiling scenario, we don't actually run detect-arch.c but instead we do this:

elseif(CMAKE_CROSSCOMPILING)
set(ARCH ${CMAKE_C_COMPILER_TARGET})
else()

It would seem to me that we don't need detect-arch.c and could just use CMAKE_SYSTEM_PROCESSOR.

@mtl1979
Copy link
Collaborator

mtl1979 commented Jul 10, 2022

@nmoinvaz We would still need to verify that contents of CMAKE_SYSTEM_PROCESSOR are normalized... At least for ARM, there is so many different processors and I'm not at all confident that we can gracefully handle all the values.

@nmoinvaz
Copy link
Member

Yeah that seems to be the purpose of the detect-arch.cmake script - to normalize the values into ARCH and BASEARCH. It currently uses CMAKE_SYSTEM_PROCESSOR as a fallback.

CMAKE_SYSTEM_PROCESSOR is essentially the same value as uname -m which is used in configure. I'm not so sure there is much value in doing the compiler check when we already have CMAKE_SYSTEM_PROCESSOR.

@Dead2
Copy link
Member

Dead2 commented Jul 10, 2022

The value detect-arch.c brings is that it directly queries the compiler we are targeting and not whatever CMAKE thinks. It was made in response to having problems due to a mismatch between compiler and cmake. This solved that problem nearly completely (except for cross-compiling, however I guess it could perhaps even be used for that if providing only the correct CC?).

I have not investigated whether CMake is any better at this now than before, or whether this was a problem with bad cmake scripting, cmake distro problems or an inherent cmake problem.

That said, whatever the source of the problems were, I am not very eager to revert this unless there is a problem though, because that would be fixing something that actually works and it has a real possibility of regressions we are unable to test ahead of time.

@mtl1979
Copy link
Collaborator

mtl1979 commented Jul 11, 2022

Even though in most cases it is bad idea to "reinvent the wheel", when it comes to open-source software, sometimes getting the original software fixed is harder than rewriting the bad parts... I've worked with open-source software since December 1996 and rewritten a lot of code, some of which has been merged upstream. A lot of projects, including cmake, try to be backwards compatible as much as possible, but not always. Hardly any project however is forwards compatible. Can't really expect a program written for example 20 years old to run correctly on modern computers and operating systems.

We are trying hard to make things work with wide range of Windows and Linux versions, and if possible support some versions of MacOS and FreeBSD/OpenBSD/NetBSD. Any other operating systems might work, but there is no guarantee that all features work the same, especially the parts that depend on hardware detection.

We don't, or even can't, support every possible compiler version, be it old or new, as some compiler versions have serious bugs or breaking changes that are not present in any of the previous or subsequent major versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Architecture Architecture specific question
Projects
None yet
Development

No branches or pull requests

4 participants