summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorTim Schumacher <timschumi@gmx.de>2022-08-13 20:58:47 +0200
committerLinus Groh <mail@linusgroh.de>2022-09-05 10:12:02 +0100
commit226608a48fe4a32c8a8d216cc080718f668249d7 (patch)
treef8bb4ce82c795346756018f51d60e69260aded9b /Userland
parent27bfb8170239bc27b57734e8adc4cfad1e0413f8 (diff)
downloadserenity-226608a48fe4a32c8a8d216cc080718f668249d7.zip
LibDl: Move the `dlfcn` implementation to LibC
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibC/dlfcn.cpp74
-rw-r--r--Userland/Libraries/LibC/dlfcn.h (renamed from Userland/Libraries/LibDl/dlfcn.h)0
-rw-r--r--Userland/Libraries/LibC/dlfcn_integration.h (renamed from Userland/Libraries/LibDl/dlfcn_integration.h)0
-rw-r--r--Userland/Libraries/LibDl/CMakeLists.txt10
-rw-r--r--Userland/Libraries/LibDl/dlfcn.cpp74
5 files changed, 77 insertions, 81 deletions
diff --git a/Userland/Libraries/LibC/dlfcn.cpp b/Userland/Libraries/LibC/dlfcn.cpp
index df611300e1..d27b1074cd 100644
--- a/Userland/Libraries/LibC/dlfcn.cpp
+++ b/Userland/Libraries/LibC/dlfcn.cpp
@@ -4,10 +4,82 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
+#include <AK/String.h>
+#include <AK/Types.h>
+#include <dlfcn.h>
#include <dlfcn_integration.h>
+#include <string.h>
-// These are used by libdl and are filled in by the dynamic loader.
+// These are filled in by the dynamic loader.
DlCloseFunction __dlclose;
DlOpenFunction __dlopen;
DlSymFunction __dlsym;
DlAddrFunction __dladdr;
+
+// FIXME: use thread_local and a String once TLS works
+#ifdef NO_TLS
+char* s_dlerror_text = NULL;
+bool s_dlerror_retrieved = false;
+#else
+__thread char* s_dlerror_text = NULL;
+__thread bool s_dlerror_retrieved = false;
+#endif
+
+static void store_error(String const& error)
+{
+ free(s_dlerror_text);
+ s_dlerror_text = strdup(error.characters());
+ s_dlerror_retrieved = false;
+}
+
+int dlclose(void* handle)
+{
+ auto result = __dlclose(handle);
+ if (result.is_error()) {
+ store_error(result.error().text);
+ return -1;
+ }
+ return 0;
+}
+
+char* dlerror()
+{
+ if (s_dlerror_retrieved) {
+ free(s_dlerror_text);
+ s_dlerror_text = nullptr;
+ }
+ s_dlerror_retrieved = true;
+ return const_cast<char*>(s_dlerror_text);
+}
+
+void* dlopen(char const* filename, int flags)
+{
+ auto result = __dlopen(filename, flags);
+ if (result.is_error()) {
+ store_error(result.error().text);
+ return nullptr;
+ }
+ return result.value();
+}
+
+void* dlsym(void* handle, char const* symbol_name)
+{
+ auto result = __dlsym(handle, symbol_name);
+ if (result.is_error()) {
+ store_error(result.error().text);
+ return nullptr;
+ }
+ return result.value();
+}
+
+int dladdr(void* addr, Dl_info* info)
+{
+ auto result = __dladdr(addr, info);
+ if (result.is_error()) {
+ // FIXME: According to the man page glibc does _not_ make the error
+ // available via dlerror(), however we do. Does this break anything?
+ store_error(result.error().text);
+ return 0;
+ }
+ return 1;
+}
diff --git a/Userland/Libraries/LibDl/dlfcn.h b/Userland/Libraries/LibC/dlfcn.h
index 99f2c68e67..99f2c68e67 100644
--- a/Userland/Libraries/LibDl/dlfcn.h
+++ b/Userland/Libraries/LibC/dlfcn.h
diff --git a/Userland/Libraries/LibDl/dlfcn_integration.h b/Userland/Libraries/LibC/dlfcn_integration.h
index bf5a20ae60..bf5a20ae60 100644
--- a/Userland/Libraries/LibDl/dlfcn_integration.h
+++ b/Userland/Libraries/LibC/dlfcn_integration.h
diff --git a/Userland/Libraries/LibDl/CMakeLists.txt b/Userland/Libraries/LibDl/CMakeLists.txt
index 16199b9388..b86c5f768e 100644
--- a/Userland/Libraries/LibDl/CMakeLists.txt
+++ b/Userland/Libraries/LibDl/CMakeLists.txt
@@ -1,6 +1,4 @@
-set(SOURCES
- dlfcn.cpp
-)
-
-serenity_libc(LibDl dl)
-target_link_libraries(LibDl LibC)
+# Provide a dummy target and a linker script that tells everything to link against LibC instead.
+add_library(LibDl INTERFACE)
+target_link_libraries(LibDl INTERFACE LibC)
+file(WRITE "${CMAKE_STAGING_PREFIX}/${CMAKE_INSTALL_LIBDIR}/libdl.so" "INPUT(libc.so)")
diff --git a/Userland/Libraries/LibDl/dlfcn.cpp b/Userland/Libraries/LibDl/dlfcn.cpp
deleted file mode 100644
index 076d0e17ec..0000000000
--- a/Userland/Libraries/LibDl/dlfcn.cpp
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2021, Gunnar Beutner <gunnar@beutner.name>
- *
- * SPDX-License-Identifier: BSD-2-Clause
- */
-
-#include <AK/String.h>
-#include <AK/Types.h>
-#include <dlfcn.h>
-#include <dlfcn_integration.h>
-#include <string.h>
-
-// FIXME: use thread_local and a String once TLS works
-__thread char* s_dlerror_text = NULL;
-__thread bool s_dlerror_retrieved = false;
-
-static void store_error(String const& error)
-{
- free(s_dlerror_text);
- s_dlerror_text = strdup(error.characters());
- s_dlerror_retrieved = false;
-}
-
-int dlclose(void* handle)
-{
- auto result = __dlclose(handle);
- if (result.is_error()) {
- store_error(result.error().text);
- return -1;
- }
- return 0;
-}
-
-char* dlerror()
-{
- if (s_dlerror_retrieved) {
- free(s_dlerror_text);
- s_dlerror_text = nullptr;
- }
- s_dlerror_retrieved = true;
- return const_cast<char*>(s_dlerror_text);
-}
-
-void* dlopen(char const* filename, int flags)
-{
- auto result = __dlopen(filename, flags);
- if (result.is_error()) {
- store_error(result.error().text);
- return nullptr;
- }
- return result.value();
-}
-
-void* dlsym(void* handle, char const* symbol_name)
-{
- auto result = __dlsym(handle, symbol_name);
- if (result.is_error()) {
- store_error(result.error().text);
- return nullptr;
- }
- return result.value();
-}
-
-int dladdr(void* addr, Dl_info* info)
-{
- auto result = __dladdr(addr, info);
- if (result.is_error()) {
- // FIXME: According to the man page glibc does _not_ make the error
- // available via dlerror(), however we do. Does this break anything?
- store_error(result.error().text);
- return 0;
- }
- return 1;
-}