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.
This commit is contained in:
Undefine 2025-06-30 09:39:46 +02:00 committed by Andrew Kaster
commit 2aa8c950ca
Notes: github-actions[bot] 2025-07-15 19:46:35 +00:00
2 changed files with 7 additions and 1 deletions

View file

@ -13,6 +13,9 @@
#if defined(AK_OS_MACOS) || defined(AK_OS_IOS) #if defined(AK_OS_MACOS) || defined(AK_OS_IOS)
# include <crt_externs.h> # include <crt_externs.h>
#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) #elif !defined(AK_OS_WINDOWS)
extern "C" char** environ; extern "C" char** environ;
#endif #endif

View file

@ -75,8 +75,11 @@ if (NOT WIN32 AND NOT APPLE AND NOT ENABLE_FUZZERS)
else() else()
add_link_options(LINKER:-z,defs) add_link_options(LINKER:-z,defs)
add_link_options(LINKER:--no-undefined) add_link_options(LINKER:--no-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) add_link_options(LINKER:--no-allow-shlib-undefined)
endif() endif()
endif()
endif() endif()
if (ENABLE_LAGOM_COVERAGE_COLLECTION) if (ENABLE_LAGOM_COVERAGE_COLLECTION)