From 6a945e1d2b6b9527432fbb604af2f44c9a2e7d75 Mon Sep 17 00:00:00 2001 From: Artemis Tosini Date: Mon, 13 May 2024 01:01:45 +0000 Subject: [PATCH] Fix build on FreeBSD FreeBSD defines environ in crt1.o, so allow undefined symbols when linking libraries to fix libutil build. Also set defines in libutil to fix boost headers. Change-Id: I094b8ac97469b26fd5d096617a58d7fd279103ae --- meson.build | 7 +++++++ misc/clangbuildanalyzer.nix | 2 +- src/libutil/fmt.hh | 2 +- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/meson.build b/meson.build index 16cf80cf4..233a21fad 100644 --- a/meson.build +++ b/meson.build @@ -138,6 +138,7 @@ message('canonical Nix system name:', host_system) is_linux = host_machine.system() == 'linux' is_darwin = host_machine.system() == 'darwin' +is_freebsd = host_machine.system() == 'freebsd' is_x64 = host_machine.cpu_family() == 'x86_64' # Per-platform arguments that you should probably pass to shared_module() invocations. @@ -454,6 +455,12 @@ if cxx.get_linker_id() in ['ld.bfd', 'ld.gold'] add_project_link_arguments('-Wl,--no-copy-dt-needed-entries', language : 'cpp') endif +if is_freebsd + # FreeBSD's `environ` is defined in `crt1.o`, not `libc.so`. + # + add_project_link_arguments('-Wl,-z,undefs', language: 'cpp') +endif + # Generate Chromium tracing files for each compiled file, which enables # maintainers/buildtime_report.sh BUILD-DIR to simply work in clang builds. # diff --git a/misc/clangbuildanalyzer.nix b/misc/clangbuildanalyzer.nix index d73fa8bbb..a4fa2b83c 100644 --- a/misc/clangbuildanalyzer.nix +++ b/misc/clangbuildanalyzer.nix @@ -27,7 +27,7 @@ stdenv.mkDerivation (finalAttrs: { platforms = lib.platforms.unix; # `long long int` != `size_t` # There's no convenient lib.platforms.32bit or anything, but it's easy enough to do ourselves. - badPlatforms = lib.filter (plat: (lib.systems.elaborate plat).is32bit) lib.platforms.all; + badPlatforms = (lib.filter (plat: (lib.systems.elaborate plat).is32bit) lib.platforms.all) ++ lib.platforms.freebsd; mainProgram = "ClangBuildAnalyzer"; }; }) diff --git a/src/libutil/fmt.hh b/src/libutil/fmt.hh index df4492993..3e447a668 100644 --- a/src/libutil/fmt.hh +++ b/src/libutil/fmt.hh @@ -6,7 +6,7 @@ #include #include // Darwin stdenv does not define _GNU_SOURCE but does have _Unwind_Backtrace. -#ifdef __APPLE__ +#if __APPLE__ || __FreeBSD__ #define BOOST_STACKTRACE_GNU_SOURCE_NOT_REQUIRED #endif #include