[llvm-objcopy] Add file names to error messages

Summary:
This patch adds the file names to llvm-objcopy error messages. It makes easy to identify which file causes an error.

Bugzilla: https://bugs.llvm.org/show_bug.cgi?id=41798

Reviewers: espindola, alexshap, rupprecht, jhenderson, jakehehrlich

Reviewed By: rupprecht, jhenderson, jakehehrlich

Subscribers: emaste, arichardson, jakehehrlich, MaskRay, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D61993

llvm-svn: 361450
diff --git a/llvm/test/tools/llvm-objcopy/ELF/dump-section.test b/llvm/test/tools/llvm-objcopy/ELF/dump-section.test
index 7547fa0..ed46c30 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/dump-section.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/dump-section.test
@@ -3,7 +3,7 @@
 # RUN: llvm-objcopy -O binary --only-section .text %t %t3
 # RUN: llvm-objcopy --dump-section .text=%t4 %t %t5
 # RUN: llvm-objcopy --dump-section .foo=%t6 %t %t7
-# RUN: not llvm-objcopy --dump-section .bar=%t8 %t %t9 2>&1 | FileCheck %s --check-prefix=NOBITS
+# RUN: not llvm-objcopy --dump-section .bar=%t8 %t %t9 2>&1 | FileCheck %s --check-prefix=NOBITS -DINPUT=%t
 # RUN: od -t x1 %t2 | FileCheck %s
 # RUN: od -t x1 %t6 | FileCheck %s --check-prefix=NON-ALLOC
 # RUN: wc -c %t2 | FileCheck %s --check-prefix=SIZE
@@ -41,4 +41,4 @@
 
 #SIZE: 4
 
-#NOBITS: cannot dump section '.bar': it has no contents
+#NOBITS: error: '[[INPUT]]': cannot dump section '.bar': it has no contents
diff --git a/llvm/test/tools/llvm-objcopy/ELF/dynrelocsec-remove-shlink-reference.test b/llvm/test/tools/llvm-objcopy/ELF/dynrelocsec-remove-shlink-reference.test
index 1f07fdf..2ff68de 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/dynrelocsec-remove-shlink-reference.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/dynrelocsec-remove-shlink-reference.test
@@ -2,8 +2,8 @@
 

 ## Check we cannot remove the .dynsym symbol table because dynamic

 ## relocation section .rela.dyn still references it via sh_link field.

-# RUN: not llvm-objcopy -R .dynsym %t %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR

-# ERR: error: symbol table '.dynsym' cannot be removed because it is referenced by the relocation section '.rela.dyn'

+# RUN: not llvm-objcopy -R .dynsym %t %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR -DINPUT=%t

+# ERR: error: '[[INPUT]]': symbol table '.dynsym' cannot be removed because it is referenced by the relocation section '.rela.dyn'

 

 ## Check we can remove .dynsym after removing the reference.

 # RUN: llvm-objcopy -R .dynsym -R .rela.dyn %t %t2

diff --git a/llvm/test/tools/llvm-objcopy/ELF/dynsym-error-remove-strtab.test b/llvm/test/tools/llvm-objcopy/ELF/dynsym-error-remove-strtab.test
index 0a2964b..49779e0 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/dynsym-error-remove-strtab.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/dynsym-error-remove-strtab.test
@@ -1,8 +1,9 @@
-# RUN: not llvm-objcopy -R .dynstr %p/Inputs/dynsym.so %t 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
+# RUN: not llvm-objcopy -R .dynstr %p/Inputs/dynsym.so %t 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR1 -DINPUT=%p/Inputs/dynsym.so
 # RUN: cp  %p/Inputs/dynsym.so %t2
-# RUN: not llvm-strip --no-strip-all -R .dynstr %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
+# RUN: not llvm-strip --no-strip-all -R .dynstr %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR2 -DINPUT=%t2
 
-# ERR: section '.dynstr' cannot be removed because it is referenced by the section '.dynsym'
+# ERR1: error: '[[INPUT]]': section '.dynstr' cannot be removed because it is referenced by the section '.dynsym'
+# ERR2: error: '[[INPUT]]': section '.dynstr' cannot be removed because it is referenced by the section '.dynsym'
 
 # RUN: llvm-objcopy --allow-broken-links -R .dynstr %p/Inputs/dynsym.so %t3
 # RUN: llvm-objdump --section-headers %t3 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.dynstr
