From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x834.google.com (mail-qt1-x834.google.com [IPv6:2607:f8b0:4864:20::834]) by sourceware.org (Postfix) with ESMTPS id 41500386EC26 for ; Fri, 21 May 2021 20:11:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 41500386EC26 Received: by mail-qt1-x834.google.com with SMTP id c10so16198461qtx.10 for ; Fri, 21 May 2021 13:11:15 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=G8y5+Zp6mqm1EsfNomuEs+V6Rz7JZlr3w4GxvTqQQC8=; b=SnMNGSpL495zOtW5vNAFeakAW7melOdMoh2NNmdNbSSd0eaPzdksc7vsqw+tRlB9xI mLhIKKbT9D50xcUQz1Q5i/q3flCBBXcfzMOl2Ye6MnlQVxuN8xf+Xv0IY8zpdDA0PyRI dQCkK+Zffwra0w9WfKlPdPGwRJbNIMsOSkJTMmksZVZCBt4/66exoeMCQmYgWOic3vIM dLMcaMxNTcxGIkkOGiCwQVfuD3Eyml94nPhgRR39N+s1Dfg7ht3Elk8HvQ3lIodJCOKi wXCK4+zvWMFdVMYyoq1UGd97fUd1i9/4fKSOY8H5iV12Uh90Hqob6tG4gbuWSyjHJ3Zi pKQQ== X-Gm-Message-State: AOAM5323z4huNUYel24yl7INnQRS83ykK/VxsraAkNRdshj2G5EmrNMS mxefHD6ZEwaqHvSe4et6NlxidEH8sO/KnA== X-Google-Smtp-Source: ABdhPJxgu8B66VznRRmXOKxWwzt85SPLJGd7tUbSCiM4r2W54j9XunwQ2zWK+KSyihojUJwSo5ZykQ== X-Received: by 2002:a05:622a:1789:: with SMTP id s9mr13384263qtk.92.1621627874523; Fri, 21 May 2021 13:11:14 -0700 (PDT) Received: from [192.168.1.4] ([177.194.37.86]) by smtp.gmail.com with ESMTPSA id a23sm5549765qkl.6.2021.05.21.13.11.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 21 May 2021 13:11:14 -0700 (PDT) Subject: Re: [PATCH v2 4/8] elf: Use custom NODELETE DSO for tst-dlopenfail, tst-dlopenfail-2 To: Florian Weimer , libc-alpha@sourceware.org References: <35f180c09c45ab24ac4131fe3a53df071bcd2062.1621600831.git.fweimer@redhat.com> From: Adhemerval Zanella Message-ID: <751fe13b-6b0e-6743-9d44-8ce2786dad96@linaro.org> Date: Fri, 21 May 2021 17:11:11 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <35f180c09c45ab24ac4131fe3a53df071bcd2062.1621600831.git.fweimer@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.4 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_NUMSUBJECT, KAM_SHORT, NICE_REPLY_A, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: , X-List-Received-Date: Fri, 21 May 2021 20:11:17 -0000 On 21/05/2021 09:45, Florian Weimer via Libc-alpha wrote: > Once libpthread is empty and no longer marked NODELETE, it no longer > can be used for testing. LGTM, thanks. Reviewed-by: Adhemerval Zanella > --- > v2: Restrict the use of xdlopen/xdlsym, reverting to what was there before. > > elf/Makefile | 11 +++++++-- > elf/tst-dlopenfail-2.c | 5 +--- > elf/tst-dlopenfail.c | 46 +++++++++++++++--------------------- > elf/tst-dlopenfailmod2.c | 6 ++--- > elf/tst-dlopenfailnodelmod.c | 29 +++++++++++++++++++++++ > 5 files changed, 61 insertions(+), 36 deletions(-) > create mode 100644 elf/tst-dlopenfailnodelmod.c > > diff --git a/elf/Makefile b/elf/Makefile > index 5e809dbfaa..834ec858a8 100644 > --- a/elf/Makefile > +++ b/elf/Makefile > @@ -334,7 +334,7 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \ > tst-auditmanymod7 tst-auditmanymod8 tst-auditmanymod9 \ > tst-initlazyfailmod tst-finilazyfailmod \ > tst-dlopenfailmod1 tst-dlopenfaillinkmod tst-dlopenfailmod2 \ > - tst-dlopenfailmod3 tst-ldconfig-ld-mod \ > + tst-dlopenfailmod3 tst-dlopenfailnodelmod tst-ldconfig-ld-mod \ > tst-filterobj-flt tst-filterobj-aux tst-filterobj-filtee \ > tst-auditlogmod-1 tst-auditlogmod-2 tst-auditlogmod-3 \ > tst-single_threaded-mod1 tst-single_threaded-mod2 \ > @@ -1733,11 +1733,18 @@ LDFLAGS-tst-dlopenfailmod1.so = -Wl,--no-as-needed > $(objpfx)tst-dlopenfailmod1.so: \ > $(shared-thread-library) $(objpfx)tst-dlopenfaillinkmod.so > LDFLAGS-tst-dlopenfaillinkmod.so = -Wl,-soname,tst-dlopenfail-missingmod.so > -$(objpfx)tst-dlopenfailmod2.so: $(shared-thread-library) > +$(objpfx)tst-dlopenfailmod2.so: $(objpfx)tst-dlopenfailnodelmod.so > $(objpfx)tst-dlopenfail-2: $(libdl) > $(objpfx)tst-dlopenfail-2.out: \ > $(objpfx)tst-dlopenfailmod1.so $(objpfx)tst-dlopenfailmod2.so \ > $(objpfx)tst-dlopenfailmod3.so > +# tst-dlopenfailnodelmod.so emulates how libpthread was linked. > +$(objpfx)tst-dlopenfailnodelmod.so: $(libsupport) > +LDFLAGS-tst-dlopenfailnodelmod.so = \ > + -Wl,--enable-new-dtags,-z,nodelete,-z,initfirst > +# tst-dlopenfail should export the libsupport symbols, so that > +# tst-dlopenfailnodelmod.so uses them for error reporting. > +LDFLAGS-tst-dlopenfail = -Wl,-E > > $(objpfx)tst-dlopen-nodelete-reloc: $(libdl) > $(objpfx)tst-dlopen-nodelete-reloc.out: \ > diff --git a/elf/tst-dlopenfail-2.c b/elf/tst-dlopenfail-2.c > index 50eed81cb0..168c4b2c7f 100644 > --- a/elf/tst-dlopenfail-2.c > +++ b/elf/tst-dlopenfail-2.c > @@ -28,10 +28,7 @@ > static int > do_test (void) > { > - /* This test uses libpthread as the canonical NODELETE module. If > - libpthread is no longer NODELETE because it has been merged into > - libc, the test needs to be updated. */ > - TEST_VERIFY (dlsym (NULL, "pthread_create") == NULL); > + TEST_VERIFY (dlsym (NULL, "no_delete_mod_function") == NULL); > > /* This is expected to fail because of the missing dependency. */ > puts ("info: attempting to load tst-dlopenfailmod1.so"); > diff --git a/elf/tst-dlopenfail.c b/elf/tst-dlopenfail.c > index db2b41f9b5..edf84e8259 100644 > --- a/elf/tst-dlopenfail.c > +++ b/elf/tst-dlopenfail.c > @@ -18,7 +18,6 @@ > > #include > #include > -#include > #include > #include > #include > @@ -28,10 +27,7 @@ > static int > do_test (void) > { > - /* This test uses libpthread as the canonical NODELETE module. If > - libpthread is no longer NODELETE because it has been merged into > - libc, the test needs to be updated. */ > - TEST_VERIFY (dlsym (NULL, "pthread_create") == NULL); > + TEST_VERIFY (dlsym (NULL, "no_delete_mod_function") == NULL); > > /* This is expected to fail because of the missing dependency. */ > puts ("info: attempting to load tst-dlopenfailmod1.so"); > @@ -42,36 +38,32 @@ do_test (void) > " cannot open shared object file:" > " No such file or directory"); > > - /* Do not probe for the presence of libpthread at this point because > - that might trigger relocation if bug 20839 is present, obscuring > - a subsequent crash. */ > + /* Do not probe for the presence of the tst-dlopenfailnodelmod.so at > + this point because that might trigger relocation if bug 20839 is > + present, obscuring a subsequent crash. */ > > /* This is expected to succeed. */ > puts ("info: loading tst-dlopenfailmod2.so"); > void *handle = xdlopen ("tst-dlopenfailmod2.so", RTLD_NOW); > xdlclose (handle); > > - /* libpthread should remain loaded. */ > - TEST_VERIFY (dlopen (LIBPTHREAD_SO, RTLD_LAZY | RTLD_NOLOAD) != NULL); > - TEST_VERIFY (dlsym (NULL, "pthread_create") == NULL); > + /* The NODELETE module should remain loaded. */ > + TEST_VERIFY (dlopen ("tst-dlopenfailnodelmod.so", RTLD_LAZY | RTLD_NOLOAD) > + != NULL); > + /* But the symbol is not in the global scope. */ > + TEST_VERIFY (dlsym (NULL, "no_delete_mod_function") == NULL); > > - /* We can make libpthread global, and then the symbol should become > - available. */ > - TEST_VERIFY (dlopen (LIBPTHREAD_SO, RTLD_LAZY | RTLD_GLOBAL) != NULL); > - TEST_VERIFY (dlsym (NULL, "pthread_create") != NULL); > + /* We can make tst-dlopenfailnodelmod.so global, and then the symbol > + should become available. */ > + TEST_VERIFY (dlopen ("tst-dlopenfailnodelmod.so", RTLD_LAZY | RTLD_GLOBAL) > + != NULL); > + void (*no_delete_mod_function) (void) > + = dlsym (NULL, "no_delete_mod_function"); > + TEST_VERIFY_EXIT (no_delete_mod_function != NULL); > > - /* sem_open is sufficiently complex to depend on relocations. */ > - void *(*sem_open_ptr) (const char *, int flag, ...) > - = dlsym (NULL, "sem_open"); > - if (sem_open_ptr == NULL) > - /* Hurd does not implement sem_open. */ > - puts ("warning: sem_open not found, further testing not possible"); > - else > - { > - errno = 0; > - TEST_VERIFY (sem_open_ptr ("/", 0) == NULL); > - TEST_COMPARE (errno, EINVAL); > - } > + /* Hopefully, no_delete_mod_function is sufficiently complex to > + depend on relocations. */ > + no_delete_mod_function (); > > return 0; > } > diff --git a/elf/tst-dlopenfailmod2.c b/elf/tst-dlopenfailmod2.c > index cd6f9cf56b..ed353f9a3c 100644 > --- a/elf/tst-dlopenfailmod2.c > +++ b/elf/tst-dlopenfailmod2.c > @@ -16,11 +16,11 @@ > License along with the GNU C Library; if not, see > . */ > > -#include > #include > > -/* Force linking against libpthread. */ > -void *pthread_create_reference = pthread_create; > +/* Force linking against tst-dlopenfailnodelmod.so. */ > +void no_delete_mod_function (void); > +void *function_reference = no_delete_mod_function; > > static void __attribute__ ((constructor)) > init (void) > diff --git a/elf/tst-dlopenfailnodelmod.c b/elf/tst-dlopenfailnodelmod.c > new file mode 100644 > index 0000000000..c4347b7591 > --- /dev/null > +++ b/elf/tst-dlopenfailnodelmod.c > @@ -0,0 +1,29 @@ > +/* NODELETE module for tst-dlopenfail, tst-dlopenfail-2. > + Copyright (C) 2021 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 > + > +/* Introduce some relocation dependencies. */ > +const char test_string[] = "test string"; > +const char *test_string_ptr = test_string; > + > +void > +no_delete_mod_function (void) > +{ > + TEST_COMPARE_STRING (test_string, test_string_ptr); > +} >