stabilize build system: depends, installer, boost/bdb fixes, cross targets groundwork

This commit is contained in:
2026-02-24 18:38:47 +00:00
parent da8c28aaeb
commit 65cb2619a7
13106 changed files with 2484322 additions and 1804 deletions
@@ -0,0 +1,169 @@
// Copyright 2014-2015 Renato Tegon Forti, Antony Polukhin.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_DLL_DETAIL_POSIX_PATH_FROM_HANDLE_HPP
#define BOOST_DLL_DETAIL_POSIX_PATH_FROM_HANDLE_HPP
#include <boost/config.hpp>
#include <boost/dll/detail/system_error.hpp>
#include <boost/dll/detail/posix/program_location_impl.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/predef/os.h>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#if BOOST_OS_MACOS || BOOST_OS_IOS
# include <mach-o/dyld.h>
# include <mach-o/nlist.h>
# include <cstddef> // for std::ptrdiff_t
namespace boost { namespace dll { namespace detail {
inline void* strip_handle(void* handle) BOOST_NOEXCEPT {
return reinterpret_cast<void*>(
(reinterpret_cast<std::ptrdiff_t>(handle) >> 2) << 2
);
}
inline boost::filesystem::path path_from_handle(void* handle, boost::system::error_code &ec) {
handle = strip_handle(handle);
// Iterate through all images currently in memory
// https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man3/dyld.3.html
const std::size_t count = _dyld_image_count(); // not thread safe: other thread my [un]load images
for (std::size_t i = 0; i <= count; ++i) {
// on last iteration `i` is equal to `count` which is out of range, so `_dyld_get_image_name`
// will return NULL. `dlopen(NULL, RTLD_LAZY)` call will open the current executable.
const char* image_name = _dyld_get_image_name(i);
// dlopen/dlclose must not affect `_dyld_image_count()`, because libraries are already loaded and only the internal counter is affected
void* probe_handle = dlopen(image_name, RTLD_LAZY);
dlclose(probe_handle);
// If the handle is the same as what was passed in (modulo mode bits), return this image name
if (handle == strip_handle(probe_handle)) {
boost::dll::detail::reset_dlerror();
return image_name;
}
}
boost::dll::detail::reset_dlerror();
ec = boost::system::error_code(
boost::system::errc::bad_file_descriptor,
boost::system::generic_category()
);
return boost::filesystem::path();
}
}}} // namespace boost::dll::detail
#elif BOOST_OS_ANDROID
#include <boost/dll/runtime_symbol_info.hpp>
namespace boost { namespace dll { namespace detail {
struct soinfo {
// if defined(__work_around_b_24465209__), then an array of char[128] goes here.
// Unfortunately, __work_around_b_24465209__ is visible only during compilation of Android's linker
const void* phdr;
size_t phnum;
void* entry;
void* base;
// ... // Ignoring remaning parts of the structure
};
inline boost::filesystem::path path_from_handle(const void* handle, boost::system::error_code &ec) {
static const std::size_t work_around_b_24465209__offset = 128;
const struct soinfo* si = reinterpret_cast<const struct soinfo*>(
static_cast<const char*>(handle) + work_around_b_24465209__offset
);
boost::filesystem::path ret = boost::dll::symbol_location_ptr(si->base, ec);
if (ec) {
ec.clear();
si = static_cast<const struct soinfo*>(handle);
return boost::dll::symbol_location_ptr(si->base, ec);
}
return ret;
}
}}} // namespace boost::dll::detail
#else // #if BOOST_OS_MACOS || BOOST_OS_IOS || BOOST_OS_ANDROID
// for dlinfo
#include <dlfcn.h>
#if BOOST_OS_QNX
// QNX's copy of <elf.h> and <link.h> reside in sys folder
# include <sys/link.h>
#else
# include <link.h> // struct link_map
#endif
namespace boost { namespace dll { namespace detail {
#if BOOST_OS_QNX
// Android and QNX miss struct link_map. QNX misses ElfW macro, so avoiding it.
struct link_map {
void *l_addr; // Base address shared object is loaded at
char *l_name; // Absolute file name object was found in
// ... // Ignoring remaning parts of the structure
};
#endif // #if BOOST_OS_QNX
inline boost::filesystem::path path_from_handle(void* handle, boost::system::error_code &ec) {
// RTLD_DI_LINKMAP (RTLD_DI_ORIGIN returns only folder and is not suitable for this case)
// Obtain the Link_map for the handle that is specified.
// The p argument points to a Link_map pointer (Link_map
// **p). The actual storage for the Link_map structure is
// maintained by ld.so.1.
//
// Unfortunately we can not use `dlinfo(handle, RTLD_DI_LINKMAP, &link_map) < 0`
// because it is not supported on MacOS X 10.3, NetBSD 3.0, OpenBSD 3.8, AIX 5.1,
// HP-UX 11, IRIX 6.5, OSF/1 5.1, Cygwin, mingw, Interix 3.5, BeOS.
// Fortunately investigating the sources of open source projects brought the understanding, that
// `handle` is just a `struct link_map*` that contains full library name.
const struct link_map* link_map = 0;
#if BOOST_OS_BSD_FREE
// FreeBSD has it's own logic http://code.metager.de/source/xref/freebsd/libexec/rtld-elf/rtld.c
// Fortunately it has the dlinfo call.
if (dlinfo(handle, RTLD_DI_LINKMAP, &link_map) < 0) {
link_map = 0;
}
#else
link_map = static_cast<const struct link_map*>(handle);
#endif
if (!link_map) {
boost::dll::detail::reset_dlerror();
ec = boost::system::error_code(
boost::system::errc::bad_file_descriptor,
boost::system::generic_category()
);
return boost::filesystem::path();
}
if (!link_map->l_name || *link_map->l_name == '\0') {
return program_location_impl(ec);
}
return boost::filesystem::path(link_map->l_name);
}
}}} // namespace boost::dll::detail
#endif // #if BOOST_OS_MACOS || BOOST_OS_IOS
#endif // BOOST_DLL_DETAIL_POSIX_PATH_FROM_HANDLE_HPP
@@ -0,0 +1,140 @@
// Copyright 2014 Renato Tegon Forti, Antony Polukhin.
// Copyright 2015 Antony Polukhin.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_DLL_DETAIL_POSIX_PROGRAM_LOCATION_IMPL_HPP
#define BOOST_DLL_DETAIL_POSIX_PROGRAM_LOCATION_IMPL_HPP
#include <boost/config.hpp>
#include <boost/dll/detail/system_error.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/predef/os.h>
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
#if BOOST_OS_MACOS || BOOST_OS_IOS
#include <mach-o/dyld.h>
namespace boost { namespace dll { namespace detail {
inline boost::filesystem::path program_location_impl(boost::system::error_code &ec) {
ec.clear();
char path[1024];
uint32_t size = sizeof(path);
if (_NSGetExecutablePath(path, &size) == 0)
return boost::filesystem::path(path);
char *p = new char[size];
if (_NSGetExecutablePath(p, &size) != 0) {
ec = boost::system::error_code(
boost::system::errc::bad_file_descriptor,
boost::system::generic_category()
);
}
boost::filesystem::path ret(p);
delete[] p;
return ret;
}
}}} // namespace boost::dll::detail
#elif BOOST_OS_SOLARIS
#include <stdlib.h>
namespace boost { namespace dll { namespace detail {
inline boost::filesystem::path program_location_impl(boost::system::error_code& ec) {
ec.clear();
return boost::filesystem::path(getexecname());
}
}}} // namespace boost::dll::detail
#elif BOOST_OS_BSD_FREE
#include <sys/types.h>
#include <sys/sysctl.h>
#include <stdlib.h>
namespace boost { namespace dll { namespace detail {
inline boost::filesystem::path program_location_impl(boost::system::error_code& ec) {
ec.clear();
int mib[4];
mib[0] = CTL_KERN;
mib[1] = KERN_PROC;
mib[2] = KERN_PROC_PATHNAME;
mib[3] = -1;
char buf[10240];
size_t cb = sizeof(buf);
sysctl(mib, 4, buf, &cb, NULL, 0);
return boost::filesystem::path(buf);
}
}}} // namespace boost::dll::detail
#elif BOOST_OS_BSD_NET
#include <boost/filesystem/operations.hpp>
namespace boost { namespace dll { namespace detail {
inline boost::filesystem::path program_location_impl(boost::system::error_code &ec) {
return boost::filesystem::read_symlink("/proc/curproc/exe", ec);
}
}}} // namespace boost::dll::detail
#elif BOOST_OS_BSD_DRAGONFLY
#include <boost/filesystem/operations.hpp>
namespace boost { namespace dll { namespace detail {
inline boost::filesystem::path program_location_impl(boost::system::error_code &ec) {
return boost::filesystem::read_symlink("/proc/curproc/file", ec);
}
}}} // namespace boost::dll::detail
#elif BOOST_OS_QNX
#include <fstream>
#include <string> // for std::getline
namespace boost { namespace dll { namespace detail {
inline boost::filesystem::path program_location_impl(boost::system::error_code &ec) {
ec.clear();
std::string s;
std::ifstream ifs("/proc/self/exefile");
std::getline(ifs, s);
if (ifs.fail() || s.empty()) {
ec = boost::system::error_code(
boost::system::errc::bad_file_descriptor,
boost::system::generic_category()
);
}
return boost::filesystem::path(s);
}
}}} // namespace boost::dll::detail
#else // BOOST_OS_LINUX || BOOST_OS_UNIX || BOOST_OS_HPUX || BOOST_OS_ANDROID
#include <boost/filesystem/operations.hpp>
namespace boost { namespace dll { namespace detail {
inline boost::filesystem::path program_location_impl(boost::system::error_code &ec) {
// We can not use
// boost::dll::detail::path_from_handle(dlopen(NULL, RTLD_LAZY | RTLD_LOCAL), ignore);
// because such code returns empty path.
return boost::filesystem::read_symlink("/proc/self/exe", ec); // Linux specific
}
}}} // namespace boost::dll::detail
#endif
#endif // BOOST_DLL_DETAIL_POSIX_PROGRAM_LOCATION_IMPL_HPP
@@ -0,0 +1,215 @@
// Copyright 2014 Renato Tegon Forti, Antony Polukhin.
// Copyright 2015-2016 Antony Polukhin.
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt
// or copy at http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_DLL_SHARED_LIBRARY_IMPL_HPP
#define BOOST_DLL_SHARED_LIBRARY_IMPL_HPP
#include <boost/config.hpp>
#include <boost/dll/shared_library_load_mode.hpp>
#include <boost/dll/detail/posix/path_from_handle.hpp>
#include <boost/dll/detail/posix/program_location_impl.hpp>
#include <boost/move/utility.hpp>
#include <boost/swap.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/predef/os.h>
#include <dlfcn.h>
#include <cstring> // strncmp
#if !BOOST_OS_MACOS && !BOOST_OS_IOS && !BOOST_OS_QNX
# include <link.h>
#elif BOOST_OS_QNX
// QNX's copy of <elf.h> and <link.h> reside in sys folder
# include <sys/link.h>
#endif
#ifdef BOOST_HAS_PRAGMA_ONCE
# pragma once
#endif
namespace boost { namespace dll { namespace detail {
class shared_library_impl {
BOOST_MOVABLE_BUT_NOT_COPYABLE(shared_library_impl)
public:
typedef void* native_handle_t;
shared_library_impl() BOOST_NOEXCEPT
: handle_(NULL)
{}
~shared_library_impl() BOOST_NOEXCEPT {
unload();
}
shared_library_impl(BOOST_RV_REF(shared_library_impl) sl) BOOST_NOEXCEPT
: handle_(sl.handle_)
{
sl.handle_ = NULL;
}
shared_library_impl & operator=(BOOST_RV_REF(shared_library_impl) sl) BOOST_NOEXCEPT {
swap(sl);
return *this;
}
void load(boost::filesystem::path sl, load_mode::type mode, boost::system::error_code &ec) {
typedef int native_mode_t;
unload();
// Do not allow opening NULL paths. User must use program_location() instead
if (sl.empty()) {
boost::dll::detail::reset_dlerror();
ec = boost::system::error_code(
boost::system::errc::bad_file_descriptor,
boost::system::generic_category()
);
return;
}
// Fixing modes
if (!(mode & load_mode::rtld_now)) {
mode |= load_mode::rtld_lazy;
}
if (!(mode & load_mode::rtld_global)) {
mode |= load_mode::rtld_local;
}
#if BOOST_OS_LINUX || BOOST_OS_ANDROID
if (!sl.has_parent_path() && !(mode & load_mode::search_system_folders)) {
sl = "." / sl;
}
#else
if (!sl.is_absolute() && !(mode & load_mode::search_system_folders)) {
boost::system::error_code current_path_ec;
boost::filesystem::path prog_loc = boost::filesystem::current_path(current_path_ec);
if (!current_path_ec) {
prog_loc /= sl;
sl.swap(prog_loc);
}
}
#endif
mode &= ~load_mode::search_system_folders;
// Trying to open with appended decorations
if (!!(mode & load_mode::append_decorations)) {
mode &= ~load_mode::append_decorations;
boost::filesystem::path actual_path = (
std::strncmp(sl.filename().string().c_str(), "lib", 3)
? (sl.has_parent_path() ? sl.parent_path() / L"lib" : L"lib").native() + sl.filename().native()
: sl
);
actual_path += suffix();
handle_ = dlopen(actual_path.c_str(), static_cast<native_mode_t>(mode));
if (handle_) {
boost::dll::detail::reset_dlerror();
return;
}
}
// Opening by exactly specified path
handle_ = dlopen(sl.c_str(), static_cast<native_mode_t>(mode));
if (handle_) {
boost::dll::detail::reset_dlerror();
return;
}
ec = boost::system::error_code(
boost::system::errc::bad_file_descriptor,
boost::system::generic_category()
);
// Maybe user wanted to load the executable itself? Checking...
// We assume that usually user wants to load a dynamic library not the executable itself, that's why
// we try this only after traditional load fails.
boost::system::error_code prog_loc_err;
boost::filesystem::path loc = boost::dll::detail::program_location_impl(prog_loc_err);
if (!prog_loc_err && boost::filesystem::equivalent(sl, loc, prog_loc_err) && !prog_loc_err) {
// As is known the function dlopen() loads the dynamic library file
// named by the null-terminated string filename and returns an opaque
// "handle" for the dynamic library. If filename is NULL, then the
// returned handle is for the main program.
ec.clear();
boost::dll::detail::reset_dlerror();
handle_ = dlopen(NULL, static_cast<native_mode_t>(mode));
if (!handle_) {
ec = boost::system::error_code(
boost::system::errc::bad_file_descriptor,
boost::system::generic_category()
);
}
}
}
bool is_loaded() const BOOST_NOEXCEPT {
return (handle_ != 0);
}
void unload() BOOST_NOEXCEPT {
if (!is_loaded()) {
return;
}
dlclose(handle_);
handle_ = 0;
}
void swap(shared_library_impl& rhs) BOOST_NOEXCEPT {
boost::swap(handle_, rhs.handle_);
}
boost::filesystem::path full_module_path(boost::system::error_code &ec) const {
return boost::dll::detail::path_from_handle(handle_, ec);
}
static boost::filesystem::path suffix() {
// https://sourceforge.net/p/predef/wiki/OperatingSystems/
#if BOOST_OS_MACOS || BOOST_OS_IOS
return ".dylib";
#else
return ".so";
#endif
}
void* symbol_addr(const char* sb, boost::system::error_code &ec) const BOOST_NOEXCEPT {
// dlsym - obtain the address of a symbol from a dlopen object
void* const symbol = dlsym(handle_, sb);
if (symbol == NULL) {
ec = boost::system::error_code(
boost::system::errc::invalid_seek,
boost::system::generic_category()
);
}
// If handle does not refer to a valid object opened by dlopen(),
// or if the named symbol cannot be found within any of the objects
// associated with handle, dlsym() shall return NULL.
// More detailed diagnostic information shall be available through dlerror().
return symbol;
}
native_handle_t native() const BOOST_NOEXCEPT {
return handle_;
}
private:
native_handle_t handle_;
};
}}} // boost::dll::detail
#endif // BOOST_DLL_SHARED_LIBRARY_IMPL_HPP