Index: test/tools/llvm-objcopy/ELF/ihex-reader.test =================================================================== --- test/tools/llvm-objcopy/ELF/ihex-reader.test +++ test/tools/llvm-objcopy/ELF/ihex-reader.test @@ -1,81 +1,8 @@ -# Check section headers when converting from hex to ELF +## Check section headers when converting from hex to ELF. # RUN: yaml2obj %p/Inputs/ihex-elf-sections.yaml -o %t # RUN: llvm-objcopy -O ihex %t %t.hex # RUN: llvm-objcopy -I ihex -O elf32-i386 %t.hex %t2 -# RUN: llvm-readobj -section-headers %t2 | FileCheck %s - -# Check section contents -# RUN: llvm-objcopy -O binary --only-section=.text %t %t.text -# RUN: llvm-objcopy -O binary --only-section=.sec1 %t2 %t2.sec1 -# RUN: cmp %t.text %t2.sec1 -# RUN: llvm-objcopy -O binary --only-section=.data %t %t.data -# RUN: llvm-objcopy -O binary --only-section=.sec2 %t2 %t2.sec2 -# RUN: cmp %t.data %t2.sec2 -# RUN: llvm-objcopy -O binary --only-section=.data2 %t %t.data2 -# RUN: llvm-objcopy -O binary --only-section=.sec3 %t2 %t2.sec3 -# RUN: cmp %t.data2 %t2.sec3 -# RUN: llvm-objcopy -O binary --only-section=.data3 %t %t.data3 -# RUN: llvm-objcopy -O binary --only-section=.sec4 %t2 %t2.sec4 -# RUN: cmp %t.data3 %t2.sec4 - -# Check loading from raw hex file -# RUN: llvm-objcopy -I ihex -O elf32-i386 %p/Inputs/sections.hex %t-raw -# RUN: llvm-readobj -section-headers %t-raw | FileCheck %s --check-prefix=RAW - -# Check section contents -# RUN: llvm-objcopy -O ihex --only-section=.sec1 %t-raw - | FileCheck %s --check-prefix=RAW-SEC1 -# RUN: llvm-objcopy -O ihex --only-section=.sec2 %t-raw - | FileCheck %s --check-prefix=RAW-SEC2 -# RUN: llvm-objcopy -O ihex --only-section=.sec3 %t-raw - | FileCheck %s --check-prefix=RAW-SEC3 - -# Check that line is trimmed from whitespace -# RUN: echo " :0100000001FE " | llvm-objcopy -I ihex -O elf64-x86-64 - - \ -# RUN: | llvm-objcopy -O ihex - - | FileCheck %s --check-prefix=SPACES - -# Check for various parsing errors -# 1. String too short -# RUN: echo "01000000FF" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_LENGTH - -# 2. missing ':' -# RUN: echo "0100000000FF" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=MISSING_COLON - -# 3. invalid charatcer -# RUN: echo ":01000000xF" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_CHAR - -# 4. incorrect string length -# RUN: echo ":010000000000000F" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_LENGTH2 - -# 5. invalid type (06) -# RUN: echo ":00000006FA" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_TYPE - -# 6. invalid checksum -# RUN: echo ":00000001FA" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_CKSUM - -# 7. zero data length -# RUN: echo ":00010000FF" | not llvm-objcopy -I ihex - - 2>&1 | FileCheck %s --check-prefix=ZERO_DATA_LEN - -# 8. Bad data length for '02' (SegmentAddr) record -# RUN: echo ":03000002000000FB" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_SEGADDR_LEN - -# 9. Bad data length for '03' (StartAddr80x86) record -# RUN: echo ":03000003000000FA" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_STARTADDR_LEN - -# 10. Bad data length for '05' (StartAddr) record -# RUN: echo ":03000005000000F8" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_STARTADDR_LEN - -# 11. Address value for 'StartAddr80x86' is greater then 0xFFFFFU -# RUN: echo ":04000003FFFFFFFFFD" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_STARTADDR - -# 12. Invalid extended address data size -# RUN: echo ":04000004FFFFFFFFFC" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_EXTADDR_LEN - -# 13. no sections in the hex file -# a) try empty file: -# RUN: echo "" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=NO_SECTIONS -# b) EOF record should cancel processing further records. Not having any section data -# before EOF should trigger an error -# RUN: echo ":00000001FF" > %t-bad14.hex -# RUN: echo ":0100000001FE" >> %t-bad14.hex -# RUN: not llvm-objcopy -I ihex %t-bad14.hex %t-none 2>&1 | FileCheck %s --check-prefix=NO_SECTIONS +# RUN: llvm-readobj --section-headers %t2 | FileCheck %s # CHECK: Index: 1 # CHECK-NEXT: Name: .sec1 @@ -137,6 +64,24 @@ # CHECK-NEXT: AddressAlignment: 1 # CHECK-NEXT: EntrySize: 0 +## Check section contents. +# RUN: llvm-objcopy -O binary --only-section=.text %t %t.text +# RUN: llvm-objcopy -O binary --only-section=.sec1 %t2 %t2.sec1 +# RUN: cmp %t.text %t2.sec1 +# RUN: llvm-objcopy -O binary --only-section=.data %t %t.data +# RUN: llvm-objcopy -O binary --only-section=.sec2 %t2 %t2.sec2 +# RUN: cmp %t.data %t2.sec2 +# RUN: llvm-objcopy -O binary --only-section=.data2 %t %t.data2 +# RUN: llvm-objcopy -O binary --only-section=.sec3 %t2 %t2.sec3 +# RUN: cmp %t.data2 %t2.sec3 +# RUN: llvm-objcopy -O binary --only-section=.data3 %t %t.data3 +# RUN: llvm-objcopy -O binary --only-section=.sec4 %t2 %t2.sec4 +# RUN: cmp %t.data3 %t2.sec4 + +## Check loading from raw hex file. +# RUN: llvm-objcopy -I ihex -O elf32-i386 %p/Inputs/sections.hex %t-raw +# RUN: llvm-readobj --section-headers %t-raw | FileCheck %s --check-prefix=RAW + # RAW: Index: 1 # RAW-NEXT: Name: .sec1 # RAW-NEXT: Type: SHT_PROGBITS (0x1) @@ -170,34 +115,102 @@ # RAW-NEXT: Offset: 0x4A # RAW-NEXT: Size: 11 +## Check section contents. +# RUN: llvm-objcopy -O ihex --only-section=.sec1 %t-raw - | FileCheck %s --check-prefix=RAW-SEC1 + # RAW-SEC1: :020000021000EC # RAW-SEC1-NEXT: :08FFF8000001020304050607E5 # RAW-SEC1-NEXT: :020000022000DC # RAW-SEC1-NEXT: :0300000008090AE2 +# RUN: llvm-objcopy -O ihex --only-section=.sec2 %t-raw - | FileCheck %s --check-prefix=RAW-SEC2 + # RAW-SEC2: :02000002F0000C # RAW-SEC2-NEXT: :08FFF800303132333435363765 # RAW-SEC2-NEXT: :020000020000FC # RAW-SEC2-NEXT: :020000040010EA # RAW-SEC2-NEXT: :030000003839404C +# RUN: llvm-objcopy -O ihex --only-section=.sec3 %t-raw - | FileCheck %s --check-prefix=RAW-SEC3 + # RAW-SEC3: :02000004001FDB # RAW-SEC3-NEXT: :08FFF8004041424344454647E5 # RAW-SEC3-NEXT: :020000040020DA # RAW-SEC3-NEXT: :030000004849501C +## Check that line is trimmed from whitespace. +# RUN: echo " :0100000001FE " | llvm-objcopy -I ihex -O elf64-x86-64 - - \ +# RUN: | llvm-objcopy -O ihex - - | FileCheck %s --check-prefix=SPACES + # SPACES: :0100000001FE # SPACES-NEXT: :00000001FF +## Check for various parsing errors. +# 1. String too short +# RUN: echo "01000000FF" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_LENGTH + # BAD_LENGTH: error: '{{.*}}': line 1: line is too short: 10 chars + +## 2. missing ':'. +# RUN: echo "0100000000FF" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=MISSING_COLON + # MISSING_COLON: error: '{{.*}}': line 1: missing ':' in the beginning of line + +## 3. invalid charatcer. +# RUN: echo ":01000000xF" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_CHAR + # BAD_CHAR: error: '{{.*}}': line 1: invalid character at position 10 + +## 4. incorrect string length. +# RUN: echo ":010000000000000F" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_LENGTH2 + # BAD_LENGTH2: error: '{{.*}}': line 1: invalid line length 17 (should be 13) + +## 5. invalid type (06). +# RUN: echo ":00000006FA" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_TYPE + # BAD_TYPE: error: '{{.*}}': line 1: unknown record type: 6 + +## 6. invalid checksum. +# RUN: echo ":00000001FA" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_CKSUM + # BAD_CKSUM: error: '{{.*}}': line 1: incorrect checksum + +## 7. zero data length. +# RUN: echo ":00010000FF" | not llvm-objcopy -I ihex - - 2>&1 | FileCheck %s --check-prefix=ZERO_DATA_LEN + # ZERO_DATA_LEN: error: '{{.*}}': line 1: zero data length is not allowed for data records + +## 8. Bad data length for '02' (SegmentAddr) record. +# RUN: echo ":03000002000000FB" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_SEGADDR_LEN + # BAD_SEGADDR_LEN: error: '{{.*}}': line 1: segment address data should be 2 bytes in size + +## 9. Bad data length for '03' (StartAddr80x86) record. +# RUN: echo ":03000003000000FA" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_STARTADDR_LEN + +## 10. Bad data length for '05' (StartAddr) record. +# RUN: echo ":03000005000000F8" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_STARTADDR_LEN + # BAD_STARTADDR_LEN: error: '{{.*}}': line 1: start address data should be 4 bytes in size + +## 11. Address value for 'StartAddr80x86' is greater then 0xFFFFFU. +# RUN: echo ":04000003FFFFFFFFFD" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_STARTADDR + # BAD_STARTADDR: error: '{{.*}}': line 1: start address exceeds 20 bit for 80x86 + +## 12. Invalid extended address data size. +# RUN: echo ":04000004FFFFFFFFFC" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_EXTADDR_LEN + # BAD_EXTADDR_LEN: error: '{{.*}}': line 1: extended address data should be 2 bytes in size + +## 13. no sections in the hex file. +# a) try empty file: +# RUN: echo "" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=NO_SECTIONS +# b) EOF record should cancel processing further records. Not having any section data +# before EOF should trigger an error +# RUN: echo ":00000001FF" > %t-bad14.hex +# RUN: echo ":0100000001FE" >> %t-bad14.hex +# RUN: not llvm-objcopy -I ihex %t-bad14.hex %t-none 2>&1 | FileCheck %s --check-prefix=NO_SECTIONS + # NO_SECTIONS: error: '{{.*}}': no sections