unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* resend patch//: Add testcese// [PATCH] dlsym: Add RTLD_PROBE for situation when dlsym only wants to probe a symbol but not use it
@ 2022-11-22  1:26 Wangbing(wangbing, RTOS/Poincare Lab) via Libc-alpha
  0 siblings, 0 replies; only message in thread
From: Wangbing(wangbing, RTOS/Poincare Lab) via Libc-alpha @ 2022-11-22  1:26 UTC (permalink / raw)
  To: Szabolcs Nagy
  Cc: Florian Weimer,
	Wangbing(wangbing, RTOS/Poincare Lab) via Libc-alpha, Nixiaoming,
	zhongjubin, Yanhuijun (DOPRA SSP)

diff --git a/dlfcn/dlfcn.h b/dlfcn/dlfcn.h
index 6f7cad8682..ab709883a6 100644
--- a/dlfcn/dlfcn.h
+++ b/dlfcn/dlfcn.h
@@ -49,6 +49,10 @@ typedef long int Lmid_t;
    is returned.  */
 #define RTLD_DEFAULT   ((void *) 0)

+/* If only find sym in the global scope, but will not use it, do not
+   set sym dependency. */
+# define RTLD_PROBE    ((void *) -2l)
+
 __BEGIN_DECLS

 /* Open the shared object FILE and map it in; return a handle that can be
diff --git a/elf/dl-sym.c b/elf/dl-sym.c
index b1cf42f36d..bc95b12a19 100644
--- a/elf/dl-sym.c
+++ b/elf/dl-sym.c
@@ -92,10 +92,17 @@ do_sym (void *handle, const char *name, void *who,
   /* Link map of the caller if needed.  */
   struct link_map *match = NULL;

-  if (handle == RTLD_DEFAULT)
+  int def_flags;
+
+  if (handle == RTLD_DEFAULT || handle == RTLD_PROBE)
     {
       match = _dl_sym_find_caller_link_map (caller);

+      def_flags = flags
+      if (def_flags == RTLD_DEFAULT) {
+          def_flags != DL_LOOKUP_ADD_DEPENDENCY;
+      }
+
       /* Search the global scope.  We have the simple case where
         we look up in the scope of an object which was part of
         the initial binary.  And then the more complex part
@@ -104,7 +111,7 @@ do_sym (void *handle, const char *name, void *who,
       if (RTLD_SINGLE_THREAD_P)
        result = GLRO(dl_lookup_symbol_x) (name, match, &ref,
                                           match->l_scope, vers, 0,
-                                          flags | DL_LOOKUP_ADD_DEPENDENCY,
+                                          def_flags,
                                           NULL);
       else
        {
@@ -113,7 +120,7 @@ do_sym (void *handle, const char *name, void *who,
          args.map = match;
          args.vers = vers;
          args.flags
-           = flags | DL_LOOKUP_ADD_DEPENDENCY | DL_LOOKUP_GSCOPE_LOCK;
+           = def_flags | DL_LOOKUP_GSCOPE_LOCK;
          args.refp = &ref;

          THREAD_GSCOPE_SET_FLAG ();
diff --git a/elf/Makefile b/elf/Makefile
index eca7b28ab5..f9fc9fbebb 100644
--- a/elf/Makefile
+++ b/elf/Makefile
@@ -472,6 +472,7 @@ tests += \
   unload7 \
   unload8 \
   valgrind-test \
+  tst-dlsym-rtld-probe \
   # tests
 tests-cxx = \
   tst-dlopen-nodelete-reloc \
diff --git a/elf/tst-dlsym-rtld-probe.c b/elf/tst-dlsym-rtld-probe.c
new file mode 100644
index 0000000000..84ba92c6c8
--- /dev/null
+++ b/elf/tst-dlsym-rtld-probe.c
@@ -0,0 +1,50 @@
+/* Test RTLD_PROBE for dlsym.
+   Copyright (C) 2022-2022 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <https://www.gnu.org/licenses/>.  */
+
+#include <dlfcn.h>
+#include <gnu/lib-names.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <support/check.h>
+#include <support/xdlfcn.h>
+
+static int
+do_test (void)
+{
+  int *iptr;
+  int ret;
+  void *handle;
+
+  handle = dlopen (LIBM_SO, RTLD_LAZY);
+  TEST_VERIFY (handle == NULL);
+  iptr = (int *)dlsym (RTLD_PROBE, "finite");
+  ret = dlclose (handle);
+  TEST_VERIFY (ret != 0);
+  ret = 0;
+
+  handle = dlopen (LIBM_SO, RTLD_LAZY);
+  TEST_VERIFY (handle == NULL);
+  iptr = (int *)dlsym (RTLD_DEFAULT, "finite");
+  ret = dlcose (handle);
+  TEST_VERIFY (ret == 0);
+  return 0;
+}
+
+
+#include <support/test-driver.c>

-----邮件原件-----
发件人: Szabolcs Nagy [mailto:szabolcs.nagy@arm.com] 
发送时间: 2022年11月21日 22:34
收件人: Wangbing(wangbing,RTOS/Poincare Lab) <wangbing6@huawei.com>
抄送: Florian Weimer <fw@deneb.enyo.de>; Wangbing(wangbing, RTOS/Poincare Lab) via Libc-alpha <libc-alpha@sourceware.org>; Nixiaoming <nixiaoming@huawei.com>; zhongjubin <zhongjubin@huawei.com>; Yanhuijun (DOPRA SSP) <yanhuijun@huawei.com>
主题: Re: Add testcese// [PATCH] dlsym: Add RTLD_PROBE for situation when dlsym only wants to probe a symbol but not use it

The 11/21/2022 14:06, Wangbing(wangbing, RTOS/Poincare Lab) via Libc-alpha wrote:
> diff --git a/dlfcn/dlfcn.h b/dlfcn/dlfcn.h index 6f7cad8682..ab709883a6 100644
> --- a/dlfcn/dlfcn.h
> +++ b/dlfcn/dlfcn.h
> @@ -49,6 +49,10 @@ typedef long int Lmid_t;
>     is returned.  */
>  #define RTLD_DEFAULT   ((void *) 0)
> 
> +/* If only find sym in the global scope, but will not use it, do not
> +   set sym dependency. */
> +# define RTLD_PROBE    ((void *) -2l)
> +
>  __BEGIN_DECLS
> 
>  /* Open the shared object FILE and map it in; return a handle that can be diff --git a/elf/Makefile b/elf/Makefile index eca7b28ab5..f9fc9fbebb 100644
> --- a/elf/Makefile
> +++ b/elf/Makefile

looks like the patch got corrupted.

i think it would help if you could resend it.

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2022-11-22  1:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-22  1:26 resend patch//: Add testcese// [PATCH] dlsym: Add RTLD_PROBE for situation when dlsym only wants to probe a symbol but not use it Wangbing(wangbing, RTOS/Poincare Lab) via Libc-alpha

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).