diff --git a/llvm/test/tools/llvm-objcopy/ELF/no-build-id.test b/llvm/test/tools/llvm-objcopy/ELF/no-build-id.test
index 24aa4c1..a66af94 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/no-build-id.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/no-build-id.test
@@ -1,7 +1,7 @@
 # RUN: yaml2obj %s > %t
-# RUN: not llvm-objcopy --build-id-link-dir=%t-dir --build-id-link-input=.debug %t 2>&1 >/dev/null | FileCheck %s
+# RUN: not llvm-objcopy --build-id-link-dir=%t-dir --build-id-link-input=.debug %t 2>&1 >/dev/null | FileCheck %s -DINPUT=%t
 
-# CHECK: could not find build ID
+# CHECK: error: '[[INPUT]]': could not find build ID
 
 --- !ELF
 FileHeader:
diff --git a/llvm/test/tools/llvm-objcopy/ELF/reloc-error-remove-symtab.test b/llvm/test/tools/llvm-objcopy/ELF/reloc-error-remove-symtab.test
index 0724abf..4c161de 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/reloc-error-remove-symtab.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/reloc-error-remove-symtab.test
@@ -1,7 +1,7 @@
 # RUN: yaml2obj %s > %t
-# RUN: not llvm-objcopy -R .symtab %t %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
+# RUN: not llvm-objcopy -R .symtab %t %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR1 -DINPUT=%t
 # RUN: cp %t %t3
-# RUN: not llvm-strip --no-strip-all -R .symtab %t3 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
+# RUN: not llvm-strip --no-strip-all -R .symtab %t3 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR2 -DINPUT=%t3
 
 !ELF
 FileHeader:
@@ -31,7 +31,8 @@
     Size:     4
     Binding:  STB_GLOBAL
 
-# ERR: symbol table '.symtab' cannot be removed because it is referenced by the relocation section '.rel.text'
+# ERR1: error: '[[INPUT]]': symbol table '.symtab' cannot be removed because it is referenced by the relocation section '.rel.text'
+# ERR2: error: '[[INPUT]]': symbol table '.symtab' cannot be removed because it is referenced by the relocation section '.rel.text'
 
 # RUN: llvm-objcopy --allow-broken-links -R .symtab %t %t4
 # RUN: llvm-readobj --sections %t4 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.symtab
diff --git a/llvm/test/tools/llvm-objcopy/ELF/remove-linked-section.test b/llvm/test/tools/llvm-objcopy/ELF/remove-linked-section.test
index 909c6d0..53ffc9e 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/remove-linked-section.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/remove-linked-section.test
@@ -1,7 +1,7 @@
 # RUN: yaml2obj %s -o %t.o
-# RUN: not llvm-objcopy -R .foo %t.o %t1 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
+# RUN: not llvm-objcopy -R .foo %t.o %t1 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR1 -DINPUT=%t.o
 # RUN: cp %t.o %t2
-# RUN: not llvm-strip --no-strip-all -R .foo %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
+# RUN: not llvm-strip --no-strip-all -R .foo %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR2 -DINPUT=%t2
 
 --- !ELF
 FileHeader:
@@ -16,7 +16,8 @@
     Type:            SHT_PROGBITS
     Link:            .foo
 
-# ERR: section '.foo' cannot be removed because it is referenced by the section '.bar'
+# ERR1: error: '[[INPUT]]': section '.foo' cannot be removed because it is referenced by the section '.bar'
+# ERR2: error: '[[INPUT]]': section '.foo' cannot be removed because it is referenced by the section '.bar'
 
 # RUN: llvm-objcopy --allow-broken-links -R .foo %t.o %t3
 # RUN: llvm-readobj --sections %t3 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.foo
