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

Add support to build a host GCC for building the toolchain #1423

Merged
merged 1 commit into from
Feb 29, 2024

Conversation

cmuellner
Copy link
Collaborator

A significant amount of users of this project are using it for toolchain development. These users need to ensure that their code is warning free before submitting it upstream. Let's support this use case by adding a configure flag '--enable-host-gcc', which does exactly that:

  • build a host GCC before building other components
  • setting PATH such that this new GCC is used to build the cross toolchain
  • enable -Werror for the GCC build

This patch was tested on a Fedora 39 machine (GCC 13), with the following modification in a GCC source file:

  #if __GNUC__ == 13
  #error Host compiler in use!
  #endif

This fails when building without the new flag and does not fail when building with latest upstream/master (GCC 14 prerelease).

The '--enable-werror-always' was tested with a warning that showed up recently in upstream GCC.

A significant amount of users of this project are using it for toolchain
development. These users need to ensure that their code is warning free
before submitting it upstream. Let's support this use case by adding a
configure flag '--enable-host-gcc', which does exactly that:
* build a host GCC before building other components
* setting PATH such that this new GCC is used to build the cross
  toolchain
* enable -Werror for the GCC build

This patch was tested on a Fedora 39 machine (GCC 13),
with the following modification in a GCC source file:
  #if __GNUC__ == 13
  #error Host compiler in use!
  #endif
This fails when building without the new flag and does not fail
when building with latest upstream/master (GCC 14 prerelease).

The '--enable-werror-always' was tested with a warning that showed
up recently in upstream GCC.

Signed-off-by: Christoph Müllner <christoph.muellner@vrull.eu>
@TommyMurphyTM1234
Copy link
Collaborator

A significant amount of users of this project are using it for toolchain development. These users need to ensure that their code is warning free before submitting it upstream. Let's support this use case by adding a configure flag '--enable-host-gcc', which does exactly that:

  • build a host GCC before building other components
  • setting PATH such that this new GCC is used to build the cross toolchain

Hi @cmuellner - can you expand on why and when this (building the host GCC compiler from scratch) is necessary? It's not clear to me and it seems very onerous - building the RISC-V toolchain already takes quite a long time in many cases (and a looooong time when it's LLVM!). Why won't just getting a recent (e.g. GCC 13 at the time of writing) host GCC toolchain suffice?

@cmuellner
Copy link
Collaborator Author

For upstream contributions to GCC a bootstrap build and executing all tests of the regression test suite is a must (see https://gcc.gnu.org/contribute.html).

Bootstrapping means building a stage 1 compiler, which then builds the actual GCC. Really performant RISC-V CPUs are still rare (and often used for work other than simple QA checks). Therefore, these builds/tests are usually run on x86_64/QEMU (system or user-mode emulation), but that takes several hours to complete.

Cross-compiling is a solution for that issue because we avoid QEMU for everything except executing the test binaries. And the way this is done in this PR is close to a bootstrap build.

Using a "recent" GCC is insufficient because there might be a change in the warning behavior of GCC in every commit.

The trigger for all this was a patch from somebody that was reviewed and approved by a maintainer, which I picked up for final testing and pushing. I did not run a bootstrap build because I was too impatient (and did not want to block my machine for several hours), but only a make check with this repo. After this showed no regressions, I pushed the patch. A few days later, this patch was identified to trigger a compiler warning. The fix of the warning is trivial, but I want to avoid this from happening again (especially since it has already happened the second time for me). The previous time this happened to me was even more surprising since GCC 13 did indeed not emit the warning that GCC origin/master did.

@TommyMurphyTM1234
Copy link
Collaborator

Hi @cmuellner - thanks for the thorough explanation. Much appreciated.

@cmuellner
Copy link
Collaborator Author

@kito-cheng ping

Copy link
Collaborator

@kito-cheng kito-cheng left a comment

Choose a reason for hiding this comment

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

LGTM, That's really useful!

@cmuellner cmuellner merged commit 1946480 into riscv-collab:master Feb 29, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants