Skip to content

Commit ba3c03b

Browse files
authored
Merge pull request #2797 from aeolio/eventHorizon
Fix cross-compilation issues w/ custom toolchain
2 parents df0cd7c + 1fa09a8 commit ba3c03b

File tree

6 files changed

+67
-8
lines changed

6 files changed

+67
-8
lines changed

src/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,24 @@ add_subdirectory(config)
348348
add_subdirectory(tools)
349349
add_subdirectory(ntp)
350350
351+
# optional headers - may depend on type or version of the C standard library
352+
include(CheckIncludeFile)
353+
354+
check_include_file("sys/random.h" HAVE_RANDOM_H)
355+
if(HAVE_RANDOM_H)
356+
target_compile_definitions(config PRIVATE USE_GETRANDOM)
357+
target_compile_definitions(core PRIVATE USE_GETRANDOM)
358+
endif()
359+
360+
check_include_file("execinfo.h" HAVE_EXECINFO_H)
361+
if(HAVE_EXECINFO_H)
362+
message(STATUS "Building FTL with unwind support: YES")
363+
target_compile_definitions(core PRIVATE USE_BACKTRACE)
364+
else()
365+
message(STATUS "Building FTL with unwind support: NO")
366+
endif()
367+
368+
351369
option(USE_READLINE "Build FTL with readline support, if available" ON)
352370
353371
find_library(LIBREADLINE NAMES libreadline${LIBRARY_SUFFIX} readline)

src/daemon.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,10 @@ pid_t FTL_gettid(void);
4545

4646
// getrandom() is only available since glibc 2.25
4747
// https://www.gnu.org/software/gnulib/manual/html_node/sys_002frandom_002eh.html
48-
#if !defined(__GLIBC__) || __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 25)
48+
#if defined(USE_GETRANDOM)
4949
#include <sys/random.h>
5050
#else
51+
#define GRND_NONBLOCK 0x0001
5152
#define getrandom getrandom_fallback
5253
#endif
5354

src/signals.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
* Please see LICENSE file for your rights under this license. */
1010

1111
#include "FTL.h"
12-
#if defined(__GLIBC__)
12+
#if defined(USE_BACKTRACE)
13+
// backtrace(), backtrace_symbols()
1314
#include <execinfo.h>
1415
#endif
1516
#include "signals.h"
@@ -53,7 +54,7 @@ static char * __attribute__ ((nonnull (1))) getthread_name(char buffer[16])
5354
return buffer;
5455
}
5556

56-
#if defined(__GLIBC__)
57+
#if defined(USE_BACKTRACE)
5758
static void print_addr2line(const char *symbol, const void *address, const int j, const void *offset)
5859
{
5960
// Only do this analysis for our own binary (skip trying to analyse libc.so, etc.)
@@ -95,13 +96,13 @@ static void print_addr2line(const char *symbol, const void *address, const int j
9596
if(addr2line != NULL)
9697
pclose(addr2line);
9798
}
98-
#endif
99+
#endif // USE_BACKTRACE
99100

100101
// Log backtrace
101102
void generate_backtrace(void)
102103
{
103-
// Check GLIBC availability as MUSL does not support live backtrace generation
104-
#if defined(__GLIBC__)
104+
// Live backtrace generation is not supported by every C standard library
105+
#if defined(USE_BACKTRACE)
105106
// Try to obtain backtrace. This may not always be helpful, but it is better than nothing
106107
void *buffer[255];
107108
const int calls = backtrace(buffer, sizeof(buffer)/sizeof(void *));
@@ -137,7 +138,7 @@ void generate_backtrace(void)
137138
free(bcktrace);
138139
#else
139140
log_info("!!! INFO: pihole-FTL has not been compiled with glibc/backtrace support, not generating one !!!");
140-
#endif
141+
#endif // USE_BACKTRACE
141142
}
142143

143144
/**
@@ -210,8 +211,14 @@ static void __attribute__((noreturn)) signal_handler(int sig, siginfo_t *si, voi
210211
case BUS_ADRALN: log_info(" with code: BUS_ADRALN (Invalid address alignment)"); break;
211212
case BUS_ADRERR: log_info(" with code: BUS_ADRERR (Non-existent physical address)"); break;
212213
case BUS_OBJERR: log_info(" with code: BUS_OBJERR (Object specific hardware error)"); break;
214+
#if defined (BUS_MCEERR_AR)
215+
// 2025-May: not defined by uClibc
213216
case BUS_MCEERR_AR: log_info(" with code: BUS_MCEERR_AR (Hardware memory error: action required)"); break;
217+
#endif
218+
#if defined (BUS_MCEERR_AO)
219+
// 2025-May: not defined by uClibc
214220
case BUS_MCEERR_AO: log_info(" with code: BUS_MCEERR_AO (Hardware memory error: action optional)"); break;
221+
#endif
215222
default: log_info(" with code: Unknown (%i)", si->si_code); break;
216223
}
217224
}

src/tools/netlink.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,14 @@ static int nlparsemsg_link(struct ifinfomsg *ifi, void *buf, size_t len, cJSON *
610610
case IFLA_ALT_IFNAME:
611611
case IFLA_PHYS_PORT_NAME:
612612
case IFLA_QDISC:
613+
#if defined (IFLA_PARENT_DEV_NAME)
614+
// 2025-May: kernel version dependent
613615
case IFLA_PARENT_DEV_NAME:
616+
#endif
617+
#if defined (IFLA_PARENT_DEV_BUS_NAME)
618+
// 2025-May: kernel version dependent
614619
case IFLA_PARENT_DEV_BUS_NAME:
620+
#endif
615621
{
616622
if(!detailed)
617623
break;

src/tools/netlink_consts.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,10 @@ static struct flag_names iflatypes[] =
3737
{ ARPHRD_X25, "x25" },
3838
{ ARPHRD_HWX25, "hwx25" },
3939
{ ARPHRD_CAN, "can" },
40+
#if defined (ARPHRD_MCTP)
41+
// 2025-May: kernel version dependent
4042
{ ARPHRD_MCTP, "mctp" },
43+
#endif
4144
{ ARPHRD_PPP, "ppp" },
4245
{ ARPHRD_CISCO, "cisco" },
4346
{ ARPHRD_HDLC, "hdlc" },
@@ -145,7 +148,10 @@ static struct flag_names rtprots[] = {
145148
{ RTPROT_MROUTED, "mrouted" },
146149
{ RTPROT_KEEPALIVED, "keepalived" },
147150
{ RTPROT_BABEL, "babel" },
151+
#if defined (RTPROT_OPENR)
152+
// 2025-May: kernel version dependent
148153
{ RTPROT_OPENR, "openr" },
154+
#endif
149155
{ RTPROT_BGP, "bgp" },
150156
{ RTPROT_ISIS, "isis" },
151157
{ RTPROT_OSPF, "ospf" },
@@ -185,7 +191,10 @@ static struct flag_names rtmflags[] = {
185191
{ RTM_F_FIB_MATCH, "fib_match" },
186192
{ RTM_F_OFFLOAD, "offload" },
187193
{ RTM_F_TRAP, "trap" },
194+
#if defined (RTM_F_OFFLOAD_FAILED)
195+
// 2025-May: kernel version dependent
188196
{ RTM_F_OFFLOAD_FAILED, "offload_failed" },
197+
#endif
189198
};
190199

191200
static struct flag_names rtnhflags[] = {
@@ -195,7 +204,10 @@ static struct flag_names rtnhflags[] = {
195204
{ RTNH_F_OFFLOAD, "offload" },
196205
{ RTNH_F_LINKDOWN, "linkdown" },
197206
{ RTNH_F_UNRESOLVED, "unresolved" },
207+
#if defined (RTNH_F_TRAP)
208+
// 2025-May: kernel version dependent
198209
{ RTNH_F_TRAP, "trap" },
210+
#endif
199211
};
200212

201213
static struct flag_names ifstates[] = {
@@ -439,10 +451,16 @@ static const char *__attribute__ ((const)) iflaTypeToString(const int ifla_type)
439451
return "perm_address";
440452
case IFLA_PROTO_DOWN_REASON:
441453
return "proto_down_reason";
454+
#if defined (IFLA_PARENT_DEV_NAME)
455+
// 2025-May: kernel version dependent
442456
case IFLA_PARENT_DEV_NAME:
443457
return "parent_dev_name";
458+
#endif
459+
#if defined (IFLA_PARENT_DEV_BUS_NAME)
460+
// 2025-May: kernel version dependent
444461
case IFLA_PARENT_DEV_BUS_NAME:
445462
return "parent_dev_bus_name";
463+
#endif
446464
default:
447465
return "unknown";
448466
}
@@ -522,10 +540,16 @@ static const char *__attribute__ ((const)) family_name(int family)
522540
return "wanpipe";
523541
case PF_LLC:
524542
return "llc";
543+
#if defined (PF_IB)
544+
// 2025-May: defined by glibc but not uClibc
525545
case PF_IB:
526546
return "ib";
547+
#endif
548+
#if defined (PF_MPLS)
549+
// 2025-May: defined by glibc but not uClibc
527550
case PF_MPLS:
528551
return "mpls";
552+
#endif
529553
case PF_CAN:
530554
return "can";
531555
case PF_TIPC:
@@ -556,8 +580,11 @@ static const char *__attribute__ ((const)) family_name(int family)
556580
return "qipcrtr";
557581
case PF_SMC:
558582
return "smc";
583+
#if defined (PF_XDP)
584+
// 2025-May: defined by glibc but not uClibc
559585
case PF_XDP:
560586
return "xdp";
587+
#endif
561588
#ifdef PF_MCTP
562589
// 2024-July: defined by glibc but not musl
563590
case PF_MCTP:

src/webserver/civetweb/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,5 @@ target_compile_definitions(civetweb PRIVATE NO_CGI
3232
USE_LUA
3333
TIMER_RESOLUTION=1000)
3434

35-
include_directories(${PROJECT_SOURCE_DIR}/src/lua /usr/local/include)
35+
include_directories(${PROJECT_SOURCE_DIR}/src/lua)
3636
target_include_directories(civetweb PRIVATE ${PROJECT_SOURCE_DIR}/src)

0 commit comments

Comments
 (0)