[PATCH] [utils] Add exact check to check_cfc.py dash_s_no_change

Rafael EspĂ­ndola rafael.espindola at gmail.com
Tue Jun 2 18:20:21 PDT 2015


Lgtm
On Jun 2, 2015 1:31 PM, "Russell Gallop" <russell.gallop at gmail.com> wrote:

> Hi rafael, echristo,
>
> Files compiled with -via-file-asm should be byte for byte identical to
> those compiled in the same way without that option. This change adds an
> exact check to check_cfc.py to spot non-code differences. If there is a
> difference, the check then compares code and debug to try and report more
> detail on the check failure.
>
> This could be helpful in finding bugs like this one:
> https://llvm.org/bugs/show_bug.cgi?id=14524
>
> Running the llvm-test-suite there are dash_s_no_change check failures (as
> of r238815) but not failures in check_cfc.py or new failures introduced by
> this change. I will report bugs for these check failures.
>
> Please let me know if okay to commit?
>
> http://reviews.llvm.org/D10188
>
> Files:
>   utils/check_cfc/check_cfc.py
>   utils/check_cfc/obj_diff.py
>
> Index: utils/check_cfc/check_cfc.py
> ===================================================================
> --- utils/check_cfc/check_cfc.py
> +++ utils/check_cfc/check_cfc.py
> @@ -282,12 +282,24 @@
>          run_step(alternate_command, my_env,
>                   "Error compiling with -via-file-asm")
>
> -        # Compare disassembly (returns first diff if differs)
> -        difference = obj_diff.compare_object_files(self._output_file_a,
> -                                                   output_file_b)
> -        if difference:
> -            raise WrapperCheckException(
> -                "Code difference detected with -S\n{}".format(difference))
> +        # Compare if object files are exactly the same
> +        exactly_equal = obj_diff.compare_exact(self._output_file_a,
> output_file_b)
> +        if not exactly_equal:
> +            # Compare disassembly (returns first diff if differs)
> +            difference =
> obj_diff.compare_object_files(self._output_file_a,
> +                                                       output_file_b)
> +            if difference:
> +                raise WrapperCheckException(
> +                    "Code difference detected with
> -S\n{}".format(difference))
> +
> +            # Code is identical, compare debug info
> +            dbgdifference =
> obj_diff.compare_debug_info(self._output_file_a,
> +                                                        output_file_b)
> +            if dbgdifference:
> +                raise WrapperCheckException(
> +                    "Debug info difference detected with
> -S\n{}".format(dbgdifference))
> +
> +            raise WrapperCheckException("Object files not identical with
> -S\n")
>
>          # Clean up temp file if comparison okay
>          os.remove(output_file_b)
> Index: utils/check_cfc/obj_diff.py
> ===================================================================
> --- utils/check_cfc/obj_diff.py
> +++ utils/check_cfc/obj_diff.py
> @@ -4,6 +4,7 @@
>
>  import argparse
>  import difflib
> +import filecmp
>  import os
>  import subprocess
>  import sys
> @@ -26,6 +27,15 @@
>          sys.exit(1)
>      return filter(keep_line, out.split(os.linesep))
>
> +def dump_debug(objfile):
> +    """Dump all of the debug info from a file."""
> +    p = subprocess.Popen([disassembler, '-WliaprmfsoRt', objfile],
> stdout=subprocess.PIPE, stderr=subprocess.PIPE)
> +    (out, err) = p.communicate()
> +    if p.returncode or err:
> +        print("Dump debug failed: {}".format(objfile))
> +        sys.exit(1)
> +    return filter(keep_line, out.split(os.linesep))
> +
>  def first_diff(a, b, fromfile, tofile):
>      """Returns the first few lines of a difference, if there is one.
> Python
>      diff can be very slow with large objects and the most interesting
> changes
> @@ -63,6 +73,22 @@
>      disb = disassemble(objfileb)
>      return first_diff(disa, disb, objfilea, objfileb)
>
> +def compare_debug_info(objfilea, objfileb):
> +    """Compare debug info of two different files.
> +       Allowing unavoidable differences, such as filenames.
> +       Return the first difference if the debug info differs, or None.
> +       If there are differences in the code, there will almost certainly
> be differences in the debug info too.
> +    """
> +    dbga = dump_debug(objfilea)
> +    dbgb = dump_debug(objfileb)
> +    return first_diff(dbga, dbgb, objfilea, objfileb)
> +
> +def compare_exact(objfilea, objfileb):
> +    """Byte for byte comparison between object files.
> +       Returns True if equal, False otherwise.
> +    """
> +    return filecmp.cmp(objfilea, objfileb)
> +
>  if __name__ == '__main__':
>      parser = argparse.ArgumentParser()
>      parser.add_argument('objfilea', nargs=1)
>
> EMAIL PREFERENCES
>   http://reviews.llvm.org/settings/panel/emailpreferences/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150602/24691881/attachment.html>


More information about the cfe-commits mailing list