[PATCH] elfclassify tool

Mark Wielaard mark@klomp.org
Sat Jul 27 11:54:00 GMT 2019


On Sat, Jul 27, 2019 at 02:04:48AM +0300, Dmitry V. Levin wrote:
> On Sat, Jul 20, 2019 at 11:51:16PM +0200, Mark Wielaard wrote:
> > On Sat, Jul 20, 2019 at 01:57:27AM +0300, Dmitry V. Levin wrote:
> [...]
> > > btw, I think it would be appropriate to move the has_dynamic check before
> > > the first check in is_shared that returns true.
> > 
> > Yes, that is probably fine, but does it really matter?
> 
> It doesn't matter unless the file has DT_SONAME but doesn't have PT_DYNAMIC.
> 
> If /lib64/ld-linux-x86-64.so.2 --verify doesn't like files without
> PT_DYNAMIC, elfclassify --shared shouldn't classify them as DSOs, too.

Yes, I see how theoretically that is "more correct".  But if the file
doesn't have PT_DYNAMIC then it cannot have a DT_SONAME.  And there
are no other checks that return true. So in practice there is no
difference. Still, if it looks more correct, then lets just swap the
checks.

diff --git a/src/elfclassify.c b/src/elfclassify.c
index 03655aea..0b1bb63a 100644
--- a/src/elfclassify.c
+++ b/src/elfclassify.c
@@ -498,6 +498,11 @@ is_shared (void)
   if (elf_type == ET_EXEC)
     return false;
 
+  /* If there is no dynamic section, the file cannot be loaded as a
+     shared object.  */
+  if (!has_dynamic)
+    return false;
+
   /* If the object is marked as PIE, it is definitely an executable,
      and not a loadlable shared object.  */
   if (has_pie_flag)
@@ -526,10 +531,6 @@ is_shared (void)
   if (has_dt_debug)
     return false;
 
-  /* If there is no dynamic section, the file cannot be loaded as a
-     shared object.  */
-  if (!has_dynamic)
-    return false;
   return true;
 }
 
Thanks,

Mark



More information about the Elfutils-devel mailing list