public inbox for glibc-cvs@sourceware.org
help / color / mirror / Atom feed
* [glibc/azanella/ld-audit-fixes] elf: Run constructors if executable has a soname of a dependency
@ 2021-11-09 18:19 Adhemerval Zanella
  0 siblings, 0 replies; 2+ messages in thread
From: Adhemerval Zanella @ 2021-11-09 18:19 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=33bf00b012e608a7fc211cca0e65f3f1c2677d6e

commit 33bf00b012e608a7fc211cca0e65f3f1c2677d6e
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Nov 9 13:53:07 2021 -0300

    elf: Run constructors if executable has a soname of a dependency
    
    The DSO constructor should not be ignored if the main executable
    has the SONAME set to a dependency.  It fixes the case where
    (using the scripts/dso-ordering-test.py definition):
    
      {}->a->b->c;soname({})=c
    
    Where the constructors should return
    
      c>b>a>{}<a<b<c
    
    Checked on x86_64-linux-gnu.

Diff:
---
 elf/dl-load.c            | 9 +++++++--
 elf/dso-sort-tests-1.def | 5 ++++-
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/elf/dl-load.c b/elf/dl-load.c
index 4a0ff9d010..d585e1795d 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1998,13 +1998,18 @@ _dl_map_object (struct link_map *loader, const char *name,
   assert (nsid >= 0);
   assert (nsid < GL(dl_nns));
 
+  /* Special case: trying to map itself.  */
+  if (name[0] == '\0')
+    return GL(dl_ns)[nsid]._ns_loaded;
+
   /* Look for this name among those already loaded.  */
   for (l = GL(dl_ns)[nsid]._ns_loaded; l; l = l->l_next)
     {
       /* If the requested name matches the soname of a loaded object,
 	 use that object.  Elide this check for names that have not
-	 yet been opened.  */
-      if (__glibc_unlikely ((l->l_faked | l->l_removed) != 0))
+	 yet been opened or the executable itself.  */
+      if (__glibc_unlikely ((l->l_faked | l->l_removed) != 0
+			    || l->l_type == lt_executable))
 	continue;
       if (!_dl_name_match_p (name, l))
 	{
diff --git a/elf/dso-sort-tests-1.def b/elf/dso-sort-tests-1.def
index 5f7f18ef27..e5803a0e65 100644
--- a/elf/dso-sort-tests-1.def
+++ b/elf/dso-sort-tests-1.def
@@ -50,7 +50,10 @@ output: e>d>c>b>a>{}<a<b<c<d<e
 # Test if init/fini ordering behavior is proper, despite main program with
 # an soname that may cause confusion
 tst-dso-ordering10: {}->a->b->c;soname({})=c
-output: b>a>{}<a<b
+output: c>b>a>{}<a<b<cA
+# Same as before, but with a direct dependency
+tst-dso-ordering10: {}->a->b->c;soname({})=a
+output: c>b>a>{}<a<b<c
 
 # Complex example from Bugzilla #15311, under-linked and with circular
 # relocation(dynamic) dependencies. While this is technically unspecified, the


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

* [glibc/azanella/ld-audit-fixes] elf: Run constructors if executable has a soname of a dependency
@ 2021-11-16 13:58 Adhemerval Zanella
  0 siblings, 0 replies; 2+ messages in thread
From: Adhemerval Zanella @ 2021-11-16 13:58 UTC (permalink / raw)
  To: glibc-cvs

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=706d85d0a177c8bf3e51a0d1a5d9c443f153928a

commit 706d85d0a177c8bf3e51a0d1a5d9c443f153928a
Author: Adhemerval Zanella <adhemerval.zanella@linaro.org>
Date:   Tue Nov 9 13:53:07 2021 -0300

    elf: Run constructors if executable has a soname of a dependency
    
    The DSO constructor should not be ignored if the main executable
    has the SONAME set to a dependency.  It fixes the case where
    (using the scripts/dso-ordering-test.py definition):
    
      {}->a->b->c;soname({})=c
    
    Where the constructors should return
    
      c>b>a>{}<a<b<c
    
    Checked on x86_64-linux-gnu.

Diff:
---
 elf/dl-load.c            | 11 +++++++++--
 elf/dso-sort-tests-1.def |  5 ++++-
 2 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/elf/dl-load.c b/elf/dl-load.c
index 70473fddb6..581895f141 100644
--- a/elf/dl-load.c
+++ b/elf/dl-load.c
@@ -1996,13 +1996,20 @@ _dl_map_object (struct link_map *loader, const char *name,
   assert (nsid >= 0);
   assert (nsid < GL(dl_nns));
 
+  /* Special case: trying to map itself.  An empty name correspond to
+     a NULL or "" argument for dlopen(), and it returns the head object
+     of the namespace.  */
+  if (name[0] == '\0')
+    return GL(dl_ns)[nsid]._ns_loaded;
+
   /* Look for this name among those already loaded.  */
   for (l = GL(dl_ns)[nsid]._ns_loaded; l; l = l->l_next)
     {
       /* If the requested name matches the soname of a loaded object,
 	 use that object.  Elide this check for names that have not
-	 yet been opened.  */
-      if (__glibc_unlikely ((l->l_faked | l->l_removed) != 0))
+	 yet been opened or the executable itself.  */
+      if (__glibc_unlikely ((l->l_faked | l->l_removed) != 0
+			    || l->l_type == lt_executable))
 	continue;
       if (!_dl_name_match_p (name, l))
 	{
diff --git a/elf/dso-sort-tests-1.def b/elf/dso-sort-tests-1.def
index 5f7f18ef27..2228910c0d 100644
--- a/elf/dso-sort-tests-1.def
+++ b/elf/dso-sort-tests-1.def
@@ -50,7 +50,10 @@ output: e>d>c>b>a>{}<a<b<c<d<e
 # Test if init/fini ordering behavior is proper, despite main program with
 # an soname that may cause confusion
 tst-dso-ordering10: {}->a->b->c;soname({})=c
-output: b>a>{}<a<b
+output: c>b>a>{}<a<b<c
+# Same as before, but setting the soname as a direct dependency.
+tst-dso-ordering11: {}->a->b->c;soname({})=a
+output: c>b>a>{}<a<b<c
 
 # Complex example from Bugzilla #15311, under-linked and with circular
 # relocation(dynamic) dependencies. While this is technically unspecified, the


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

end of thread, other threads:[~2021-11-16 13:58 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-09 18:19 [glibc/azanella/ld-audit-fixes] elf: Run constructors if executable has a soname of a dependency Adhemerval Zanella
2021-11-16 13:58 Adhemerval Zanella

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