about summary refs log tree commit diff
path: root/dlfcn
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2021-06-02 07:32:20 +0200
committerFlorian Weimer <fweimer@redhat.com>2021-06-02 09:06:10 +0200
commita23c28ec0d1cd67d25972181f613ef6dbfe4e299 (patch)
treea6dd4e7c1a2ebb65af836b87e8b441ae6ece357a /dlfcn
parentc44838ebf8b8da0795d56e05b477c5d2b37b4a19 (diff)
downloadglibc-a23c28ec0d1cd67d25972181f613ef6dbfe4e299.tar.gz
glibc-a23c28ec0d1cd67d25972181f613ef6dbfe4e299.tar.xz
glibc-a23c28ec0d1cd67d25972181f613ef6dbfe4e299.zip
dlfcn: Move dlerror into libc
The symbol was moved using scripts/move-symbol-to-libc.py.

There is a minor functionality enhancement: dlerror now sets
errno if it was set as part of the exception.  (This is the result
of using %m in asprintf, to avoid the strerror PLT call.) The
previous errno value upon function return was unpredictable.
Documenting this as a feature is premature; we need to make sure
that the error codes are meaningful when they are set by the dynamic
loader.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
Diffstat (limited to 'dlfcn')
-rw-r--r--dlfcn/Makefile6
-rw-r--r--dlfcn/Versions16
-rw-r--r--dlfcn/dlerror.c43
-rw-r--r--dlfcn/sdlerror.c1
4 files changed, 35 insertions, 31 deletions
diff --git a/dlfcn/Makefile b/dlfcn/Makefile
index 994a3afee6..b194762d3e 100644
--- a/dlfcn/Makefile
+++ b/dlfcn/Makefile
@@ -21,11 +21,13 @@ include ../Makeconfig
 
 headers		:= bits/dlfcn.h dlfcn.h
 extra-libs	:= libdl
-libdl-routines	:= dlopen dlclose dlsym dlvsym dlerror dladdr dladdr1 dlinfo \
+libdl-routines	:= dlopen dlclose dlsym dlvsym dladdr dladdr1 dlinfo \
 		   dlmopen dlfcn
 routines	:= $(patsubst %,s%,$(filter-out dlfcn,$(libdl-routines)))
 elide-routines.os := $(routines)
-routines += libc_dlerror_result
+routines += \
+  dlerror \
+  libc_dlerror_result \
 
 extra-libs-others := libdl
 
diff --git a/dlfcn/Versions b/dlfcn/Versions
index f07cb929aa..76049e1c6a 100644
--- a/dlfcn/Versions
+++ b/dlfcn/Versions
@@ -1,11 +1,22 @@
 libc {
+  GLIBC_2.0 {
+    dlerror;
+  }
+  GLIBC_2.34 {
+    dlerror;
+  }
   GLIBC_PRIVATE {
     __libc_dlerror_result;
+    _dlerror_run;
+    _dlfcn_hook;
   }
 }
 libdl {
   GLIBC_2.0 {
-    dladdr; dlclose; dlerror; dlopen; dlsym;
+    dladdr;
+    dlclose;
+    dlopen;
+    dlsym;
   }
   GLIBC_2.1 {
     dlopen; dlvsym;
@@ -16,7 +27,4 @@ libdl {
   GLIBC_2.3.4 {
     dlmopen;
   }
-  GLIBC_PRIVATE {
-    _dlfcn_hook;
-  }
 }
diff --git a/dlfcn/dlerror.c b/dlfcn/dlerror.c
index 7db70a26d0..3df8602f4d 100644
--- a/dlfcn/dlerror.c
+++ b/dlfcn/dlerror.c
@@ -28,16 +28,6 @@
 #include <assert.h>
 #include <dlerror.h>
 
-#if !defined SHARED && IS_IN (libdl)
-
-char *
-dlerror (void)
-{
-  return __dlerror ();
-}
-
-#else
-
 char *
 __dlerror (void)
 {
@@ -86,11 +76,15 @@ __dlerror (void)
 		    result->objname[0] == '\0' ? "" : ": ",
 		    _(result->errstring));
   else
-    n = __asprintf (&buf, "%s%s%s: %s",
-		    result->objname,
-		    result->objname[0] == '\0' ? "" : ": ",
-		    _(result->errstring),
-		    strerror (result->errcode));
+    {
+      __set_errno (result->errcode);
+      n = __asprintf (&buf, "%s%s%s: %m",
+		      result->objname,
+		      result->objname[0] == '\0' ? "" : ": ",
+		      _(result->errstring));
+      /* Set errno again in case asprintf clobbered it.  */
+      __set_errno (result->errcode);
+    }
 
   /* Mark the error as delivered.  */
   result->returned = true;
@@ -108,9 +102,11 @@ __dlerror (void)
        existing string as a fallback.  */
     return result->errstring;
 }
-# ifdef SHARED
-strong_alias (__dlerror, dlerror)
-# endif
+versioned_symbol (libc, __dlerror, dlerror, GLIBC_2_34);
+
+#if OTHER_SHLIB_COMPAT (libdl, GLIBC_2_0, GLIBC_2_34)
+compat_symbol (libdl, __dlerror, dlerror, GLIBC_2_0);
+#endif
 
 int
 _dlerror_run (void (*operate) (void *), void *args)
@@ -200,13 +196,13 @@ _dlerror_run (void (*operate) (void *), void *args)
       return 1;
     }
 }
+libc_hidden_def (_dlerror_run)
 
-# ifdef SHARED
-
+#ifdef SHARED
 struct dlfcn_hook *_dlfcn_hook __attribute__((nocommon));
-libdl_hidden_data_def (_dlfcn_hook)
+libc_hidden_data_def (_dlfcn_hook)
 
-# else
+#else /* !SHARED */
 
 static struct dlfcn_hook _dlfcn_hooks =
   {
@@ -230,5 +226,4 @@ __libc_register_dlfcn_hook (struct link_map *map)
   if (hook != NULL)
     *hook = &_dlfcn_hooks;
 }
-# endif
-#endif
+#endif /* !SHARED */
diff --git a/dlfcn/sdlerror.c b/dlfcn/sdlerror.c
deleted file mode 100644
index f1226a48c5..0000000000
--- a/dlfcn/sdlerror.c
+++ /dev/null
@@ -1 +0,0 @@
-#include "dlerror.c"