Skip to content

Commit 67ded46

Browse files
committed
Merge remote-tracking branch 'luoh/develop' into develop
2 parents a2281ce + 67ecfd3 commit 67ded46

File tree

4 files changed

+70
-4
lines changed

4 files changed

+70
-4
lines changed

include/boost/dll/alias.hpp

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,30 @@ namespace boost { namespace dll {
180180
namespace _autoaliases { \
181181
extern "C" BOOST_SYMBOL_EXPORT const void *FunctionOrVar; \
182182
} /* namespace _autoaliases */ \
183-
/**/
184-
#else
183+
/**/
184+
#elif BOOST_OS_CYGWIN
185+
#define BOOST_DLL_ALIAS_SECTIONED(FunctionOrVar, AliasName, SectionName) \
186+
namespace _autoaliases { \
187+
extern "C" BOOST_SYMBOL_EXPORT const void *AliasName; \
188+
BOOST_DLL_SECTION(SectionName, read) \
189+
const void * AliasName = reinterpret_cast<const void*>(reinterpret_cast<intptr_t>( \
190+
&FunctionOrVar \
191+
)); \
192+
} /* namespace _autoaliases */ \
193+
/**/
194+
195+
#define BOOST_DLL_AUTO_ALIAS(FunctionOrVar) \
196+
namespace _autoaliases { \
197+
const void * dummy_ ## FunctionOrVar \
198+
= reinterpret_cast<const void*>(reinterpret_cast<intptr_t>( \
199+
&FunctionOrVar \
200+
)); \
201+
extern "C" BOOST_SYMBOL_EXPORT const void *FunctionOrVar; \
202+
BOOST_DLL_SECTION(boostdll, read) \
203+
const void * FunctionOrVar = dummy_ ## FunctionOrVar; \
204+
} /* namespace _autoaliases */ \
205+
/**/
206+
#else
185207
// Note: we can not use `aggressive_ptr_cast` here, because in that case GCC applies
186208
// different permissions to the section and it causes Segmentation fault.
187209
// Note: we can not use `std::addressof()` here, because in that case GCC

include/boost/dll/detail/posix/path_from_handle.hpp

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,15 @@ namespace boost { namespace dll { namespace detail {
104104
#if BOOST_OS_QNX
105105
// QNX's copy of <elf.h> and <link.h> reside in sys folder
106106
# include <sys/link.h>
107+
#elif BOOST_OS_CYGWIN
108+
// Cygwin returns the opaque pointer-sized handle of type `HMODULE` on the invoke of `dlopen`,
109+
// which cannot be interpreted. As GCC on Cygwin always links to KERNEL32.DLL, we can use the
110+
// standard Win32 API `GetModuleFileNameW` to implement `path_from_handle`
111+
//
112+
// Introduce the Win32 API `GetModuleFileNameW` here
113+
extern "C" void GetModuleFileNameW(void*, wchar_t*, unsigned long long);
114+
// Introduce the Win32 API `GetLastError` here
115+
extern "C" unsigned long long GetLastError();
107116
#else
108117
# include <link.h> // struct link_map
109118
#endif
@@ -129,9 +138,29 @@ namespace boost { namespace dll { namespace detail {
129138
// Unfortunately we can not use `dlinfo(handle, RTLD_DI_LINKMAP, &link_map) < 0`
130139
// because it is not supported on MacOS X 10.3, NetBSD 3.0, OpenBSD 3.8, AIX 5.1,
131140
// HP-UX 11, IRIX 6.5, OSF/1 5.1, Cygwin, mingw, Interix 3.5, BeOS.
132-
// Fortunately investigating the sources of open source projects brought the understanding, that
141+
// Fortunately, investigating the sources of open source projects brought the understanding, that
133142
// `handle` is just a `struct link_map*` that contains full library name.
134143

144+
#if BOOST_OS_CYGWIN
145+
// Cygwin doesn't have <link.h> header
146+
unsigned long long buffer_size = 4096;
147+
std::vector<wchar_t> buffer;
148+
do
149+
{
150+
buffer.resize(buffer_size);
151+
GetModuleFileNameW(handle, buffer.data(), buffer.size());
152+
buffer_size *= 2;
153+
} while (GetLastError() == 122 /* ERROR_INSUFFICIENT_BUFFER */);
154+
if (GetLastError() == 0)
155+
{
156+
return boost::filesystem::path(buffer.data());
157+
} else
158+
{
159+
boost::dll::detail::reset_dlerror();
160+
ec = std::make_error_code(std::errc::bad_file_descriptor);
161+
return boost::filesystem::path();
162+
}
163+
#else
135164
const struct link_map* link_map = 0;
136165
#if BOOST_OS_BSD_FREE
137166
// FreeBSD has it's own logic http://code.metager.de/source/xref/freebsd/libexec/rtld-elf/rtld.c
@@ -156,6 +185,7 @@ namespace boost { namespace dll { namespace detail {
156185
}
157186

158187
return boost::dll::fs::path(link_map->l_name);
188+
#endif
159189
}
160190

161191
}}} // namespace boost::dll::detail

include/boost/dll/detail/posix/shared_library_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include <dlfcn.h>
2222
#include <cstring> // strncmp
23-
#if !BOOST_OS_MACOS && !BOOST_OS_IOS && !BOOST_OS_QNX
23+
#if !BOOST_OS_MACOS && !BOOST_OS_IOS && !BOOST_OS_QNX && !BOOST_OS_CYGWIN
2424
# include <link.h>
2525
#elif BOOST_OS_QNX
2626
// QNX's copy of <elf.h> and <link.h> reside in sys folder

include/boost/dll/runtime_symbol_info.hpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,20 @@
1717
# include <boost/winapi/dll.hpp>
1818
# include <boost/dll/detail/windows/path_from_handle.hpp>
1919
#else
20+
#if BOOST_OS_CYGWIN
21+
// `Dl_info` & `dladdr` is hidden by `__GNU_VISIBLE`
22+
typedef struct Dl_info Dl_info;
23+
24+
struct Dl_info
25+
{
26+
char dli_fname[PATH_MAX]; /* Filename of defining object */
27+
void *dli_fbase; /* Load address of that object */
28+
const char *dli_sname; /* Name of nearest lower symbol */
29+
void *dli_saddr; /* Exact value of nearest symbol */
30+
};
31+
32+
extern "C" int dladdr (const void *addr, Dl_info *info);
33+
#endif
2034
# include <dlfcn.h>
2135
# include <boost/dll/detail/posix/program_location_impl.hpp>
2236
#endif

0 commit comments

Comments
 (0)