public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* Side effect inside assert macro?
@ 2023-03-23 12:54 Andreas Schwab
  2023-03-25 19:48 ` Paul Pluzhnikov
  2023-03-25 21:32 ` [PATCH] Minor: don't call _dl_debug_update (which can have side effects) inside assert Paul Pluzhnikov
  0 siblings, 2 replies; 6+ messages in thread
From: Andreas Schwab @ 2023-03-23 12:54 UTC (permalink / raw)
  To: libc-alpha

In elf/dl-open.c there are two calls to _dl_debug_update inside the
assert macro:

581:      assert (_dl_debug_update (args->nsid)->r_state == RT_CONSISTENT);
930:  assert (_dl_debug_update (args.nsid)->r_state == RT_CONSISTENT);

Is it possible that these are the first calls of _dl_debug_update for
this nsid?

-- 
Andreas Schwab, SUSE Labs, schwab@suse.de
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Side effect inside assert macro?
  2023-03-23 12:54 Side effect inside assert macro? Andreas Schwab
@ 2023-03-25 19:48 ` Paul Pluzhnikov
  2023-03-25 21:32 ` [PATCH] Minor: don't call _dl_debug_update (which can have side effects) inside assert Paul Pluzhnikov
  1 sibling, 0 replies; 6+ messages in thread
From: Paul Pluzhnikov @ 2023-03-25 19:48 UTC (permalink / raw)
  To: Andreas Schwab; +Cc: libc-alpha

On Thu, Mar 23, 2023 at 5:54 AM Andreas Schwab via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> In elf/dl-open.c there are two calls to _dl_debug_update inside the
> assert macro:
>
> 581:      assert (_dl_debug_update (args->nsid)->r_state == RT_CONSISTENT);
> 930:  assert (_dl_debug_update (args.nsid)->r_state == RT_CONSISTENT);
>
> Is it possible that these are the first calls of _dl_debug_update for
> this nsid?

Regardless of whether it's possible or not, this seems like a really
bad idea(TM).
Given that a fix is trivial, why not just fix it?

I'll send a patch.


-- 
Paul Pluzhnikov

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] Minor: don't call _dl_debug_update (which can have side effects) inside assert
  2023-03-23 12:54 Side effect inside assert macro? Andreas Schwab
  2023-03-25 19:48 ` Paul Pluzhnikov
@ 2023-03-25 21:32 ` Paul Pluzhnikov
  2023-03-25 22:09   ` Florian Weimer
  1 sibling, 1 reply; 6+ messages in thread
From: Paul Pluzhnikov @ 2023-03-25 21:32 UTC (permalink / raw)
  To: libc-alpha; +Cc: Paul Pluzhnikov, Andreas Schwab

---
 elf/dl-open.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/elf/dl-open.c b/elf/dl-open.c
index 91a2d8a538..d46956ea21 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -578,7 +578,8 @@ dl_open_worker_begin (void *a)
       if ((mode & RTLD_GLOBAL) && new->l_global == 0)
 	add_to_global_update (new);
 
-      assert (_dl_debug_update (args->nsid)->r_state == RT_CONSISTENT);
+      const int r_state = _dl_debug_update (args->nsid)->r_state;
+      assert (r_state == RT_CONSISTENT);
 
       return;
     }
@@ -927,7 +928,8 @@ no more namespaces available for dlmopen()"));
       _dl_signal_exception (errcode, &exception, NULL);
     }
 
-  assert (_dl_debug_update (args.nsid)->r_state == RT_CONSISTENT);
+  const int r_state = _dl_debug_update (args.nsid)->r_state;
+  assert (r_state == RT_CONSISTENT);
 
   /* Release the lock.  */
   __rtld_lock_unlock_recursive (GL(dl_load_lock));
-- 
2.40.0.348.gf938b09366-goog


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Minor: don't call _dl_debug_update (which can have side effects) inside assert
  2023-03-25 21:32 ` [PATCH] Minor: don't call _dl_debug_update (which can have side effects) inside assert Paul Pluzhnikov
@ 2023-03-25 22:09   ` Florian Weimer
  2023-03-26  0:24     ` Paul Pluzhnikov
  0 siblings, 1 reply; 6+ messages in thread
From: Florian Weimer @ 2023-03-25 22:09 UTC (permalink / raw)
  To: Paul Pluzhnikov via Libc-alpha; +Cc: Paul Pluzhnikov, Andreas Schwab

* Paul Pluzhnikov via Libc-alpha:

> ---
>  elf/dl-open.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/elf/dl-open.c b/elf/dl-open.c
> index 91a2d8a538..d46956ea21 100644
> --- a/elf/dl-open.c
> +++ b/elf/dl-open.c
> @@ -578,7 +578,8 @@ dl_open_worker_begin (void *a)
>        if ((mode & RTLD_GLOBAL) && new->l_global == 0)
>  	add_to_global_update (new);
>  
> -      assert (_dl_debug_update (args->nsid)->r_state == RT_CONSISTENT);
> +      const int r_state = _dl_debug_update (args->nsid)->r_state;
> +      assert (r_state == RT_CONSISTENT);
>  
>        return;
>      }
> @@ -927,7 +928,8 @@ no more namespaces available for dlmopen()"));
>        _dl_signal_exception (errcode, &exception, NULL);
>      }
>  
> -  assert (_dl_debug_update (args.nsid)->r_state == RT_CONSISTENT);
> +  const int r_state = _dl_debug_update (args.nsid)->r_state;
> +  assert (r_state == RT_CONSISTENT);
>  
>    /* Release the lock.  */
>    __rtld_lock_unlock_recursive (GL(dl_load_lock));

