diff mbox series

[2/2] rtld: turn "Already zero" assumptions into asserts

Message ID 20200922121300.3503-2-eb@emlix.com
State New
Headers show
Series [1/2] rtld: fix typo in comment | expand

Commit Message

Rolf Eike Beer Sept. 22, 2020, 12:13 p.m. UTC
---
 elf/rtld.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

H.J. Lu Sept. 22, 2020, 12:28 p.m. UTC | #1
On Tue, Sep 22, 2020 at 5:13 AM Rolf Eike Beer <eb@emlix.com> wrote:
>
> ---
>  elf/rtld.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/elf/rtld.c b/elf/rtld.c
> index 99d130cd1c..441d837095 100644
> --- a/elf/rtld.c
> +++ b/elf/rtld.c
> @@ -1449,7 +1449,7 @@ of this helper program; chances are you did not intend to run this program.\n\
>            the shared object is already loaded.  */
>         _dl_rtld_libname.name = ((const char *) main_map->l_addr
>                                  + ph->p_vaddr);
> -       /* _dl_rtld_libname.next = NULL;        Already zero.  */
> +       assert(_dl_rtld_libname.next == NULL);
Space after assert.  Same applies to other changes.
and there are

rtld.c:static struct libname_list _dl_rtld_libname;
rtld.c:static struct libname_list _dl_rtld_libname2;

There is no need for assert of zero on static variables.

>         GL(dl_rtld_map).l_libname = &_dl_rtld_libname;
>
>         /* Ordinarilly, we would get additional names for the loader from
> @@ -1470,7 +1470,7 @@ of this helper program; chances are you did not intend to run this program.\n\
>             if (p != NULL)
>               {
>                 _dl_rtld_libname2.name = p;
> -               /* _dl_rtld_libname2.next = NULL;  Already zero.  */
> +               assert(_dl_rtld_libname2.next == NULL);
>                 _dl_rtld_libname.next = &_dl_rtld_libname2;
>               }
>           }
> @@ -1555,7 +1555,7 @@ of this helper program; chances are you did not intend to run this program.\n\
>        /* We were invoked directly, so the program might not have a
>          PT_INTERP.  */
>        _dl_rtld_libname.name = GL(dl_rtld_map).l_name;
> -      /* _dl_rtld_libname.next = NULL; Already zero.  */
> +      assert(_dl_rtld_libname.next == NULL);
>        GL(dl_rtld_map).l_libname =  &_dl_rtld_libname;
>      }
>    else
> --
> 2.28.0
>
Rolf Eike Beer Sept. 22, 2020, 12:38 p.m. UTC | #2
H.J. Lu wrote:
> On Tue, Sep 22, 2020 at 5:13 AM Rolf Eike Beer <eb@emlix.com> wrote:
> > ---
> > 
> >  elf/rtld.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/elf/rtld.c b/elf/rtld.c
> > index 99d130cd1c..441d837095 100644
> > --- a/elf/rtld.c
> > +++ b/elf/rtld.c
> > @@ -1449,7 +1449,7 @@ of this helper program; chances are you did not
> > intend to run this program.\n\> 
> >            the shared object is already loaded.  */
> >         
> >         _dl_rtld_libname.name = ((const char *) main_map->l_addr
> >         
> >                                  + ph->p_vaddr);
> > 
> > -       /* _dl_rtld_libname.next = NULL;        Already zero.  */
> > +       assert(_dl_rtld_libname.next == NULL);
> 
> Space after assert.  Same applies to other changes.
> and there are
> 
> rtld.c:static struct libname_list _dl_rtld_libname;
> rtld.c:static struct libname_list _dl_rtld_libname2;
> 
> There is no need for assert of zero on static variables.

Except when by accident the .bss section is not behind the last PT_LOAD and 
suddenly is not zeroed out anymore and it takes you a while to find out _what_ 
exactly is broken ;) But fine with me.

Eike
diff mbox series

Patch

diff --git a/elf/rtld.c b/elf/rtld.c
index 99d130cd1c..441d837095 100644
--- a/elf/rtld.c
+++ b/elf/rtld.c
@@ -1449,7 +1449,7 @@  of this helper program; chances are you did not intend to run this program.\n\
 	   the shared object is already loaded.  */
 	_dl_rtld_libname.name = ((const char *) main_map->l_addr
 				 + ph->p_vaddr);
-	/* _dl_rtld_libname.next = NULL;	Already zero.  */
+	assert(_dl_rtld_libname.next == NULL);
 	GL(dl_rtld_map).l_libname = &_dl_rtld_libname;
 
 	/* Ordinarilly, we would get additional names for the loader from
@@ -1470,7 +1470,7 @@  of this helper program; chances are you did not intend to run this program.\n\
 	    if (p != NULL)
 	      {
 		_dl_rtld_libname2.name = p;
-		/* _dl_rtld_libname2.next = NULL;  Already zero.  */
+		assert(_dl_rtld_libname2.next == NULL);
 		_dl_rtld_libname.next = &_dl_rtld_libname2;
 	      }
 	  }
@@ -1555,7 +1555,7 @@  of this helper program; chances are you did not intend to run this program.\n\
       /* We were invoked directly, so the program might not have a
 	 PT_INTERP.  */
       _dl_rtld_libname.name = GL(dl_rtld_map).l_name;
-      /* _dl_rtld_libname.next = NULL;	Already zero.  */
+      assert(_dl_rtld_libname.next == NULL);
       GL(dl_rtld_map).l_libname =  &_dl_rtld_libname;
     }
   else