[Git][reproducible-builds/diffoscope][master] 3 commits: Add --no-show-raw-insn to objdump commands

Chris Lamb gitlab at salsa.debian.org
Fri Jul 3 09:24:01 UTC 2020



Chris Lamb pushed to branch master at Reproducible Builds / diffoscope


Commits:
cbcb41e8 by Jean-Romain Garnier at 2020-07-03T10:23:14+01:00
Add --no-show-raw-insn to objdump commands

- - - - -
e9e29040 by Jean-Romain Garnier at 2020-07-03T10:23:14+01:00
Remove raw instructions from ELF tests

- - - - -
3e72c1c3 by Jean-Romain Garnier at 2020-07-03T10:23:14+01:00
Remove offsets before instructions in objdump

- - - - -


6 changed files:

- diffoscope/comparators/elf.py
- diffoscope/comparators/pe32.py
- tests/data/elf_lib_objdump_expected_diff
- tests/data/elf_obj_expected_diff
- tests/data/elfmix_disassembly_expected_diff
- tests/data/rlib_elf_expected_diff


Changes:

=====================================
diffoscope/comparators/elf.py
=====================================
@@ -202,6 +202,9 @@ class ReadelfStringSection(ReadElfSection):
 
 
 class ObjdumpSection(Command):
+    # Remove offsets before instructions (see issue #17)
+    RE_INSTRUCTION_OFFSET = re.compile(rb"^\s*[0-9a-f]+:")
+
     def __init__(self, path, section_name, *args, **kwargs):
         self._path = path
         self._path_bin = path.encode("utf-8")
@@ -226,7 +229,7 @@ class ObjdumpSection(Command):
         if line.startswith(b"In archive"):
             return b""
 
-        return line
+        return ObjdumpSection.RE_INSTRUCTION_OFFSET.sub(b"", line)
 
 
 class ObjdumpDisassembleSection(ObjdumpSection):
@@ -239,16 +242,23 @@ class ObjdumpDisassembleSection(ObjdumpSection):
         # disassembled instructions.
         # objdump can get the debugging information from the elf or from the
         # stripped symbols file specified in the .gnu_debuglink section
-        return ["--line-numbers", "--disassemble", "--demangle", "--reloc"]
+        return [
+            "--line-numbers",
+            "--disassemble",
+            "--demangle",
+            "--reloc",
+            "--no-show-raw-insn",
+        ]
 
     def filter(self, line):
-        line = super().filter(line)
-        return ObjdumpDisassembleSection.RE_SYMBOL_COMMENT.sub(r"\1", line)
+        # Apply this filter first as super() removes offsets
+        line = ObjdumpDisassembleSection.RE_SYMBOL_COMMENT.sub(r"\1", line)
+        return super().filter(line)
 
 
 class ObjdumpDisassembleSectionNoLineNumbers(ObjdumpDisassembleSection):
     def objdump_options(self):
-        return ["--disassemble", "--demangle"]
+        return ["--disassemble", "--demangle", "--no-show-raw-insn"]
 
 
 READELF_COMMANDS = (


=====================================
diffoscope/comparators/pe32.py
=====================================
@@ -34,6 +34,7 @@ class Objdump(Command):
             "--all-headers",
             "--disassemble-all",
             "--line-numbers",
+            "--no-show-raw-insn",
             self.path,
         )
 


=====================================
tests/data/elf_lib_objdump_expected_diff
=====================================
@@ -4,9 +4,9 @@
  
  0000000000000000 <f>:
  f():
-    0:	55                   	push   %rbp
-    1:	48 89 e5             	mov    %rsp,%rbp
--   4:	b8 2a 00 00 00       	mov    $0x2a,%eax
-+   4:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
-    9:	5d                   	pop    %rbp
-    a:	c3                   	retq   
+ 	push   %rbp
+ 	mov    %rsp,%rbp
+-	mov    $0x2a,%eax
++	mov    $0xffffffff,%eax
+ 	pop    %rbp
+ 	retq   


=====================================
tests/data/elf_obj_expected_diff
=====================================
@@ -4,9 +4,9 @@
  
  0000000000000000 <f>:
  f():
-    0:	55                   	push   %rbp
-    1:	48 89 e5             	mov    %rsp,%rbp
--   4:	b8 2a 00 00 00       	mov    $0x2a,%eax
-+   4:	b8 ff ff ff ff       	mov    $0xffffffff,%eax
-    9:	5d                   	pop    %rbp
-    a:	c3                   	retq   
+ 	push   %rbp
+ 	mov    %rsp,%rbp
+-	mov    $0x2a,%eax
++	mov    $0xffffffff,%eax
+ 	pop    %rbp
+ 	retq   


=====================================
tests/data/elfmix_disassembly_expected_diff
=====================================
@@ -4,9 +4,9 @@
  
  0000000000000000 <return42_or_3>:
  return42_or_3():
-    0:	55                   	push   %rbp
-    1:	48 89 e5             	mov    %rsp,%rbp
--   4:	b8 2a 00 00 00       	mov    $0x2a,%eax
-+   4:	b8 2b 00 00 00       	mov    $0x2b,%eax
-    9:	5d                   	pop    %rbp
-    a:	c3                   	retq   
+ 	push   %rbp
+ 	mov    %rsp,%rbp
+-	mov    $0x2a,%eax
++	mov    $0x2b,%eax
+ 	pop    %rbp
+ 	retq   


=====================================
tests/data/rlib_elf_expected_diff
=====================================
@@ -1,17 +1,17 @@
 @@ -6,15 +6,15 @@
  0000000000000000 <__rust_reallocate>:
  __rust_reallocate():
-    0:	41 57                	push   %r15
-    2:	41 56                	push   %r14
-    4:	41 54                	push   %r12
-    6:	53                   	push   %rbx
-    7:	50                   	push   %rax
--   8:	48 89 d3             	mov    %rdx,%rbx
-+   8:	48 89 d1             	mov    %rdx,%rcx
-    b:	49 89 f7             	mov    %rsi,%r15
-    e:	49 89 fe             	mov    %rdi,%r14
-   11:	48 83 f9 10          	cmp    $0x10,%rcx
-   15:	77 16                	ja     2d <__rust_reallocate+0x2d>
-   17:	4c 89 f7             	mov    %r14,%rdi
-   1a:	48 89 de             	mov    %rbx,%rsi
-   1d:	48 83 c4 08          	add    $0x8,%rsp
+ 	push   %r15
+ 	push   %r14
+ 	push   %r12
+ 	push   %rbx
+ 	push   %rax
+-	mov    %rdx,%rbx
++	mov    %rdx,%rcx
+ 	mov    %rsi,%r15
+ 	mov    %rdi,%r14
+ 	cmp    $0x10,%rcx
+ 	ja     2d <__rust_reallocate+0x2d>
+ 	mov    %r14,%rdi
+ 	mov    %rbx,%rsi
+ 	add    $0x8,%rsp



View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/0846ae8f08de5113d2035212b6a146d27beaf9de...3e72c1c37e901cb14a2d2cf1d0e7fbea8767cc00

-- 
View it on GitLab: https://salsa.debian.org/reproducible-builds/diffoscope/-/compare/0846ae8f08de5113d2035212b6a146d27beaf9de...3e72c1c37e901cb14a2d2cf1d0e7fbea8767cc00
You're receiving this email because of your account on salsa.debian.org.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.reproducible-builds.org/pipermail/rb-commits/attachments/20200703/135b26a3/attachment.htm>


More information about the rb-commits mailing list