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 Clang compiler support and update project to C17 standard #1962

Merged
merged 25 commits into from
May 29, 2024

Conversation

DL6ER
Copy link
Member

@DL6ER DL6ER commented May 17, 2024

What does this implement/fix?

Add Clang compiler support, tested with

  • Clang 14.0.0 (Ubuntu 22.04.3 LTS),
  • Clang 16.0.2 (Alpine 3.18), and
  • Clang 17.0.6 (Alpine Edge)

C17 is the informal name for ISO/IEC 9899:2018 and was published in June 2018. It replaced C11 and will eventually be superseded by C23 when it is published. C17 fixes numerous minor defects in C11 without introducing new language features. It required a number of subtle code changes without any real changes. We also bump the required minimum CMake version to the lowest version supporting the C17 standard.


Related issue or feature (if applicable): N/A

Pull request in docs with documentation (if applicable): N/A


By submitting this pull request, I confirm the following:

  1. I have read and understood the contributors guide, as well as this entire template. I understand which branch to base my commits and Pull Requests against.
  2. I have commented my proposed changes within the code.
  3. I am willing to help maintain this change if there are issues with it later.
  4. It is compatible with the EUPL 1.2 license
  5. I have squashed any insignificant commits. (git rebase)

Checklist:

  • The code change is tested and works locally.
  • I based my code and PRs against the repositories developmental branch.
  • I signed off all commits. Pi-hole enforces the DCO for all contributions
  • I signed all my commits. Pi-hole requires signatures to verify authorship
  • I have read the above and my PR is ready for review.

DL6ER added 5 commits May 12, 2024 21:01
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
…LTS), Clang 16.0.2 (Alpine 3.18), and Clang 17.0.6 (Alping Edge)

Signed-off-by: DL6ER <dl6er@dl6er.de>
@DL6ER
Copy link
Member Author

DL6ER commented May 17, 2024

Opening this PR in draft mode as I first want to add another CI step that ensures compilation fails on clang warnings as well. FOr this, we need to create new ftl-build containers including clang.

Unfortunately, there is currently a bug in alpine:edge that prevents us from creating new containers. While they updated gcc, they did not recompile libgmp using this new compiler, so far. This leads to a fatal error during linking time:

lto1: fatal error: bytecode stream in file '/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../lib/libgmp.a' generated with LTO version 13.0 instead of the expected 13.1
compilation terminated.
lto-wrapper: fatal error: /usr/bin/cc returned 1 exit status
compilation terminated.
/usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: error: lto-wrapper failed
collect2: error: ld returned 1 exit status

The proper fix for this to have the alpine team recompile libgmp as they seem to have done with most other packages already. See similar error 1 and 2 on ArchLinux.

@DL6ER
Copy link
Member Author

DL6ER commented May 17, 2024

Bug report opened upstream https://gitlab.alpinelinux.org/alpine/aports/-/issues/16121

DL6ER added 5 commits May 18, 2024 10:46
…l balways e linked statically

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
@DL6ER DL6ER changed the title Add Clang compiler support Add Clang compiler support and update project to C17 standard May 18, 2024
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

Copy link

Conflicts have been resolved.

DL6ER added 10 commits May 19, 2024 07:27
Signed-off-by: DL6ER <dl6er@dl6er.de>
…"#pragma message" is not supported by older clang versions

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
…ition detection working

Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
@DL6ER DL6ER force-pushed the new/clang branch 2 times, most recently from 1a73472 to f1506ee Compare May 21, 2024 18:08
@DL6ER
Copy link
Member Author

DL6ER commented May 21, 2024

The upstream bug has been fixed in alpine:edge via alpine/aports@6867589a.

@DL6ER
Copy link
Member Author

DL6ER commented May 21, 2024

This PR is done. It now awaits the decision on pi-hole/docker-base-images#94 and will then uses the tagged container (v2.6) as CI build environment.

DL6ER added 3 commits May 22, 2024 20:19
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
Signed-off-by: DL6ER <dl6er@dl6er.de>
@DL6ER DL6ER marked this pull request as ready for review May 25, 2024 07:59
@DL6ER
Copy link
Member Author

DL6ER commented May 25, 2024

Ready for review + merge

Copy link
Member

@yubiuser yubiuser left a comment

Choose a reason for hiding this comment

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

There are a few places where you removed some counter variables - why? Were they not used anymore and you just noticed yet?

E.g. totalcount in stats.c, num_clients in stats_database.c and elements ind validator.c

@DL6ER
Copy link
Member Author

DL6ER commented May 28, 2024

All changes were some due to compiler warnings triggered by the new C standard and additional warnings due to using clang next to gcc. No functional changes have been made.

I'm the particular case you found they were actually never used and clang complained about work being some without getting the result of it at any point. Assembly inspection showed that gcc chose to instead optimize these computations away silently.

@DL6ER DL6ER mentioned this pull request May 29, 2024
5 tasks
@DL6ER DL6ER merged commit 23d9476 into development-v6 May 29, 2024
18 checks passed
@DL6ER DL6ER deleted the new/clang branch May 29, 2024 17:19
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.

None yet

3 participants