[glade] Fixed bugs in LibcWrapGenerator.vala



commit 21e1d4397fecaa285eaf7b3141771d56eda8dda2
Author: Tristan Van Berkom <tristan upstairslabs com>
Date:   Thu Dec 19 17:42:07 2013 +0900

    Fixed bugs in LibcWrapGenerator.vala
    
    The generator was working on my system but still had some flaws I didn't
    encounter, thanks to Thiblault Saunier for testing this and finding it's
    weakness on his system I was able to fix this.
    
    Also pushing new version of the libcwrap.h file generated from glibc 2.15
    targetting glibc 2.7

 build/linux/LibcWrapGenerator.vala |   86 +++++++++++++++++++++++++++---------
 build/linux/libcwrap.h             |    8 ++--
 2 files changed, 69 insertions(+), 25 deletions(-)
---
diff --git a/build/linux/LibcWrapGenerator.vala b/build/linux/LibcWrapGenerator.vala
index 8a3bff1..10d4a65 100644
--- a/build/linux/LibcWrapGenerator.vala
+++ b/build/linux/LibcWrapGenerator.vala
@@ -31,27 +31,25 @@ static const string DEFAULT_TARGET_HELP = "Target glibc ABI (Default 2.7)";
 [Flags]
 public enum DF { 
        COLLECT,
-       FILTER
+       FILTER,
+       VERSION_PARSE,
+       VERSION_COMPARE,
+       DUMP_FILES
 }
 
 static const GLib.DebugKey[] libcwrap_debug_keys = {
-       { "collect", DF.COLLECT },
-       { "filter", DF.FILTER } 
+       { "collect",         DF.COLLECT         },
+       { "filter",          DF.FILTER          },
+       { "version-parse",   DF.VERSION_PARSE   },
+       { "version-compare", DF.VERSION_COMPARE },
+       { "dump-files",      DF.DUMP_FILES      }
 };
 
-private bool libcwrap_debug_initialized = false;
 private uint libcwrap_debug_mask = 0;
 public delegate void DebugFunc ();
 
 public void libcwrap_note (int domain, DebugFunc debug_func)
 {
-       if (!libcwrap_debug_initialized) {
-               string libcwrap_debug_env = GLib.Environment.get_variable ("LIBCWRAP_DEBUG");
-
-               libcwrap_debug_mask = GLib.parse_debug_string (libcwrap_debug_env, libcwrap_debug_keys);
-               libcwrap_debug_initialized = true;
-       }
-
        if ((libcwrap_debug_mask & domain) != 0)
                debug_func ();
 }
@@ -88,27 +86,38 @@ class VersionNumber : Object
                                revision = 0;
                } catch (GLib.RegexError e) {
                        stdout.printf ("Error compiling regular expression: %s", e.message);
-                       Posix.exit(-1);
+                       Posix.exit (-1);
                }