diff --git a/llvm/test/tools/llvm-objcopy/ELF/remove-shstrtab-error.test b/llvm/test/tools/llvm-objcopy/ELF/remove-shstrtab-error.test
index 4b7bc0e..797681f 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/remove-shstrtab-error.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/remove-shstrtab-error.test
@@ -1,5 +1,5 @@
 # RUN: yaml2obj %s > %t
-# RUN: not llvm-objcopy -R .shstrtab %t %t2 2>&1 >/dev/null | FileCheck %s
+# RUN: not llvm-objcopy -R .shstrtab %t %t2 2>&1 >/dev/null | FileCheck %s -DINPUT=%t
 
 !ELF
 FileHeader:
@@ -8,4 +8,4 @@
   Type:            ET_REL
   Machine:         EM_X86_64
 
-# CHECK: cannot write section header table because section header string table was removed
+# CHECK: error: '[[INPUT]]': cannot write section header table because section header string table was removed
diff --git a/llvm/test/tools/llvm-objcopy/ELF/strip-section-err.test b/llvm/test/tools/llvm-objcopy/ELF/strip-section-err.test
index b0ee757..8f0a809 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/strip-section-err.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/strip-section-err.test
@@ -2,8 +2,8 @@
 ## referenced by relocations contained in the object.
 
 # RUN: yaml2obj %s > %t1
-# RUN: not llvm-objcopy -R .data %t1 2>&1 | FileCheck %s
-# CHECK: error: section '.data' cannot be removed: (.text+0x1) has relocation against symbol 'foo'
+# RUN: not llvm-objcopy -R .data %t1 2>&1 | FileCheck %s -DINPUT=%t1
+# CHECK: error: '[[INPUT]]': section '.data' cannot be removed: (.text+0x1) has relocation against symbol 'foo'
 
 ## Check the behavior when we also remove the relocation section.
 ## We have no reference in this case and hence no error should be emitted.
diff --git a/llvm/test/tools/llvm-objcopy/ELF/strip-symbol-and-relocation.test b/llvm/test/tools/llvm-objcopy/ELF/strip-symbol-and-relocation.test
index 007acfb..76833c0 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/strip-symbol-and-relocation.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/strip-symbol-and-relocation.test
@@ -20,8 +20,8 @@
 # STRIPSYM-NOT: bar
 # STRIPSYM-NOT: .rela.text
 
-# RUN: not llvm-objcopy --strip-symbol=bar %t %t2 2>&1 | FileCheck %s --check-prefix=ERR
-# ERR: not stripping symbol 'bar' because it is named in a relocation
+# RUN: not llvm-objcopy --strip-symbol=bar %t %t2 2>&1 | FileCheck %s --check-prefix=ERR -DINPUT=%t
+# ERR: error: '[[INPUT]]': not stripping symbol 'bar' because it is named in a relocation
 
 --- !ELF
 FileHeader:
diff --git a/llvm/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test b/llvm/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test
index cb4cc26..7c9a460 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/symtab-error-on-remove-strtab.test
@@ -1,7 +1,7 @@
 # RUN: yaml2obj %s > %t
-# RUN: not llvm-objcopy -R .strtab %t %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
+# RUN: not llvm-objcopy -R .strtab %t %t2 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR1 -DINPUT=%t
 # RUN: cp %t %t3
-# RUN: not llvm-strip --no-strip-all -R .strtab %t3 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR
+# RUN: not llvm-strip --no-strip-all -R .strtab %t3 2>&1 >/dev/null | FileCheck %s --check-prefix=ERR2 -DINPUT=%t3
 
 !ELF
 FileHeader:
@@ -10,7 +10,8 @@
   Type:            ET_REL
   Machine:         EM_X86_64
 
-# ERR: string table '.strtab' cannot be removed because it is referenced by the symbol table '.symtab'
+# ERR1: error: '[[INPUT]]': string table '.strtab' cannot be removed because it is referenced by the symbol table '.symtab'
+# ERR2: error: '[[INPUT]]': string table '.strtab' cannot be removed because it is referenced by the symbol table '.symtab'
 
 # RUN: llvm-objcopy --allow-broken-links -R .strtab %t %t4
 # RUN: llvm-objdump --section-headers %t4 | FileCheck %s --check-prefix=SECTIONS --implicit-check-not=.strtab