Skip to content

Commit 747ff24

Browse files
mergify[bot]Tobias-Fischerahcorde
authored
Add emscripten guards to shared_library.c's dlopen path (backport ros2#591) (ros2#601)
(cherry picked from commit a2d8f50) Signed-off-by: Alejandro Hernandez Cordero <ahcorde@gmail.com> Co-authored-by: Tobias Fischer <info@tobiasfischer.info> Co-authored-by: Alejandro Hernandez Cordero <ahcorde@gmail.com>
1 parent 3214e35 commit 747ff24

1 file changed

Lines changed: 14 additions & 2 deletions

File tree

‎src/shared_library.c‎

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,14 @@ rcutils_load_shared_library(
127127
goto fail;
128128
}
129129
lib->library_path = rcutils_strdup(image_name, lib->allocator);
130-
#elif defined(_GNU_SOURCE) && !defined(__QNXNTO__) && !defined(__ANDROID__)
130+
// Emscripten defines _GNU_SOURCE but its dlopen()/dlinfo() are a JS-backed
131+
// shim, not glibc's -- RTLD_DI_LINKMAP support (reading back a real
132+
// struct link_map) doesn't exist there. A successful dlopen() would
133+
// otherwise get treated as a failure once dlinfo() returns -1 below; the
134+
// #else branch already covers this correctly (it just reuses the path we
135+
// opened the library from, no introspection needed).
136+
#elif defined(_GNU_SOURCE) && !defined(__QNXNTO__) && !defined(__ANDROID__) && \
137+
!defined(__EMSCRIPTEN__)
131138
struct link_map * map = NULL;
132139
if (dlinfo(lib->lib_pointer, RTLD_DI_LINKMAP, &map) != 0) {
133140
RCUTILS_SET_ERROR_MSG_WITH_FORMAT_STRING("dlinfo error: %s", dlerror());
@@ -294,7 +301,12 @@ rcutils_get_platform_library_name(
294301

295302
int written = 0;
296303

297-
#if defined(__linux__) || defined(__QNXNTO__)
304+
// rcl_logging_implementation dlopens its backend (spdlog or noop) by name
305+
// at runtime via this function -- with no emscripten case it always falls
306+
// through with written == 0 ("failed to format library name"), regardless
307+
// of which backend RCL_LOGGING_IMPLEMENTATION selects. wasm32 side modules
308+
// use the same "lib<name>.so" naming convention as Linux.
309+
#if defined(__linux__) || defined(__QNXNTO__) || defined(__EMSCRIPTEN__)
298310
if (debug) {
299311
if (buffer_size >= (strlen(library_name) + 8)) {
300312
written = rcutils_snprintf(

0 commit comments

Comments
 (0)