[13/14] dlfcn: Eliminate GLIBC_PRIVATE dependency from tststatic2

Message ID 55b77553739d573de35d0b558e9c5fa453cc84dd.1621953727.git.fweimer@redhat.com
State New
Headers show
Series
  • Move libdl into libc
Related show

Commit Message

Florian Weimer via Libc-alpha May 25, 2021, 2:46 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 | 3 ++-
 dlfcn/tststatic2.c | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

-- 
2.31.1

Comments

Andreas Schwab May 25, 2021, 3:38 p.m. | #1
On Mai 25 2021, Florian Weimer via Libc-alpha wrote:

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

> index 9b5aae8b9f..34568d4e6e 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,7 +118,7 @@ test (FILE *out, int a)

>        exit (1);

>      }

>  

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

> +  if (dlvsym (handle2, "malloc", FIRST_VERSION_libc_malloc_STRING) == NULL)


Shouldn't that use a public symbol from libdl?

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Florian Weimer via Libc-alpha May 25, 2021, 3:42 p.m. | #2
* Andreas Schwab:

> On Mai 25 2021, Florian Weimer via Libc-alpha wrote:

>

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

>> index 9b5aae8b9f..34568d4e6e 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,7 +118,7 @@ test (FILE *out, int a)

>>        exit (1);

>>      }

>>  

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

>> +  if (dlvsym (handle2, "malloc", FIRST_VERSION_libc_malloc_STRING) == NULL)

>

> Shouldn't that use a public symbol from libdl?


libdl is empty at this point, and there are no
FIRST_VERSION_libdl_*_STRING macros left.  I could use
FIRST_VERSION_libc_dlopen_STRING, I assume.  But malloc has the
advantage that it's unlikely that there are going to be multiple symbol
versions for it.

Thanks,
Florian
Andreas Schwab May 25, 2021, 3:54 p.m. | #3
On Mai 25 2021, Florian Weimer wrote:

> But malloc has the advantage that it's unlikely that there are going

> to be multiple symbol versions for it.


What would happen if it did?

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Florian Weimer via Libc-alpha May 25, 2021, 3:56 p.m. | #4
* Andreas Schwab:

> On Mai 25 2021, Florian Weimer wrote:

>

>> But malloc has the advantage that it's unlikely that there are going

>> to be multiple symbol versions for it.

>

> What would happen if it did?


The test will still work, I think, but anyone reading it will wonder if
the intent is to test multiple symbol versions at the same symbol.

Thanks,
Florian
Andreas Schwab May 25, 2021, 4:45 p.m. | #5
On Mai 25 2021, Florian Weimer wrote:

> The test will still work, I think, but anyone reading it will wonder if

> the intent is to test multiple symbol versions at the same symbol.


Then I think a comment is needed.

Andreas.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."

Patch

diff --git a/dlfcn/modstatic2.c b/dlfcn/modstatic2.c
index 9b5aae8b9f..34568d4e6e 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,7 +118,7 @@  test (FILE *out, int a)
       exit (1);
     }
 
-  if (dlvsym (handle2, "_dlfcn_hook", "GLIBC_PRIVATE") == NULL)
+  if (dlvsym (handle2, "malloc", FIRST_VERSION_libc_malloc_STRING) == NULL)
     {
       fprintf (out, "dlvsym: %s\n", dlerror ());
       exit (1);
diff --git a/dlfcn/tststatic2.c b/dlfcn/tststatic2.c
index f8cd5a964b..ba4648e521 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,7 +116,7 @@  do_test (void)
       exit (1);
     }
 
-  if (dlvsym (handle2, "_dlfcn_hook", "GLIBC_PRIVATE") == NULL)
+  if (dlvsym (handle2, "malloc", FIRST_VERSION_libc_malloc_STRING) == NULL)
     {
       printf ("dlvsym: %s\n", dlerror ());
       exit (1);