unofficial mirror of libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Martin Sebor via Libc-alpha <libc-alpha@sourceware.org>
To: Joseph Myers <joseph@codesourcery.com>
Cc: Florian Weimer <fweimer@redhat.com>,
	Martin Sebor via Libc-alpha <libc-alpha@sourceware.org>
Subject: Re: [PATCH] add attribute none to pthread_setspecific (BZ #27714)
Date: Tue, 27 Apr 2021 19:09:11 -0600	[thread overview]
Message-ID: <8e311d8e-2b4a-06af-b086-7beb0e494422@gmail.com> (raw)
In-Reply-To: <47fc35d1-05b0-c02e-77dc-b3193aefd865@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2423 bytes --]

On 4/27/21 4:57 PM, Martin Sebor wrote:
> On 4/27/21 3:58 PM, Joseph Myers wrote:
>> On Tue, 27 Apr 2021, Martin Sebor via Libc-alpha wrote:
>>
>>> These are warnings in my build (I've seen a few others scroll by
>>> and have always assumed they were expected(*)).  Those you pasted
>>
>> Most warnings are errors by default (unless you use --disable-werror,
>> which should never normally be used in glibc development unless you're
>> e.g. reviewing the warnings you get if you add extra warning options to
>> those with which glibc is built by default, in order to fix those 
>> warnings
>> before adding the extra options).
> 
> Ah, that's what my build script does and I keep forgetting to
> change that when working on Glibc (as opposed to testing new
> GCC warnings).  My bad.  The attached diff patches up the tests
> to pass the function a valid argument.  I'll plan to commit it
> shortly unless you prefer some other solution.

More testing exposed a few more of these pthread_setspecific()
calls with invalid pointers.  I've committed the attached patch
in rb25b067491.  Let me know if you see something else.

