From patchwork Thu May 18 08:28:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: stsp X-Patchwork-Id: 69581 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 236E53882AEA for ; Thu, 18 May 2023 08:34:11 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from forward102b.mail.yandex.net (forward102b.mail.yandex.net [IPv6:2a02:6b8:c02:900:1:45:d181:d102]) by sourceware.org (Postfix) with ESMTPS id C95BB384B81B for ; Thu, 18 May 2023 08:29:45 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C95BB384B81B Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=yandex.ru Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=yandex.ru Received: from mail-nwsmtp-smtp-production-main-91.iva.yp-c.yandex.net (mail-nwsmtp-smtp-production-main-91.iva.yp-c.yandex.net [IPv6:2a02:6b8:c0c:1186:0:640:38cb:0]) by forward102b.mail.yandex.net (Yandex) with ESMTP id BECBD600AD for ; Thu, 18 May 2023 11:29:44 +0300 (MSK) Received: by mail-nwsmtp-smtp-production-main-91.iva.yp-c.yandex.net (smtp/Yandex) with ESMTPSA id XTYe39MDZ0U0-0ksYwjs4; Thu, 18 May 2023 11:29:44 +0300 X-Yandex-Fwd: 1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1684398584; bh=lel847E5I2GPUncNHb7o9gwg6Z96ew1OLjHqi2bDGR8=; h=Message-Id:Date:In-Reply-To:Cc:Subject:References:To:From; b=itqW+W5P96Gz2Cy3F3IDBbLl8OobTNggVbAFm6mOpps9JUmPOYyGxnN3F40f3u38Q uvk0BKDSKc110CVY/3Gaf7HIGloc8NeLi0pJnuo9BbxjFf/1J5IjbyDQVXfJD7UYHM erXo3Ey4OHBxuU4dmMM1j7CEYfDPuCPftSYqnId0= Authentication-Results: mail-nwsmtp-smtp-production-main-91.iva.yp-c.yandex.net; dkim=pass header.i=@yandex.ru From: Stas Sergeev To: libc-alpha@sourceware.org Cc: Stas Sergeev Subject: [PATCH 10/14] add test-case for RTLD_NORELOCATE Date: Thu, 18 May 2023 13:28:50 +0500 Message-Id: <20230518082854.3903342-11-stsp2@yandex.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230518082854.3903342-1-stsp2@yandex.ru> References: <20230518082854.3903342-1-stsp2@yandex.ru> MIME-Version: 1.0 X-Spam-Status: No, score=-11.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" Makes sure that things work as before. Makes sure that ctors are called upon dlsym(). The test-suite was run on x86_64/64 and showed no regressions. Signed-off-by: Stas Sergeev --- dlfcn/Makefile | 6 ++-- dlfcn/ctorlib1.c | 36 ++++++++++++++++++++++ dlfcn/tst-noreloc.c | 73 +++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 dlfcn/ctorlib1.c create mode 100644 dlfcn/tst-noreloc.c diff --git a/dlfcn/Makefile b/dlfcn/Makefile index 1fa7fea1ef..16b9401610 100644 --- a/dlfcn/Makefile +++ b/dlfcn/Makefile @@ -51,12 +51,12 @@ endif ifeq (yes,$(build-shared)) tests = glrefmain failtest tst-dladdr default errmsg1 tstcxaatexit \ bug-dlopen1 bug-dlsym1 tst-dlinfo bug-atexit1 bug-atexit2 \ - bug-atexit3 tstatexit bug-dl-leaf tst-rec-dlopen + bug-atexit3 tstatexit bug-dl-leaf tst-rec-dlopen tst-noreloc endif modules-names = glreflib1 glreflib2 glreflib3 failtestmod defaultmod1 \ defaultmod2 errmsg1mod modatexit modcxaatexit \ bug-dlsym1-lib1 bug-dlsym1-lib2 bug-atexit1-lib \ - bug-atexit2-lib bug-dl-leaf-lib \ + bug-atexit2-lib bug-dl-leaf-lib ctorlib1 \ bug-dl-leaf-lib-cb moddummy1 moddummy2 failtestmod.so-no-z-defs = yes @@ -102,6 +102,8 @@ $(objpfx)glrefmain.out: $(objpfx)glrefmain \ $(objpfx)failtest.out: $(objpfx)failtestmod.so $(objpfx)tst-dladdr.out: $(objpfx)glreflib1.so +$(objpfx)tst-noreloc.out: $(objpfx)ctorlib1.so +LDFLAGS-tst-noreloc = $(LDFLAGS-rdynamic) $(objpfx)tst-dlinfo.out: $(objpfx)glreflib3.so LDFLAGS-glreflib3.so = -Wl,-rpath,: diff --git a/dlfcn/ctorlib1.c b/dlfcn/ctorlib1.c new file mode 100644 index 0000000000..cf7a9096ea --- /dev/null +++ b/dlfcn/ctorlib1.c @@ -0,0 +1,36 @@ +/* Test for ctor calling. + Copyright (C) 2000-2023 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 + . */ + +#include +#include +#include + +extern int ref1 (void); +int +ref1 (void) +{ + return 42; +} + +void __attribute__((constructor)) +ctor (void) +{ + int *ct = (int *) dlsym (RTLD_DEFAULT, "ctor_called"); + assert (ct); + (*ct)++; +} diff --git a/dlfcn/tst-noreloc.c b/dlfcn/tst-noreloc.c new file mode 100644 index 0000000000..78f5a7fb25 --- /dev/null +++ b/dlfcn/tst-noreloc.c @@ -0,0 +1,73 @@ +/* Tests for RTLD_NORELOCATE flag. + Copyright (C) 2000-2023 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 + . */ + +#include +#include +#include +#include +#include +#include +#include + +int ctor_called; + +static int +do_test (void) +{ + void *handle; + int (*sym) (void); + Dl_info info; + int ret; + + handle = dlopen ("ctorlib1.so", RTLD_NOW | RTLD_NORELOCATE); + if (handle == NULL) + error (EXIT_FAILURE, 0, "cannot load: ctorlib1.so"); + + TEST_COMPARE (ctor_called, 0); + sym = dlsym (handle, "ref1"); + if (sym == NULL) + error (EXIT_FAILURE, 0, "dlsym failed"); + TEST_COMPARE (ctor_called, 1); + + memset (&info, 0, sizeof (info)); + ret = dladdr (sym, &info); + if (ret == 0) + error (EXIT_FAILURE, 0, "dladdr failed"); + + printf ("ret = %d\n", ret); + printf ("info.dli_fname = %p (\"%s\")\n", info.dli_fname, info.dli_fname); + printf ("info.dli_fbase = %p\n", info.dli_fbase); + printf ("info.dli_sname = %p (\"%s\")\n", info.dli_sname, info.dli_sname); + printf ("info.dli_saddr = %p\n", info.dli_saddr); + + if (info.dli_fname == NULL) + error (EXIT_FAILURE, 0, "dli_fname is NULL"); + if (info.dli_fbase == NULL) + error (EXIT_FAILURE, 0, "dli_fbase is NULL"); + if (info.dli_sname == NULL) + error (EXIT_FAILURE, 0, "dli_sname is NULL"); + if (info.dli_saddr == NULL) + error (EXIT_FAILURE, 0, "dli_saddr is NULL"); + + dlclose (handle); + + return 0; +} + + +#include