public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Florian Weimer <fweimer@redhat.com>
To: Wang Bing via Libc-alpha <libc-alpha@sourceware.org>
Cc: Wang Bing <wangbing6@huawei.com>,  <hjl.tools@gmail.com>,
	<nixiaoming@huawei.com>,  <szabolcs.nagy@arm.com>,
	<yanhuijun@huawei.com>,  <zhongjubin@huawei.com>
Subject: Re: [PATCH v2] dlsym: Add RTLD_PROBE to dlsym only probe symbol without add dependency.
Date: Mon, 05 Dec 2022 15:45:22 +0100	[thread overview]
Message-ID: <87ilipsyd9.fsf@oldenburg.str.redhat.com> (raw)
In-Reply-To: <20221123022137.65977-1-wangbing6@huawei.com> (Wang Bing via Libc-alpha's message of "Wed, 23 Nov 2022 10:21:37 +0800")

* Wang Bing via Libc-alpha:

> diff --git a/elf/tst-dlsym-rtld-probe.c b/elf/tst-dlsym-rtld-probe.c
> new file mode 100644
> index 0000000000..c72ceaa182
> --- /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");	// get sym but not call --detect if symbol exist
> +  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"); // get sym and keep
> +  ret = dlcose (handle);
> +  TEST_VERIFY (ret == 0);
> +  return 0;
> +}
> +
> +
> +#include <support/test-driver.c>

I tried to fix the test case to work stand-alone, and with RTLD_DEFAULT:

#include <dlfcn.h>
#include <err.h>
#include <gnu/lib-names.h>
#include <stddef.h>

int
main (void)
{
  void *handle = dlopen (LIBM_SO, RTLD_LAZY);
  if (handle == NULL)
    errx (1, dlerror ());

  void *p = dlsym (RTLD_DEFAULT, "finite");

  if (p == NULL)
    errx (1, dlerror ());
  if (dlclose (handle) != 0)
    errx (1, dlerror ());

  if (dlopen (LIBM_SO, RTLD_LAZY | RTLD_NOLOAD) != NULL)
    errx (1, "libm not unloaded");
  return 0;
}

It does not show that unloading is blocked: RTLD_NOLOAD subsequently
fails.  Furthermore, the LD_DEBUG=all output indicates that unloading
happens before the return from main (before the ELF destructors are
called):

    268899:	symbol=dlclose;  lookup in file=./a.out [0]
    268899:	symbol=dlclose;  lookup in file=/lib64/libc.so.6 [0]
    268899:	binding file ./a.out [0] to /lib64/libc.so.6 [0]: normal symbol `dlclose' [GLIBC_2.34]
    268899:	
    268899:	calling fini: /lib64/libm.so.6 [0]
    268899:	
    268899:	
    268899:	file=/lib64/libm.so.6 [0];  destroying link map
    268899:	
    268899:	file=libm.so.6 [0];  dynamically loaded by ./a.out [0]
    268899:	find library=libm.so.6 [0]; searching
    268899:	 search cache=/etc/ld.so.cache
    268899:	  trying file=/lib64/libm.so.6
    268899:	
    268899:	
    268899:	calling fini:  [0]

Please post a test case that demonstrates the problem you are trying to
fix.

Thanks,
Florian


      reply	other threads:[~2022-12-05 14:45 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-22  2:30 [PATCH] " Wang Bing
2022-11-22  2:36 ` H.J. Lu
2022-11-22 16:35   ` H.J. Lu
2022-11-23  2:21     ` [PATCH v2] " Wang Bing
2022-12-05 14:45       ` Florian Weimer [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87ilipsyd9.fsf@oldenburg.str.redhat.com \
    --to=fweimer@redhat.com \
    --cc=hjl.tools@gmail.com \
    --cc=libc-alpha@sourceware.org \
    --cc=nixiaoming@huawei.com \
    --cc=szabolcs.nagy@arm.com \
    --cc=wangbing6@huawei.com \
    --cc=yanhuijun@huawei.com \
    --cc=zhongjubin@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).