+
+               libcwrap_note (DF.VERSION_PARSE, () =>
+                                          stdout.printf ("Version string '%s' parsed as major: %d minor: %d 
rev: %d\n", 
+                                                                         originalString, major, minor, 
revision));
        }
 
        public bool newerThan(VersionNumber other) {
+               bool newerThanOther = false;
 
                if (major > other.major) {
-                       return true;
+                       newerThanOther = true;
                } else if (major == other.major) {
 
                        if (minor > other.minor) {
-                               return true;
+                               newerThanOther = true;
                        } else if (minor == other.minor) {
 
                                if(revision > other.revision) {
-                                       return true;
+                                       newerThanOther = true;
                                }
                        }
                }
 
-               return false;
+               libcwrap_note (DF.VERSION_COMPARE, () =>
+                                          stdout.printf ("Version '%s' is %s than version '%s'\n", 
+                                                                         originalString,
+                                                                         newerThanOther ? "newer" : "older",
+                                                                         other.getString()));
+
+               return newerThanOther;
        }
 
        public string getString() {
@@ -140,6 +149,10 @@ public class Main : Object {
 
        public static int main (string[] args) {
 
+               /* Initialize debugging */
+               string libcwrap_debug_env = GLib.Environment.get_variable ("LIBCWRAP_DEBUG");
+               libcwrap_debug_mask = GLib.parse_debug_string (libcwrap_debug_env, libcwrap_debug_keys);
+
                /* Initialize the default here */
                target = DEFAULT_TARGET;
 
@@ -196,11 +209,17 @@ public class Main : Object {
        }
 
        private static void parseLibrary (Regex regex, FileInfo fileinfo) throws Error {
-
+               string commandToUse = "objdump -T";
                string output, errorOutput;
                int returnCode;
 
-               Process.spawn_command_line_sync ("objdump -T " + libdir + "/" + fileinfo.get_name(), 
+               /* For testing on objdump files which might be collected on other systems,
+                * run the generator with --libdir /path/to/objdump/files/
+                */
+               if ((libcwrap_debug_mask & DF.DUMP_FILES) != 0)
+                       commandToUse = "cat";
+
+               Process.spawn_command_line_sync (commandToUse + " " + libdir + "/" + fileinfo.get_name(), 
                                                                                 out output, out errorOutput, 
out returnCode);
 
                if (returnCode != 0)
@@ -241,8 +260,33 @@ public class Main : Object {
                                         * minimum glibc version specified (or the only version of the symbol 
if
                                         * it's newer than the minimum version)
                                         */
-                                       if (version.newerThan (versionInMap) && minimumVersion.newerThan 
(version))
-                                               symbolMap.set (symbolName, version);
+
+                                       /* This symbol is <= minimumVersion
+                                        */
+                                       if (!version.newerThan (minimumVersion)) {
+
+                                               /* What we have in the map is > minimumVersion, so we need 
this version */
+                                               if (versionInMap.newerThan (minimumVersion))
+                                                       symbolMap.set (symbolName, version);
+
+                                               /* What we have in the map is already <= minimumVersion, but 
we want
+                                                * the most recent acceptable symbol
+                                                */
+                                               else if (version.newerThan (versionInMap))
+                                                       symbolMap.set (symbolName, version);
+
+
+                                       } else { /* This symbol is > minimumVersion */
+
+                                               /* If there are only versions > minimumVersion, then we want
+                                                * the lowest possible version, this is because we try to 
provide
+                                                * information in the linker warning about what version the 
symbol
+                                                * was initially introduced in.
+                                                */
+                                               if (versionInMap.newerThan (minimumVersion) &&
+                                                       versionInMap.newerThan (version))
+                                                       symbolMap.set (symbolName, version);
+                                       }
 
                                        /* While trucking along through the huge symbol list, remove symbols 
from
                                         * the 'safe to exclude' if there is a version found which is newer
@@ -251,7 +295,7 @@ public class Main : Object {
                                        if (version.newerThan (minimumVersion)) {
                                                filterMap.remove(symbolName);
                                                libcwrap_note (DF.FILTER, () =>
-                                                                          stdout.printf ("Removing symbol 
'%s %s' from the filter\n", 
+                                                                          stdout.printf ("Removing symbol 
'%s' from the filter, found version '%s'\n", 
                                                                                                          
symbolName, version.getString()));
                                        }
                                }
diff --git a/build/linux/libcwrap.h b/build/linux/libcwrap.h
index 6958537..57a7833 100644
--- a/build/linux/libcwrap.h
+++ b/build/linux/libcwrap.h
@@ -18,6 +18,7 @@ __asm__(".symver __isoc99_fwscanf, __isoc99_fwscanf GLIBC_2 7");
 __asm__(".symver mkostemp64, mkostemp64 GLIBC_2 7");
 __asm__(".symver __openat_2, __openat_2 GLIBC_2 7");
 __asm__(".symver memcpy, memcpy GLIBC_2 2 5");
+__asm__(".symver sys_errlist, sys_errlist GLIBC_2 4");
 __asm__(".symver __isoc99_vswscanf, __isoc99_vswscanf GLIBC_2 7");
 __asm__(".symver __fread_chk, __fread_chk GLIBC_2 7");
 __asm__(".symver __isoc99_swscanf, __isoc99_swscanf GLIBC_2 7");
@@ -28,11 +29,14 @@ __asm__(".symver __isoc99_vwscanf, __isoc99_vwscanf GLIBC_2 7");
 __asm__(".symver _sys_errlist, _sys_errlist GLIBC_2 4");
 __asm__(".symver __isoc99_wscanf, __isoc99_wscanf GLIBC_2 7");
 __asm__(".symver __isoc99_vsscanf, __isoc99_vsscanf GLIBC_2 7");
+__asm__(".symver posix_spawn, posix_spawn GLIBC_2 2 5");
 __asm__(".symver __fread_unlocked_chk, __fread_unlocked_chk GLIBC_2 7");
 __asm__(".symver __isoc99_vfscanf, __isoc99_vfscanf GLIBC_2 7");
+__asm__(".symver posix_spawnp, posix_spawnp GLIBC_2 2 5");
 __asm__(".symver __isoc99_sscanf, __isoc99_sscanf GLIBC_2 7");
 __asm__(".symver __isoc99_fscanf, __isoc99_fscanf GLIBC_2 7");
 __asm__(".symver signalfd, signalfd GLIBC_2 7");
+__asm__(".symver _sys_nerr, _sys_nerr GLIBC_2 4");
 __asm__(".symver __isoc99_scanf, __isoc99_scanf GLIBC_2 7");
 __asm__(".symver __mq_open_2, __mq_open_2 GLIBC_2 7");
 __asm__(".symver __open_2, __open_2 GLIBC_2 7");
@@ -97,7 +101,6 @@ __asm__(".symver timerfd_create, timerfd_create GLIBC_DONT_USE_THIS_VERSION_2 8"
 __asm__(".symver __jnl_finite, __jnl_finite GLIBC_DONT_USE_THIS_VERSION_2 15");
 __asm__(".symver __acosh_finite, __acosh_finite GLIBC_DONT_USE_THIS_VERSION_2 15");
 __asm__(".symver __powl_finite, __powl_finite GLIBC_DONT_USE_THIS_VERSION_2 15");
-__asm__(".symver sys_errlist, sys_errlist GLIBC_DONT_USE_THIS_VERSION_2 12");
 __asm__(".symver process_vm_writev, process_vm_writev GLIBC_DONT_USE_THIS_VERSION_2 15");
 __asm__(".symver ns_parse_ttl, ns_parse_ttl GLIBC_DONT_USE_THIS_VERSION_2 9");
 __asm__(".symver __vdprintf_chk, __vdprintf_chk GLIBC_DONT_USE_THIS_VERSION_2 8");
@@ -150,7 +153,6 @@ __asm__(".symver ns_name_skip, ns_name_skip GLIBC_DONT_USE_THIS_VERSION_2 9");
 __asm__(".symver getsgnam, getsgnam GLIBC_DONT_USE_THIS_VERSION_2 10");
 __asm__(".symver __jnf_finite, __jnf_finite GLIBC_DONT_USE_THIS_VERSION_2 15");
 __asm__(".symver fanotify_mark, fanotify_mark GLIBC_DONT_USE_THIS_VERSION_2 13");
-__asm__(".symver posix_spawn, posix_spawn GLIBC_DONT_USE_THIS_VERSION_2 15");
 __asm__(".symver __lgammaf_r_finite, __lgammaf_r_finite GLIBC_DONT_USE_THIS_VERSION_2 15");
 __asm__(".symver __scalbl_finite, __scalbl_finite GLIBC_DONT_USE_THIS_VERSION_2 15");
 __asm__(".symver qsort_r, qsort_r GLIBC_DONT_USE_THIS_VERSION_2 8");
@@ -162,7 +164,6 @@ __asm__(".symver ns_parserr, ns_parserr GLIBC_DONT_USE_THIS_VERSION_2 9");
 __asm__(".symver __sqrtl_finite, __sqrtl_finite GLIBC_DONT_USE_THIS_VERSION_2 15");
 __asm__(".symver scandirat, scandirat GLIBC_DONT_USE_THIS_VERSION_2 15");
 __asm__(".symver __log10_finite, __log10_finite GLIBC_DONT_USE_THIS_VERSION_2 15");
-__asm__(".symver posix_spawnp, posix_spawnp GLIBC_DONT_USE_THIS_VERSION_2 15");
 __asm__(".symver ns_samedomain, ns_samedomain GLIBC_DONT_USE_THIS_VERSION_2 9");
 __asm__(".symver clock_adjtime, clock_adjtime GLIBC_DONT_USE_THIS_VERSION_2 14");
 __asm__(".symver accept4, accept4 GLIBC_DONT_USE_THIS_VERSION_2 10");
@@ -186,7 +187,6 @@ __asm__(".symver mkostemps64, mkostemps64 GLIBC_DONT_USE_THIS_VERSION_2 11");
 __asm__(".symver __cosh_finite, __cosh_finite GLIBC_DONT_USE_THIS_VERSION_2 15");
 __asm__(".symver __fmodf_finite, __fmodf_finite GLIBC_DONT_USE_THIS_VERSION_2 15");
 __asm__(".symver dup3, dup3 GLIBC_DONT_USE_THIS_VERSION_2 9");
-__asm__(".symver _sys_nerr, _sys_nerr GLIBC_DONT_USE_THIS_VERSION_2 12");
 __asm__(".symver syncfs, syncfs GLIBC_DONT_USE_THIS_VERSION_2 14");
 __asm__(".symver __asin_finite, __asin_finite GLIBC_DONT_USE_THIS_VERSION_2 15");
 __asm__(".symver pwritev64, pwritev64 GLIBC_DONT_USE_THIS_VERSION_2 10");


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]