summaryrefslogtreecommitdiffstats
path: root/llvm/test/tools/llvm-objcopy/ELF/invalid-e_shoff.test
diff options
context:
space:
mode:
authorJames Henderson <jh7370@my.bristol.ac.uk>2019-05-10 12:58:52 +0000
committerJames Henderson <jh7370@my.bristol.ac.uk>2019-05-10 12:58:52 +0000
commit5772e02bd0f1a815bd49ad0344394b24be10847e (patch)
tree3ad3de3f5615376e64cc9a2847cb8a44f160aa78 /llvm/test/tools/llvm-objcopy/ELF/invalid-e_shoff.test
parent6c1e3f94938f29ff4bbc447c489fe951a4529042 (diff)
downloadbcm5719-llvm-5772e02bd0f1a815bd49ad0344394b24be10847e.tar.gz
bcm5719-llvm-5772e02bd0f1a815bd49ad0344394b24be10847e.zip
[llvm-objcopy] Add additional testing for various cases
This patch adds a number of tests to test various cases not covered by existing tests. All of them work correctly, with no need to change llvm-objcopy itself, although some do indicate possible areas for improvement. Reviewed by: MaskRay Differential Revision: https://reviews.llvm.org/D61727 llvm-svn: 360422
Diffstat (limited to 'llvm/test/tools/llvm-objcopy/ELF/invalid-e_shoff.test')
-rw-r--r--llvm/test/tools/llvm-objcopy/ELF/invalid-e_shoff.test30
1 files changed, 30 insertions, 0 deletions
diff --git a/llvm/test/tools/llvm-objcopy/ELF/invalid-e_shoff.test b/llvm/test/tools/llvm-objcopy/ELF/invalid-e_shoff.test
new file mode 100644
index 00000000000..7eecde6b0ab
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/ELF/invalid-e_shoff.test
@@ -0,0 +1,30 @@
+## If the e_shoff field is set to a value either past the end of the file, or
+## such that e_shoff + e_shnum * sizeof(Elf_Shdr) is past the end of the file,
+## we should emit an error. This test checks that the emitted error is sensible.
+
+# RUN: yaml2obj %s -o %t.o
+# RUN: cp %t.o %t2.o
+
+## Sanity check that the section header table is at offset 64:
+# RUN: llvm-readobj --file-headers %t.o | FileCheck %s --check-prefix=VALIDATE
+# VALIDATE: SectionHeaderOffset: 0x40{{$}}
+
+## Truncate the file to end before the section header table ends.
+# RUN: %python -c "with open('%/t.o', 'r+b') as input: input.truncate(65)"
+# RUN: not llvm-objcopy %t.o 2>&1 | FileCheck %s -DINPUT=%t.o
+
+## Set the e_shoff field to a value much larger than the object file size.
+# RUN: %python -c "with open('%/t2.o', 'r+b') as input: import struct; bytes = struct.pack('<Q', 0x40000000); input.seek(40); input.write(bytes)"
+# RUN: not llvm-objcopy %t2.o 2>&1 | FileCheck %s -DINPUT=%t2.o
+
+--- !ELF
+FileHeader:
+ Class: ELFCLASS64
+ Data: ELFDATA2LSB
+ Type: ET_EXEC
+ Machine: EM_X86_64
+Sections:
+ - Name: .foo
+ Type: SHT_PROGBITS
+
+# CHECK: error: '[[INPUT]]': section header table goes past the end of the file
OpenPOWER on IntegriCloud