Skip to content

Fix cross-compilation issues w/ custom toolchain#2797

Merged
DL6ER merged 6 commits intopi-hole:developmentfrom
aeolio:eventHorizon
Mar 6, 2026
Merged

Fix cross-compilation issues w/ custom toolchain#2797
DL6ER merged 6 commits intopi-hole:developmentfrom
aeolio:eventHorizon

Conversation

@aeolio
Copy link

@aeolio aeolio commented Mar 6, 2026

What does this PR aim to accomplish?:

Trying to build Pi-hole inside a Buildroot build environment, I ran into a few issues. Most are related to the custom toolchain used (i586 /GCC 15 /uClibc /kernel headers 5.10 /binutils 2.45.1).

I have not squashed my commits, because I think they are easier to read and review if left separate.
I stole one change shamelessly from #2762 (it was also in my backlog, but @rehsack showed that the additional path could be omitted).

4afe481
Absolute include in path in webserver/civetweb/CMakeLists.txt prevents cross-compilation.

edfb685
The getrandom() fallback has not been used for some time and needed fixing.

3408d23 and 3e3f635
The __GLIBC__ macro is also used by uClibc, but the version information is outdated. This notoriously causes problems also in other projects.

e3a3b6e and 1fa09a8
Precompiler symbols missing in the toolchain, some related to uClibc, most to the kernel version. Linux 5.10 is a LTS version, and will be supported for another 10 years by the CIP project.

How does this PR accomplish the above?:

A number of precompiler checks were introduced for missing symbols. Unless self explanatory, they were commented in the prevalent style.

The most significant change is the insertion of logic in CMakelists.txt to detect optional include files (sys/random.h, execinfo.h). This allows replacing of unreadable and often problematic C library detection code with monotonic symbols generated by CMake.

Link documentation PRs if any are needed to support this PR:

(No change in functionality)


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 and I have tested my changes.
  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)
  6. I have checked that another pull request for this purpose does not exist.
  7. I have considered, and confirmed that this submission will be valuable to others.
  8. I accept that this submission may not be used, and the pull request closed at the will of the maintainer.
  9. I give this submission freely, and claim no ownership to its content.

  • I have read the above and my PR is ready for review. Check this box to confirm

aeolio added 6 commits March 6, 2026 05:35
Most cross-compilation tools terminate the build, when they encounter
unsafe (e.g. absolute) paths in include directives, because that might
leak host components into the target. Buildroot fails with:

i586-buildroot-linux-uclibc-gcc: ERROR: unsafe header/library path used in cross-compilation: '-I/usr/local/include'

Remove offending path snippet to correspond with all other include
definitions in Pi-hole/FTL.

Signed-off-by: Andreas Ziegler <15275159+aeolio@users.noreply.github.com>
If sys/random.h cannot be found, the build terminates with this error:

pihole-ftl-6.5/src/config/password.c: In function ‘get_secure_randomness’:
pihole-ftl-6.5/src/config/password.c:100:52: error: ‘GRND_NONBLOCK’ undeclared (first use in this function); did you mean ‘SOCK_NONBLOCK’?
  100 |                 result = getrandom(buffer, length, GRND_NONBLOCK);
      |                                                    ^~~~~~~~~~~~~
      |                                                    SOCK_NONBLOCK

Add the missing definition of GRND_NONBLOCK in daemon.h.

Signed-off-by: Andreas Ziegler <15275159+aeolio@users.noreply.github.com>
The __GLIBC__ version check causes problems with uClibc, because
this library also defines these variables, but the numbering is not
consistent with GNU libc. This prevents the inclusion of sys/random.h
in a uClibc toolchain, even if the file is present

Instead let CMake detect sys/random.h and control header inclusion
with a preprocessor symbol.

Signed-off-by: Andreas Ziegler <15275159+aeolio@users.noreply.github.com>
The __GLIBC__ logic to detect stack backtracing capability fails for
uClibc, because uClibc also defines these symbols, but backtrace
functionality is optional.

pihole-ftl-6.5/src/signals.c:13:10: fatal error: execinfo.h: No such file or directory
   13 | #include <execinfo.h>
      |          ^~~~~~~~~~~~

Instead of adding unreadable preprocessor exceptions, have CMake detect
execinfo.h and use a appropriate preprocessor symbol.

Signed-off-by: Andreas Ziegler <15275159+aeolio@users.noreply.github.com>
Building with a custom toolchain (GCC 15, uClibc, kernel headers 5.10)
fails in netlink.c with errors like these:

pihole-ftl-6.5/src/tools/netlink_consts.h:40:11: error: ‘ARPHRD_MCTP’ undeclared here (not in a function); did you mean ‘ARPHRD_FCPP’?
   40 |         { ARPHRD_MCTP, "mctp" },
      |           ^~~~~~~~~~~
      |           ARPHRD_FCPP
pihole-ftl-6.5/src/tools/netlink_consts.h:148:11: error: ‘RTPROT_OPENR’ undeclared here (not in a function); did you mean ‘RTPROT_OSPF’?
  148 |         { RTPROT_OPENR, "openr" },
      |           ^~~~~~~~~~~~
      |           RTPROT_OSPF

Bracket undeclared symbols with precompiler directives.

Signed-off-by: Andreas Ziegler <15275159+aeolio@users.noreply.github.com>
Building with a custom toolchain (GCC 15, uClibc, kernel headers 5.10)
fails in netlink.c with errors like these:

pihole-ftl-6.5/src/signals.c:214:30: error: ‘BUS_MCEERR_AR’ undeclared (first use in this function)
  214 |                         case BUS_MCEERR_AR: log_info("     with code:  BUS_MCEERR_AR (Hardware memory error: action required)"); break;
      |                              ^~~~~~~~~~~~~
pihole-ftl-6.5/src/signals.c:214:30: note: each undeclared identifier is reported only once for each function it appears in
pihole-ftl-6.5/src/signals.c:215:30: error: ‘BUS_MCEERR_AO’ undeclared (first use in this function)
  215 |                         case BUS_MCEERR_AO: log_info("     with code:  BUS_MCEERR_AO (Hardware memory error: action optional)"); break;
      |                              ^~~~~~~~~~~~~

Bracket undeclared symbols with precompiler directives.

Signed-off-by: Andreas Ziegler <15275159+aeolio@users.noreply.github.com>
@aeolio aeolio requested a review from a team as a code owner March 6, 2026 07:19
@DL6ER DL6ER merged commit ba3c03b into pi-hole:development Mar 6, 2026
19 of 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.

2 participants