> 
> Martin
> 
>>
>>> I test by simply running make check.  I can make the change to
>>> the test if you expect warning-free test builds.
>>
>> We expect builds, for all glibc ABIs, free from compile errors or 
>> failures
>> of tests that can run without needing to execute any code for the glibc
>> architecture.  That means no warnings that are turned into errors by
>> -Werror.  There are some warnings for which -Wno-error or pragmas are 
>> used
>> to stop them being errors; all other warnings are disallowed.
>>
>>> [*] Here's an example of a warning I just noticed while rerunning
>>> make check:
>>>
>>> tst-chk1.c: In function ‘do_test’:
>>
>> That's an example covered by -Wno-error.
>>
>> # We know these tests have problems with format strings, this is what
>> # we are testing.  Disable that warning.  They are also testing
>> # deprecated functions (notably gets) so disable that warning as well.
>> # And they also generate warnings from warning attributes, which
>> # cannot be disabled via pragmas, so require -Wno-error to be used.
>> CFLAGS-tst-chk1.c += -Wno-format -Wno-deprecated-declarations -Wno-error
>>
>> (Any code disabling any warnings or disabling -Werror for them is 
>> expected
>> to have a comment explaining why it's OK to do so in that case.)
>>
> 


[-- Attachment #2: glibc-tests-pthread_setspecific.diff --]
[-- Type: text/x-patch, Size: 5987 bytes --]

diff --git a/nptl/tst-tsd3.c b/nptl/tst-tsd3.c
index 0dd39ccb2b..45c7e4e1ea 100644
--- a/nptl/tst-tsd3.c
+++ b/nptl/tst-tsd3.c
@@ -37,7 +37,8 @@ destr1 (void *arg)
     {
       puts ("set key2");
 
-      if (pthread_setspecific (key2, (void *) 1l) != 0)
+      /* Use an arbirary but valid pointer to avoid GCC warnings.  */
+      if (pthread_setspecific (key2, (void *) &left) != 0)
 	{
 	  puts ("destr1: setspecific failed");
 	  exit (1);
@@ -53,7 +54,8 @@ destr2 (void *arg)
     {
       puts ("set key1");
 
-      if (pthread_setspecific (key1, (void *) 1l) != 0)
+      /* Use an arbirary but valid pointer to avoid GCC warnings.  */
+      if (pthread_setspecific (key1, (void *) &left) != 0)
 	{
 	  puts ("destr2: setspecific failed");
 	  exit (1);
@@ -68,8 +70,9 @@ tf (void *arg)
   /* Let the destructors work.  */
   left = 7;
 
-  if (pthread_setspecific (key1, (void *) 1l) != 0
-      || pthread_setspecific (key2, (void *) 1l) != 0)
+  /* Use an arbirary but valid pointer to avoid GCC warnings.  */
+  if (pthread_setspecific (key1, (void *) &left) != 0
+      || pthread_setspecific (key2, (void *) &left) != 0)
     {
       puts ("tf: setspecific failed");
       exit (1);
diff --git a/nptl/tst-tsd4.c b/nptl/tst-tsd4.c
index cc1ada4d4d..d72219466f 100644
--- a/nptl/tst-tsd4.c
+++ b/nptl/tst-tsd4.c
@@ -34,7 +34,8 @@ destr (void *arg)
 {
   ++rounds;
 
-  if (pthread_setspecific (key, (void *) 1l) != 0)
+  /* Use an arbirary but valid pointer to avoid GCC warnings.  */
+  if (pthread_setspecific (key, (void *) &rounds) != 0)
     {
       puts ("destr: setspecific failed");
       exit (1);
@@ -45,7 +46,8 @@ destr (void *arg)
 static void *
 tf (void *arg)
 {
-  if (pthread_setspecific (key, (void *) 1l) != 0)
+  /* Use an arbirary but valid pointer to avoid GCC warnings.  */
+  if (pthread_setspecific (key, (void *) &rounds) != 0)
     {
       puts ("tf: setspecific failed");
       exit (1);
diff --git a/sysdeps/pthread/tst-key2.c b/sysdeps/pthread/tst-key2.c
index 6828873e41..28ba547073 100644
--- a/sysdeps/pthread/tst-key2.c
+++ b/sysdeps/pthread/tst-key2.c
@@ -56,7 +56,8 @@ tf (void *arg)
 {
   pthread_key_t *key = (pthread_key_t *) arg;
 
-  if (pthread_setspecific (*key, (void *) -1l) != 0)
+  /* Use an arbirary but valid pointer to avoid GCC warnings.  */
+  if (pthread_setspecific (*key, arg) != 0)
     {
       write_message ("setspecific failed\n");
       _exit (1);
diff --git a/sysdeps/pthread/tst-key3.c b/sysdeps/pthread/tst-key3.c
index 5cf5dcf06f..b6cc8c49a3 100644
--- a/sysdeps/pthread/tst-key3.c
+++ b/sysdeps/pthread/tst-key3.c
@@ -59,7 +59,7 @@ tf (void *arg)
 {
   pthread_key_t *key = (pthread_key_t *) arg;
 
-  if (pthread_setspecific (*key, (void *) -1l) != 0)
+  if (pthread_setspecific (*key, arg) != 0)
     {
       write_message ("setspecific failed\n");
       _exit (1);
diff --git a/sysdeps/pthread/tst-tsd1.c b/sysdeps/pthread/tst-tsd1.c
index eeabfb9012..37b4aef27e 100644
--- a/sysdeps/pthread/tst-tsd1.c
+++ b/sysdeps/pthread/tst-tsd1.c
@@ -27,6 +27,9 @@ do_test (void)
   pthread_key_t key1;
   pthread_key_t key2;
   void *value;
+  /* Addresses of val1 and val2 are used as arbitrary but valid pointers
+     in calls to pthread_setspecific to avoid GCC warnings.  */
+  char val1 = 0, val2 = 0;
   int result = 0;
   int err;
 
@@ -45,7 +48,7 @@ do_test (void)
       result = 1;
     }
 
-  err = pthread_setspecific (key1, (void *) -2l);
+  err = pthread_setspecific (key1, (void *) &val1);
   if (err != 0)
     {
       printf ("1st setspecific failed: %s\n", strerror (err));
@@ -58,13 +61,13 @@ do_test (void)
       puts ("2nd getspecific == NULL\n");
       result = 1;
     }
-  else if (value != (void *) -2l)
+  else if (value != (void *) &val1)
     {
-      puts ("2nd getspecific != -2l\n");
+      puts ("2nd getspecific != &val1l\n");
       result = 1;
     }
 
-  err = pthread_setspecific (key1, (void *) -3l);
+  err = pthread_setspecific (key1, (void *) &val2);
   if (err != 0)
     {
       printf ("2nd setspecific failed: %s\n", strerror (err));
@@ -77,9 +80,9 @@ do_test (void)
       puts ("3rd getspecific == NULL\n");
       result = 1;
     }
-  else if (value != (void *) -3l)
+  else if (value != (void *) &val2)
     {
-      puts ("3rd getspecific != -2l\n");
+      puts ("3rd getspecific != &val2\n");
       result = 1;
     }
 
diff --git a/sysdeps/pthread/tst-tsd2.c b/sysdeps/pthread/tst-tsd2.c
index 275bbccfdd..6b4ca7c49f 100644
--- a/sysdeps/pthread/tst-tsd2.c
+++ b/sysdeps/pthread/tst-tsd2.c
@@ -27,7 +27,7 @@ static int result;
 static void
 destr (void *arg)
 {
-  if (arg != (void *) -2l)
+  if (arg != (void *) &result)
     result = 2;
   else
     result = 0;
@@ -40,7 +40,8 @@ tf (void *arg)
   pthread_key_t key = (pthread_key_t) (long int) arg;
   int err;
 
-  err = pthread_setspecific (key, (void *) -2l);
+  /* Use an arbirary but valid pointer to avoid GCC warnings.  */
+  err = pthread_setspecific (key, &result);
   if (err != 0)
     result = 3;
 
diff --git a/sysdeps/pthread/tst-tsd5.c b/sysdeps/pthread/tst-tsd5.c
index 5f62b5a6e8..e875863892 100644
--- a/sysdeps/pthread/tst-tsd5.c
+++ b/sysdeps/pthread/tst-tsd5.c
@@ -53,7 +53,8 @@ do_test (void)
       puts ("key_create failed");
       return 1;
     }
-  if (pthread_setspecific (k, (void *) 1) != 0)
+  /* Use an arbitrary but valid pointer as the value.  */
+  if (pthread_setspecific (k, (void *) &k) != 0)
     {
       puts ("setspecific failed");
       return 1;
diff --git a/sysdeps/pthread/tst-tsd6.c b/sysdeps/pthread/tst-tsd6.c
index debb1dd367..5f2aa42e98 100644
--- a/sysdeps/pthread/tst-tsd6.c
+++ b/sysdeps/pthread/tst-tsd6.c
@@ -17,7 +17,8 @@ tf (void *arg)
   for (int i = 0; i < NKEYS; ++i)
     {
       void *p = pthread_getspecific (keys[i]);
-      pthread_setspecific (keys[i], (void *) 7);
+      /* Use an arbitrary but valid pointer as the value.  */
+      pthread_setspecific (keys[i], (void *) keys);
       if (p != NULL)
 	res = p;
     }

  reply	other threads:[~2021-04-28  1:09 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-22 21:30 [PATCH] add attribute none to pthread_setspecific (BZ #27714) Martin Sebor via Libc-alpha
2021-04-22 22:26 ` Martin Sebor via Libc-alpha
2021-04-23  0:11 ` Paul Eggert
2021-04-23 15:24   ` Martin Sebor via Libc-alpha
2021-04-23 20:19     ` Paul Eggert
2021-04-23 21:29       ` Martin Sebor via Libc-alpha
2021-04-24  0:27         ` Paul Eggert
2021-04-26 19:38           ` Martin Sebor via Libc-alpha
2021-04-27  4:41 ` Florian Weimer via Libc-alpha
2021-04-27 19:07   ` Martin Sebor via Libc-alpha
2021-04-27 21:07     ` Joseph Myers
2021-04-27 21:46       ` Martin Sebor via Libc-alpha
2021-04-27 21:58         ` Joseph Myers
2021-04-27 22:57           ` Martin Sebor via Libc-alpha
2021-04-28  1:09             ` Martin Sebor via Libc-alpha [this message]
2021-04-28  7:32               ` Florian Weimer via Libc-alpha
2021-04-28 14:49                 ` Martin Sebor via Libc-alpha
2021-04-29  7:45                   ` Florian Weimer via Libc-alpha
2021-04-29 14:55                     ` Martin Sebor via Libc-alpha
2021-04-29 16:16                       ` Florian Weimer via Libc-alpha
2021-04-28  1:30             ` H.J. Lu via Libc-alpha

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

  List information: https://www.gnu.org/software/libc/involved.html

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

  git send-email \
    --in-reply-to=8e311d8e-2b4a-06af-b086-7beb0e494422@gmail.com \
    --to=libc-alpha@sourceware.org \
    --cc=fweimer@redhat.com \
    --cc=joseph@codesourcery.com \
    --cc=msebor@gmail.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).