Substitution of the filename with "<elf>" causes unnecessary differences
This bug was originally reported by Mike Hommey (mh+reportbug@glandium.org) in Debian bug #945572:
Steps to reproduce:
$ cat > foo.c <<EOF
int foo() {
return N;
}
EOF
$ cat > foo.syms <<EOF
libfoo.so {
global: *;
};
EOF
$ mkdir old
$ gcc -o old/libfoo.so -shared foo.c -fPIC -DN=42 -Wl,--version-script,foo.syms
$ gcc -o libfoo.so -shared foo.c -fPIC -DN=2 -Wl,--version-script,foo.syms
$ diffoscope old/libfoo.so libfoo.so
--- old/libfoo.so
+++ libfoo.so
├── readelf --wide --symbols {}
│ @@ -2,16 +2,16 @@
│ Symbol table '.dynsym' contains 7 entries:
│ Num: Value Size Type Bind Vis Ndx Name
│ 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
│ 1: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __cxa_finalize
│ 2: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable
│ 3: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTable
│ 4: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
│ - 5: 0000000000000000 0 OBJECT GLOBAL DEFAULT ABS libfoo.so
│ - 6: 00000000000010f5 11 FUNC GLOBAL DEFAULT 11 foo@@libfoo.so
│ + 5: 0000000000000000 0 OBJECT GLOBAL DEFAULT ABS <elf>
│ + 6: 00000000000010f5 11 FUNC GLOBAL DEFAULT 11 foo@@<elf>
│
│ Symbol table '.symtab' contains 48 entries:
│ Num: Value Size Type Bind Vis Ndx Name
│ 0: 0000000000000000 0 NOTYPE LOCAL DEFAULT UND
│ 1: 0000000000000238 0 SECTION LOCAL DEFAULT 1
│ 2: 0000000000000260 0 SECTION LOCAL DEFAULT 2
│ 3: 0000000000000288 0 SECTION LOCAL DEFAULT 3
│ @@ -53,9 +53,9 @@
│ 39: 0000000000002000 0 NOTYPE LOCAL DEFAULT 13 __GNU_EH_FRAME_HDR
│ 40: 0000000000001100 0 FUNC LOCAL DEFAULT 12 _fini
│ 41: 0000000000004000 0 OBJECT LOCAL DEFAULT 19 _GLOBAL_OFFSET_TABLE_
│ 42: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __cxa_finalize
│ 43: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_registerTMCloneTable
│ 44: 0000000000000000 0 NOTYPE WEAK DEFAULT UND _ITM_deregisterTMCloneTable
│ 45: 00000000000010f5 11 FUNC GLOBAL DEFAULT 11 foo
│ - 46: 0000000000000000 0 OBJECT GLOBAL DEFAULT ABS libfoo.so
│ + 46: 0000000000000000 0 OBJECT GLOBAL DEFAULT ABS <elf>
│ 47: 0000000000000000 0 NOTYPE WEAK DEFAULT UND __gmon_start__
├── readelf --wide --notes {}
│ @@ -1,4 +1,4 @@
│
│ Displaying notes found in: .note.gnu.build-id
│ Owner Data size Description
│ - GNU 0x00000014 NT_GNU_BUILD_ID (unique build ID bitstring) Build ID: 53f0f7a35b61ebb857235ac3e519faf82f1dc6e1
│ + GNU 0x00000014 NT_GNU_BUILD_ID (unique build ID bitstring) Build ID: ffcb9d36c33ccdc0b1c5819bbfb239e28559c8ee
├── readelf --wide --version-info {}
│ @@ -1,10 +1,10 @@
│
│ Version symbols section '.gnu.version' contains 7 entries:
│ Addr: 0x0000000000000394 Offset: 0x000394 Link: 3 (.dynsym)
│ 000: 0 (*local*) 0 (*local*) 0 (*local*) 0 (*local*)
│ - 004: 0 (*local*) 2 (libfoo.so) 2 (libfoo.so)
│ + 004: 0 (*local*) 2 (<elf>) 2 (<elf>)
│
│ Version definition section '.gnu.version_d' contains 2 entries:
│ Addr: 0x00000000000003a8 Offset: 0x0003a8 Link: 4 (.dynstr)
│ - 000000: Rev: 1 Flags: BASE Index: 1 Cnt: 1 Name: libfoo.so
│ - 0x001c: Rev: 1 Flags: none Index: 2 Cnt: 1 Name: libfoo.so
│ + 000000: Rev: 1 Flags: BASE Index: 1 Cnt: 1 Name: <elf>
│ + 0x001c: Rev: 1 Flags: none Index: 2 Cnt: 1 Name: <elf>
├── objdump --line-numbers --disassemble --demangle --reloc --section=.text {}
│ @@ -59,10 +59,10 @@
│ frame_dummy():
│ 10f0: e9 7b ff ff ff jmpq 1070 <register_tm_clones>
│
│ 00000000000010f5 <foo>:
│ foo():
│ 10f5: 55 push %rbp
│ 10f6: 48 89 e5 mov %rsp,%rbp
│ - 10f9: b8 2a 00 00 00 mov $0x2a,%eax
│ + 10f9: b8 02 00 00 00 mov $0x2,%eax
│ 10fe: 5d pop %rbp
│ 10ff: c3 retq
None of these libfoo.so vs. <elf> differences are relevant. They are
entirely due to diffoscope doing the substitution of the filename with
<elf>. Passing full file paths to the command works around the problem:
$ diffoscope old/libfoo.so $PWD/libfoo.so
--- old/libfoo.so
+++ /tmp/libfoo.so
├── readelf --wide --notes {}
│ @@ -1,4 +1,4 @@
│
│ Displaying notes found in: .note.gnu.build-id
│ Owner Data size Description
│ - GNU 0x00000014 NT_GNU_BUILD_ID (unique build ID bitstring) Build ID: 53f0f7a35b61ebb857235ac3e519faf82f1dc6e1
│ + GNU 0x00000014 NT_GNU_BUILD_ID (unique build ID bitstring) Build ID: ffcb9d36c33ccdc0b1c5819bbfb239e28559c8ee
├── objdump --line-numbers --disassemble --demangle --reloc --section=.text {}
│ @@ -59,10 +59,10 @@
│ frame_dummy():
│ 10f0: e9 7b ff ff ff jmpq 1070 <register_tm_clones>
│
│ 00000000000010f5 <foo>:
│ foo():
│ 10f5: 55 push %rbp
│ 10f6: 48 89 e5 mov %rsp,%rbp
│ - 10f9: b8 2a 00 00 00 mov $0x2a,%eax
│ + 10f9: b8 02 00 00 00 mov $0x2,%eax
│ 10fe: 5d pop %rbp
│ 10ff: c3 retq