From 2aa8c950caff9ec26be567b28f7c16c4d71ea3f7 Mon Sep 17 00:00:00 2001 From: Undefine Date: Mon, 30 Jun 2025 09:39:46 +0200 Subject: [PATCH] LibCore+Meta: Workaround some symbols not being exported on FreeBSD On FreeBSD some symbols like `environ` or `__progname` are not exported anywhere and are filled in by the dynamic loader. `environ` is a special case because we make use of it explicitly so we need to mark it a weak symbol so the linker doesn't complain. --- Libraries/LibCore/Environment.cpp | 3 +++ Meta/CMake/lagom_compile_options.cmake | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Libraries/LibCore/Environment.cpp b/Libraries/LibCore/Environment.cpp index b377bf7f5fd..6e1f895704a 100644 --- a/Libraries/LibCore/Environment.cpp +++ b/Libraries/LibCore/Environment.cpp @@ -13,6 +13,9 @@ #if defined(AK_OS_MACOS) || defined(AK_OS_IOS) # include +#elif defined(AK_OS_FREEBSD) +// FIXME: Remove this once FreeBSD exports environ from libc +extern "C" __attribute__((weak)) char** environ; #elif !defined(AK_OS_WINDOWS) extern "C" char** environ; #endif diff --git a/Meta/CMake/lagom_compile_options.cmake b/Meta/CMake/lagom_compile_options.cmake index ceab3ba37a3..86100743327 100644 --- a/Meta/CMake/lagom_compile_options.cmake +++ b/Meta/CMake/lagom_compile_options.cmake @@ -75,7 +75,10 @@ if (NOT WIN32 AND NOT APPLE AND NOT ENABLE_FUZZERS) else() add_link_options(LINKER:-z,defs) add_link_options(LINKER:--no-undefined) - add_link_options(LINKER:--no-allow-shlib-undefined) + # FIXME: Remove this once FreeBSD exports environ from libc + if (NOT CMAKE_SYSTEM_NAME MATCHES "FreeBSD") + add_link_options(LINKER:--no-allow-shlib-undefined) + endif() endif() endif()