This needs __attribute__ ((unused)) on r_state to support building
with -DNDEBUG (although I have not tested that).

^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH] Minor: don't call _dl_debug_update (which can have side effects) inside assert
  2023-03-25 22:09   ` Florian Weimer
@ 2023-03-26  0:24     ` Paul Pluzhnikov
  2023-03-26 10:35       ` Florian Weimer
  0 siblings, 1 reply; 6+ messages in thread
From: Paul Pluzhnikov @ 2023-03-26  0:24 UTC (permalink / raw)
  To: libc-alpha; +Cc: Paul Pluzhnikov, Florian Weimer, Andreas Schwab

On Sat, Mar 25, 2023 at 3:09 PM Florian Weimer <fw@deneb.enyo.de> wrote:

> This needs __attribute__ ((unused)) on r_state to support building
> with -DNDEBUG (although I have not tested that).

Thanks. Revised patch included.

---
 elf/dl-open.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

diff --git a/elf/dl-open.c b/elf/dl-open.c
index 91a2d8a538..2d985e21d8 100644
--- a/elf/dl-open.c
+++ b/elf/dl-open.c
@@ -578,7 +578,9 @@ dl_open_worker_begin (void *a)
       if ((mode & RTLD_GLOBAL) && new->l_global == 0)
 	add_to_global_update (new);
 
-      assert (_dl_debug_update (args->nsid)->r_state == RT_CONSISTENT);
+      const int r_state __attribute__ ((unused))
+        = _dl_debug_update (args->nsid)->r_state;
+      assert (r_state == RT_CONSISTENT);
 
       return;
     }
@@ -927,7 +929,9 @@ no more namespaces available for dlmopen()"));
       _dl_signal_exception (errcode, &exception, NULL);
     }
 
-  assert (_dl_debug_update (args.nsid)->r_state == RT_CONSISTENT);
+  const int r_state __attribute__ ((unused))
+    = _dl_debug_update (args.nsid)->r_state;
+  assert (r_state == RT_CONSISTENT);
 
   /* Release the lock.  */
   __rtld_lock_unlock_recursive (GL(dl_load_lock));
-- 
2.40.0.348.gf938b09366-goog


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] Minor: don't call _dl_debug_update (which can have side effects) inside assert
  2023-03-26  0:24     ` Paul Pluzhnikov
@ 2023-03-26 10:35       ` Florian Weimer
  0 siblings, 0 replies; 6+ messages in thread
From: Florian Weimer @ 2023-03-26 10:35 UTC (permalink / raw)
  To: Paul Pluzhnikov via Libc-alpha; +Cc: Paul Pluzhnikov, Andreas Schwab

* Paul Pluzhnikov via Libc-alpha:

> On Sat, Mar 25, 2023 at 3:09 PM Florian Weimer <fw@deneb.enyo.de> wrote:
>
>> This needs __attribute__ ((unused)) on r_state to support building
>> with -DNDEBUG (although I have not tested that).
>
> Thanks. Revised patch included.
>
> ---
>  elf/dl-open.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/elf/dl-open.c b/elf/dl-open.c
> index 91a2d8a538..2d985e21d8 100644
> --- a/elf/dl-open.c
> +++ b/elf/dl-open.c
> @@ -578,7 +578,9 @@ dl_open_worker_begin (void *a)
>        if ((mode & RTLD_GLOBAL) && new->l_global == 0)
>  	add_to_global_update (new);
>  
> -      assert (_dl_debug_update (args->nsid)->r_state == RT_CONSISTENT);
> +      const int r_state __attribute__ ((unused))
> +        = _dl_debug_update (args->nsid)->r_state;
> +      assert (r_state == RT_CONSISTENT);
>  
>        return;
>      }
> @@ -927,7 +929,9 @@ no more namespaces available for dlmopen()"));
>        _dl_signal_exception (errcode, &exception, NULL);
>      }
>  
> -  assert (_dl_debug_update (args.nsid)->r_state == RT_CONSISTENT);
> +  const int r_state __attribute__ ((unused))
> +    = _dl_debug_update (args.nsid)->r_state;
> +  assert (r_state == RT_CONSISTENT);
>  
>    /* Release the lock.  */
>    __rtld_lock_unlock_recursive (GL(dl_load_lock));

This version looks okay to me, thanks.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-03-26 10:35 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-03-23 12:54 Side effect inside assert macro? Andreas Schwab
2023-03-25 19:48 ` Paul Pluzhnikov
2023-03-25 21:32 ` [PATCH] Minor: don't call _dl_debug_update (which can have side effects) inside assert Paul Pluzhnikov
2023-03-25 22:09   ` Florian Weimer
2023-03-26  0:24     ` Paul Pluzhnikov
2023-03-26 10:35       ` Florian Weimer

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).