insane.bbclass: Detect if someone is not using our LDFLAGS
authorHolger Hans Peter Freyther <zecke@selfish.org>
Sun, 26 Oct 2008 19:14:53 +0000 (20:14 +0100)
committerHolger Hans Peter Freyther <zecke@selfish.org>
Tue, 28 Oct 2008 14:15:17 +0000 (15:15 +0100)
    We started passing --target-style=gnu/both to the linker. If the
    buildsystem is not picking up our LDFLAGS it will not have this
    hash in the binary. E.g. this is true for busybox. Add a check to
    insane.bbclass to check if we have a GNU_HASH in the elf binary.

    Make this a non fatal QA option until the majority of packages
    are fixed.

classes/insane.bbclass

index 331fd57..7c9966f 100644 (file)
@@ -183,7 +183,7 @@ def package_qa_make_fatal_error(error_class, name, path,d):
 
     TODO: Load a whitelist of known errors
     """
-    return not error_class in [0, 5, 7]
+    return not error_class in [0, 5, 7, 9]
 
 def package_qa_write_error(error_class, name, path, d):
     """
@@ -204,6 +204,7 @@ def package_qa_write_error(error_class, name, path, d):
         "evil hides inside the .pc",
         "the desktop file is not valid",
         ".la contains reference to the workdir",
+        "LDFLAGS ignored",
     ]
 
     log_path = os.path.join( bb.data.getVar('T', d, True), "log.qa_package" )
@@ -325,6 +326,41 @@ def package_qa_check_desktop(path, name, d):
 
     return sane
 
+def package_qa_hash_style(path, name, d):
+    """
+    Check if the binary has the right hash style...
+    """
+    import bb, os
+
+    if os.path.islink(path):
+        return True
+
+    gnu_hash = "--hash-style=gnu" in bb.data.getVar('LDFLAGS', d, True)
+    if not gnu_hash:
+        gnu_hash = "--hash-style=both" in bb.data.getVar('LDFLAGS', d, True)
+
+    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
+    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 "GNU_HASH" in line:
+            sane = True
+
+    if elf and not sane:
+        error_msg = "No GNU_HASH in the elf binary: '%s'" % path
+        return package_qa_handle_error(9, error_msg, name, path, d)
+
+    return True
+
 def package_qa_check_staged(path,d):
     """
     Check staged la and pc files for sanity
@@ -433,7 +469,7 @@ python do_package_qa () {
 
     checks = [package_qa_check_rpath, package_qa_check_devdbg,
               package_qa_check_perm, package_qa_check_arch,
-              package_qa_check_desktop]
+              package_qa_check_desktop, package_qa_hash_style]
     walk_sane = True
     rdepends_sane = True
     for package in packages.split():