[v2,15/16] dlfcn: Eliminate GLIBC_PRIVATE dependency from tststatic2

Message ID 66fdbeb88347a0f07f1185e3294bbc78ded0d370.1622469909.git.fweimer@redhat.com
State New
Headers show
Series
  • Move libdl into libc
Related show

Commit Message

Szabolcs Nagy via Libc-alpha May 31, 2021, 2:12 p.m.
The test appears to use _dlfcn_hook@@GLIBC_PRIVATE as a way to
test dlvsym without having to know the appropriate symbol version.
With <first-versions.h>, we can use a public symbol and the symbol
version at which it was defined first.
---
 dlfcn/modstatic2.c | 10 +++++++++-
 dlfcn/tststatic2.c | 10 +++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

-- 
2.31.1

Comments

Szabolcs Nagy via Libc-alpha June 2, 2021, 6:09 p.m. | #1
On 31/05/2021 11:12, Florian Weimer via Libc-alpha wrote:
> The test appears to use _dlfcn_hook@@GLIBC_PRIVATE as a way to

> test dlvsym without having to know the appropriate symbol version.

> With <first-versions.h>, we can use a public symbol and the symbol

> version at which it was defined first.


Right, I think by including the <first-versions.h> there is no need 
to make it an internal test.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>



> ---

>  dlfcn/modstatic2.c | 10 +++++++++-

>  dlfcn/tststatic2.c | 10 +++++++++-

>  2 files changed, 18 insertions(+), 2 deletions(-)

> 

> diff --git a/dlfcn/modstatic2.c b/dlfcn/modstatic2.c

> index 9b5aae8b9f..02d561a7b0 100644

> --- a/dlfcn/modstatic2.c

> +++ b/dlfcn/modstatic2.c

> @@ -4,6 +4,7 @@

>  #include <stdlib.h>

>  #include <string.h>

>  #include <gnu/lib-names.h>

> +#include <first-versions.h>

>  

>  int test (FILE *out, int a);

>  

> @@ -117,11 +118,18 @@ test (FILE *out, int a)

>        exit (1);

>      }

>  

> -  if (dlvsym (handle2, "_dlfcn_hook", "GLIBC_PRIVATE") == NULL)

> +  /* _exit is very unlikely to receive a second symbol version.  */

> +  void *exit_ptr = dlvsym (handle2, "_exit", FIRST_VERSION_libc__exit_STRING);

> +  if (exit_ptr == NULL)

>      {

>        fprintf (out, "dlvsym: %s\n", dlerror ());

>        exit (1);

>      }

> +  if (exit_ptr != dlsym (handle2, "_exit"))

> +    {

> +      fprintf (out, "dlvsym for _exit does not match dlsym\n");

> +      exit (1);

> +    }

>  

>    void *(*dlsymfn) (void *, const char *);

>    dlsymfn = dlsym (handle2, "dlsym");


Ok.

> diff --git a/dlfcn/tststatic2.c b/dlfcn/tststatic2.c

> index f8cd5a964b..5d8a7831b2 100644

> --- a/dlfcn/tststatic2.c

> +++ b/dlfcn/tststatic2.c

> @@ -4,6 +4,7 @@

>  #include <stdlib.h>

>  #include <string.h>

>  #include <gnu/lib-names.h>

> +#include <first-versions.h>

>  

>  static int

>  do_test (void)

> @@ -115,11 +116,18 @@ do_test (void)

>        exit (1);

>      }

>  

> -  if (dlvsym (handle2, "_dlfcn_hook", "GLIBC_PRIVATE") == NULL)

> +  /* _exit is very unlikely to receive a second symbol version.  */

> +  void *exit_ptr = dlvsym (handle2, "_exit", FIRST_VERSION_libc__exit_STRING);

> +  if (exit_ptr == NULL)

>      {

>        printf ("dlvsym: %s\n", dlerror ());

>        exit (1);

>      }

> +  if (exit_ptr != dlsym (handle2, "_exit"))

> +    {

> +      printf ("dlvsym for _exit does not match dlsym\n");

> +      exit (1);

> +    }

>  

>    void *(*dlsymfn) (void *, const char *);

>    dlsymfn = dlsym (handle2, "dlsym");

> 


Ok.

Patch

diff --git a/dlfcn/modstatic2.c b/dlfcn/modstatic2.c
index 9b5aae8b9f..02d561a7b0 100644
--- a/dlfcn/modstatic2.c
+++ b/dlfcn/modstatic2.c
@@ -4,6 +4,7 @@ 
 #include <stdlib.h>
 #include <string.h>
 #include <gnu/lib-names.h>
+#include <first-versions.h>
 
 int test (FILE *out, int a);
 
@@ -117,11 +118,18 @@  test (FILE *out, int a)
       exit (1);
     }
 
-  if (dlvsym (handle2, "_dlfcn_hook", "GLIBC_PRIVATE") == NULL)
+  /* _exit is very unlikely to receive a second symbol version.  */
+  void *exit_ptr = dlvsym (handle2, "_exit", FIRST_VERSION_libc__exit_STRING);
+  if (exit_ptr == NULL)
     {
       fprintf (out, "dlvsym: %s\n", dlerror ());
       exit (1);
     }
+  if (exit_ptr != dlsym (handle2, "_exit"))
+    {
+      fprintf (out, "dlvsym for _exit does not match dlsym\n");
+      exit (1);
+    }
 
   void *(*dlsymfn) (void *, const char *);
   dlsymfn = dlsym (handle2, "dlsym");
diff --git a/dlfcn/tststatic2.c b/dlfcn/tststatic2.c
index f8cd5a964b..5d8a7831b2 100644
--- a/dlfcn/tststatic2.c
+++ b/dlfcn/tststatic2.c
@@ -4,6 +4,7 @@ 
 #include <stdlib.h>
 #include <string.h>
 #include <gnu/lib-names.h>
+#include <first-versions.h>
 
 static int
 do_test (void)
@@ -115,11 +116,18 @@  do_test (void)
       exit (1);
     }
 
-  if (dlvsym (handle2, "_dlfcn_hook", "GLIBC_PRIVATE") == NULL)
+  /* _exit is very unlikely to receive a second symbol version.  */
+  void *exit_ptr = dlvsym (handle2, "_exit", FIRST_VERSION_libc__exit_STRING);
+  if (exit_ptr == NULL)
     {
       printf ("dlvsym: %s\n", dlerror ());
       exit (1);
     }
+  if (exit_ptr != dlsym (handle2, "_exit"))
+    {
+      printf ("dlvsym for _exit does not match dlsym\n");
+      exit (1);
+    }
 
   void *(*dlsymfn) (void *, const char *);
   dlsymfn = dlsym (handle2, "dlsym");