From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qt1-x830.google.com (mail-qt1-x830.google.com [IPv6:2607:f8b0:4864:20::830]) by sourceware.org (Postfix) with ESMTPS id 1934B3951829 for ; Wed, 14 Apr 2021 18:06:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1934B3951829 Received: by mail-qt1-x830.google.com with SMTP id 1so16161395qtb.0 for ; Wed, 14 Apr 2021 11:06:51 -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=dLGzUj7ti5hLeKaW3baec1qqrh8urgZgVYxKsBFx1Lo=; b=VFzHQ5tSFCytHcjmOUNDxfTRTuTMRRZpUMS0BrutzAMTP0jPZI3Zo/Cs+rTHSHw2r0 yEEg+r6LKxKrYoJUpURrVffWhfFzncu5yUDJRORT2wmVnmcaYvnZ/6g3oBDVOrVYL/9M gDDJbo+UUz5CrNORMUjaQUknfQzPJ29Q/nR/Ibbb5EMNEYKdpngJ+DIvfpr67gR1K0tr n0W2AIynoHygV27OK+bIV/vErIdu+pUfMVbY7bA4FD5we5C0uJlx34x2Fdrnoo5fvIC/ wQXwBzw+puW7ruZLEjHi8m0KjW3bVvdkRFG+reflmjSvj6VI7Kesx8Qel5GQPvpN5NeJ ugNA== X-Gm-Message-State: AOAM530tyjicynpLbQsunlFwyCmfKxGq9bVG67P0oM+EmWSGNrTceGSf EwlsSY8ILtxlf/Wcpfzsrl1J6A== X-Google-Smtp-Source: ABdhPJxqYSqqkycV3S+xYwwS7sG8ZQBXtbLmFXzoVeFb2duIC1dnhGiJOUJhGb3fiqtiP/zyt6tRTA== X-Received: by 2002:ac8:59c7:: with SMTP id f7mr36174827qtf.320.1618423610236; Wed, 14 Apr 2021 11:06:50 -0700 (PDT) Received: from [192.168.1.132] ([177.194.41.149]) by smtp.gmail.com with ESMTPSA id n143sm148293qke.45.2021.04.14.11.06.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Apr 2021 11:06:49 -0700 (PDT) Subject: Re: [PATCH v2 02/14] elf: Add a DTV setup test [BZ #27136] To: libc-alpha@sourceware.org, Szabolcs Nagy References: <0b160a0060cd209a33496da51f915258ec5dd9a5.1618301209.git.szabolcs.nagy@arm.com> From: Adhemerval Zanella Message-ID: <39b15115-d8e2-2af2-a588-62c4c4f94b35@linaro.org> Date: Wed, 14 Apr 2021 15:06:47 -0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.7.1 MIME-Version: 1.0 In-Reply-To: <0b160a0060cd209a33496da51f915258ec5dd9a5.1618301209.git.szabolcs.nagy@arm.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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: Wed, 14 Apr 2021 18:06:52 -0000 On 13/04/2021 05:18, Szabolcs Nagy via Libc-alpha wrote: > The test dlopens a large number of modules with TLS, they are reused > from an existing test. > > The test relies on the reuse of slotinfo entries after dlclose, without > bug 27135 fixed this needs a failing dlopen. With a slotinfo list that > has non-monotone increasing generation counters, bug 27136 can trigger. > > -- > v2: > - moved from nptl/ to elf/ > - dlopen a different set of existing modules. > - code style fixes (!= NULL etc). > - moved after bug fix patch LGTM, with just a small suggestion below? Reviewed-by: Adhemerval Zanella > --- > elf/Makefile | 10 ++++- > elf/tst-tls20.c | 98 ++++++++++++++++++++++++++++++++++++++++++ > elf/tst-tls20mod-bad.c | 2 + > 3 files changed, 109 insertions(+), 1 deletion(-) > create mode 100644 elf/tst-tls20.c > create mode 100644 elf/tst-tls20mod-bad.c > > diff --git a/elf/Makefile b/elf/Makefile > index 0bef49e53d..b1344f1133 100644 > --- a/elf/Makefile > +++ b/elf/Makefile > @@ -222,7 +222,8 @@ tests += restest1 preloadtest loadfail multiload origtest resolvfail \ > tst-audit14 tst-audit15 tst-audit16 \ > tst-single_threaded tst-single_threaded-pthread \ > tst-tls-ie tst-tls-ie-dlmopen argv0test \ > - tst-glibc-hwcaps tst-glibc-hwcaps-prepend tst-glibc-hwcaps-mask > + tst-glibc-hwcaps tst-glibc-hwcaps-prepend tst-glibc-hwcaps-mask \ > + tst-tls20 > # reldep9 > tests-internal += loadtest unload unload2 circleload1 \ > neededtest neededtest2 neededtest3 neededtest4 \ Ok. > @@ -344,6 +345,7 @@ modules-names = testobj1 testobj2 testobj3 testobj4 testobj5 testobj6 \ > libmarkermod2-1 libmarkermod2-2 \ > libmarkermod3-1 libmarkermod3-2 libmarkermod3-3 \ > libmarkermod4-1 libmarkermod4-2 libmarkermod4-3 libmarkermod4-4 \ > + tst-tls20mod-bad > > # Most modules build with _ISOMAC defined, but those filtered out > # depend on internal headers. Ok. > @@ -1924,3 +1926,9 @@ $(objpfx)tst-rtld-help.out: $(objpfx)ld.so > fi; \ > (exit $$status); \ > $(evaluate-test) > + > +# Reuses tst-tls-many-dynamic-modules > +tst-tls20mod-bad.so-no-z-defs = yes > +$(objpfx)tst-tls20: $(libdl) $(shared-thread-library) > +$(objpfx)tst-tls20.out: $(objpfx)tst-tls20mod-bad.so \ > + $(tst-tls-many-dynamic-modules:%=$(objpfx)%.so) > diff --git a/elf/tst-tls20.c b/elf/tst-tls20.c Ok. > new file mode 100644 > index 0000000000..a378c1fa08 > --- /dev/null > +++ b/elf/tst-tls20.c > @@ -0,0 +1,98 @@ > +/* Test dtv setup if entries don't have monotone increasing generation. > + 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 > +#include > +#include > +#include > +#include > +#include > +#include > + > +#define NMOD 100 > +static void *mod[NMOD]; > + > +static void > +load_fail (void) > +{ > + /* Expected to fail because of a missing symbol. */ > + void *m = dlopen ("tst-tls20mod-bad.so", RTLD_NOW); > + if (m != NULL) > + FAIL_EXIT1 ("dlopen of tst-tls20mod-bad.so succeeded\n"); > +} > + > +static void > +load_mod (int i) > +{ > + char buf[100]; > + snprintf (buf, sizeof buf, "tst-tls-manydynamic%02dmod.so", i); > + mod[i] = xdlopen (buf, RTLD_LAZY); > +} Maybe xasprintf here? > + > +static void > +unload_mod (int i) > +{ > + if (mod[i] != NULL) > + xdlclose (mod[i]); > + mod[i] = NULL; > +} > + > +static void > +access (int i) > +{ > + char buf[100]; > + snprintf (buf, sizeof buf, "tls_global_%02d", i); Same as before. > + dlerror (); > + int *p = dlsym (mod[i], buf); > + printf ("mod[%d]: &tls = %p\n", i, p); > + if (p == NULL) > + FAIL_EXIT1 ("dlsym failed: %s\n", dlerror ()); > + ++*p; > +} > + > +static void * > +start (void *a) > +{ > + for (int i = 0; i < NMOD; i++) > + if (mod[i] != NULL) > + access (i); > + return 0; > +} > + > +static int > +do_test (void) > +{ > + int i; > + > + for (i = 0; i < NMOD; i++) > + { > + load_mod (i); > + /* Bump the generation of mod[0] without using new dtv slot. */ > + unload_mod (0); > + load_fail (); /* Ensure GL(dl_tls_dtv_gaps) is true: see bug 27135. */ > + load_mod (0); > + /* Access TLS in all loaded modules. */ > + pthread_t t = xpthread_create (0, start, 0); > + xpthread_join (t); > + } > + for (i = 0; i < NMOD; i++) > + unload_mod (i); > + return 0; > +} > + > +#include Ok. > diff --git a/elf/tst-tls20mod-bad.c b/elf/tst-tls20mod-bad.c > new file mode 100644 > index 0000000000..c1aed8ea7d > --- /dev/null > +++ b/elf/tst-tls20mod-bad.c > @@ -0,0 +1,2 @@ > +void missing_symbol (void); > +void f (void) {missing_symbol ();} > Ok.