Openembedded Core Discussions
 help / color / mirror / Atom feed
From: Phil Blundell <philb@gnu.org>
To: oe-core <openembedded-core@lists.openembedded.org>
Subject: Re: [PATCH v2] insane: make GNU_HASH check slightly more robust (avoids false negatives with gold); add check for useless rpaths
Date: Thu, 14 Jul 2011 10:02:11 +0100	[thread overview]
Message-ID: <1310634132.2378.36.camel@phil-desktop> (raw)

It isn't safe to make assumptions about the order of the entries in the dynamic section.  Fix the ldflags test to cope with the case where GNU_HASH comes before NEEDED and/or INIT.

Also, add a new warning for binaries which contain useless (but benign) rpath entries pointing to the default search locations.

Signed-off-by: Phil Blundell <philb@gnu.org>
---
v2: fix typo in first version

 meta/classes/insane.bbclass |   44 ++++++++++++++++++++++++++++++++----------
 1 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/meta/classes/insane.bbclass b/meta/classes/insane.bbclass
index 8d5da00..c45f2cb 100644
--- a/meta/classes/insane.bbclass
+++ b/meta/classes/insane.bbclass
@@ -92,7 +92,7 @@ def package_qa_get_machine_dict():
        }
 
 
-WARN_QA ?= "dev-so rpaths debug-deps dev-deps debug-files arch la2 pkgconfig desktop la ldflags perms"
+WARN_QA ?= "dev-so rpaths debug-deps dev-deps debug-files arch la2 pkgconfig desktop la ldflags perms useless-rpaths"
 ERROR_QA ?= ""
 #ERROR_QA ?= "rpaths debug-deps dev-deps debug-files arch pkgconfig perms"
 
@@ -141,6 +141,31 @@ def package_qa_check_rpath(file,name, d, elf, messages):
             if dir in line:
                 messages.append("package %s contains bad RPATH %s in file %s" % (name, line, file))
 
+QAPATHTEST[useless-rpaths] = "package_qa_check_useless_rpaths"
+def package_qa_check_useless_rpaths(file,name, d, elf, messages):
+    """
+    Check for RPATHs that are useless but not dangerous
+    """
+    if not elf:
+        return
+
+    objdump = bb.data.getVar('OBJDUMP', d, True)
+    env_path = bb.data.getVar('PATH', d, True)
+
+    libdir = bb.data.getVar("libdir", d, True)
+    base_libdir = bb.data.getVar("base_libdir", d, True)
+
+    import re
+    rpath_re = re.compile("\s+RPATH\s+(.*)")
+    for line in os.popen("LC_ALL=C PATH=%s %s -p '%s' 2> /dev/null" % (env_path, objdump, file), "r"):
+    	m = rpath_re.match(line)
+	if m:
+	   rpath = m.group(1)
+	   if rpath == libdir or rpath == base_libdir:
+	      # The dynamic linker searches both these places anyway.  There is no point in
+	      # looking there again.
+	      messages.append("dynamic section contains probably-redundant RPATH %s" % rpath)
+
 QAPATHTEST[dev-so] = "package_qa_check_dev"
 def package_qa_check_dev(path, name, d, elf, messages):
     """
@@ -238,22 +263,19 @@ def package_qa_hash_style(path, name, d, elf, messages):
     objdump = bb.data.getVar('OBJDUMP', d, True)
     env_path = bb.data.getVar('PATH', d, True)
 
-    sane = True
-    elf = False
-    # A bit hacky. We do not know if path is an elf binary or not
-    # we will search for 'NEEDED' or 'INIT' as this should be printed...
-    # and come before the HASH section (guess!!!) and works on split out
-    # debug symbols too
+    sane = False
+    has_syms = False
+
+    # If this binary has symbols, we expect it to have GNU_HASH too.
     for line in os.popen("LC_ALL=C PATH=%s %s -p '%s' 2> /dev/null" % (env_path, objdump, path), "r"):
-        if "NEEDED" in line or "INIT" in line:
-            sane = False
-            elf = True
+        if "SYMTAB" in line:
+            has_syms = True
         if "GNU_HASH" in line:
             sane = True
         if "[mips32]" in line or "[mips64]" in line:
 	    sane = True
 
-    if elf and not sane:
+    if has_syms and not sane:
         messages.append("No GNU_HASH in the elf binary: '%s'" % path)
 
 
-- 
1.7.4.1






             reply	other threads:[~2011-07-14  9:06 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-07-14  9:02 Phil Blundell [this message]
2011-07-14 14:07 ` [PATCH v2] insane: make GNU_HASH check slightly more robust (avoids false negatives with gold); add check for useless rpaths Richard Purdie
2011-07-14 19:26 ` Koen Kooi
2011-07-15 11:21   ` Phil Blundell
2011-07-15 12:34     ` Koen Kooi
2011-07-20 14:48     ` Richard Purdie

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

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

  git send-email \
    --in-reply-to=1310634132.2378.36.camel@phil-desktop \
    --to=philb@gnu.org \
    --cc=openembedded-core@lists.openembedded.org \
    /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