pi-hole / FTL

The Pi-hole FTL engine
https://pi-hole.net
Other
1.34k stars 187 forks source link

Add Clang compiler support and update project to C17 standard #1962

Closed DL6ER closed 1 month ago

DL6ER commented 1 month ago

What does this implement/fix?

Add Clang compiler support, tested with

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:

DL6ER commented 1 month ago

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 commented 1 month ago

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

github-actions[bot] commented 1 month ago

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

github-actions[bot] commented 1 month ago

Conflicts have been resolved.

DL6ER commented 1 month ago

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

DL6ER commented 1 month ago

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

DL6ER commented 1 month ago

Ready for review + merge

DL6ER commented 1 month ago

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.