1 ## Check section headers when converting from hex to ELF.
2 # RUN: yaml2obj %p/Inputs/ihex-elf-sections.yaml -o %t
3 # RUN: llvm-objcopy -O ihex %t %t.hex
4 # RUN: llvm-objcopy -I ihex -O elf32-i386 %t.hex %t2
5 # RUN: llvm-readobj --section-headers %t2 | FileCheck %s
8 # CHECK-NEXT: Type: SHT_PROGBITS (0x1)
9 # CHECK-NEXT: Flags [ (0x3)
10 # CHECK-NEXT: SHF_ALLOC (0x2)
11 # CHECK-NEXT: SHF_WRITE (0x1)
13 # CHECK-NEXT: Address: 0x0
15 # CHECK-NEXT: Size: 21
18 # CHECK-NEXT: AddressAlignment: 1
19 # CHECK-NEXT: EntrySize: 0
22 # CHECK-NEXT: Type: SHT_PROGBITS (0x1)
23 # CHECK-NEXT: Flags [ (0x3)
24 # CHECK-NEXT: SHF_ALLOC (0x2)
25 # CHECK-NEXT: SHF_WRITE (0x1)
27 # CHECK-NEXT: Address: 0xFFF8
29 # CHECK-NEXT: Size: 11
32 # CHECK-NEXT: AddressAlignment: 1
33 # CHECK-NEXT: EntrySize: 0
36 # CHECK-NEXT: Type: SHT_PROGBITS (0x1)
37 # CHECK-NEXT: Flags [ (0x3)
38 # CHECK-NEXT: SHF_ALLOC (0x2)
39 # CHECK-NEXT: SHF_WRITE (0x1)
41 # CHECK-NEXT: Address: 0x10100
46 # CHECK-NEXT: AddressAlignment: 1
47 # CHECK-NEXT: EntrySize: 0
50 # CHECK-NEXT: Type: SHT_PROGBITS (0x1)
51 # CHECK-NEXT: Flags [ (0x3)
52 # CHECK-NEXT: SHF_ALLOC (0x2)
53 # CHECK-NEXT: SHF_WRITE (0x1)
55 # CHECK-NEXT: Address: 0x10FFF8
57 # CHECK-NEXT: Size: 11
60 # CHECK-NEXT: AddressAlignment: 1
61 # CHECK-NEXT: EntrySize: 0
63 ## Check section contents.
64 # RUN: llvm-objcopy -O binary --only-section=.text %t %t.text
65 # RUN: llvm-objcopy -O binary --only-section=.sec1 %t2 %t2.sec1
66 # RUN: cmp %t.text %t2.sec1
67 # RUN: llvm-objcopy -O binary --only-section=.data %t %t.data
68 # RUN: llvm-objcopy -O binary --only-section=.sec2 %t2 %t2.sec2
69 # RUN: cmp %t.data %t2.sec2
70 # RUN: llvm-objcopy -O binary --only-section=.data2 %t %t.data2
71 # RUN: llvm-objcopy -O binary --only-section=.sec3 %t2 %t2.sec3
72 # RUN: cmp %t.data2 %t2.sec3
73 # RUN: llvm-objcopy -O binary --only-section=.data3 %t %t.data3
74 # RUN: llvm-objcopy -O binary --only-section=.sec4 %t2 %t2.sec4
75 # RUN: cmp %t.data3 %t2.sec4
77 ## Check loading from raw hex file.
78 # RUN: llvm-objcopy -I ihex -O elf32-i386 %p/Inputs/sections.hex %t-raw
79 # RUN: llvm-readobj --section-headers %t-raw | FileCheck %s --check-prefix=RAW
82 # RAW-NEXT: Type: SHT_PROGBITS (0x1)
83 # RAW-NEXT: Flags [ (0x3)
84 # RAW-NEXT: SHF_ALLOC (0x2)
85 # RAW-NEXT: SHF_WRITE (0x1)
87 # RAW-NEXT: Address: 0x1FFF8
92 # RAW-NEXT: Type: SHT_PROGBITS (0x1)
93 # RAW-NEXT: Flags [ (0x3)
94 # RAW-NEXT: SHF_ALLOC (0x2)
95 # RAW-NEXT: SHF_WRITE (0x1)
97 # RAW-NEXT: Address: 0xFFFF8
102 # RAW-NEXT: Type: SHT_PROGBITS (0x1)
103 # RAW-NEXT: Flags [ (0x3)
104 # RAW-NEXT: SHF_ALLOC (0x2)
105 # RAW-NEXT: SHF_WRITE (0x1)
107 # RAW-NEXT: Address: 0x1FFFF8
111 ## Check section contents.
112 # RUN: llvm-objcopy -O ihex --only-section=.sec1 %t-raw - | FileCheck %s --check-prefix=RAW-SEC1
114 # RAW-SEC1: :020000021000EC
115 # RAW-SEC1-NEXT: :08FFF8000001020304050607E5
116 # RAW-SEC1-NEXT: :020000022000DC
117 # RAW-SEC1-NEXT: :0300000008090AE2
119 # RUN: llvm-objcopy -O ihex --only-section=.sec2 %t-raw - | FileCheck %s --check-prefix=RAW-SEC2
121 # RAW-SEC2: :02000002F0000C
122 # RAW-SEC2-NEXT: :08FFF800303132333435363765
123 # RAW-SEC2-NEXT: :020000020000FC
124 # RAW-SEC2-NEXT: :020000040010EA
125 # RAW-SEC2-NEXT: :030000003839404C
127 # RUN: llvm-objcopy -O ihex --only-section=.sec3 %t-raw - | FileCheck %s --check-prefix=RAW-SEC3
129 # RAW-SEC3: :02000004001FDB
130 # RAW-SEC3-NEXT: :08FFF8004041424344454647E5
131 # RAW-SEC3-NEXT: :020000040020DA
132 # RAW-SEC3-NEXT: :030000004849501C
134 ## Check that line is trimmed from whitespace.
135 # RUN: echo " :0100000001FE " | llvm-objcopy -I ihex -O elf64-x86-64 - - \
136 # RUN: | llvm-objcopy -O ihex - - | FileCheck %s --check-prefix=SPACES
138 # SPACES: :0100000001FE
139 # SPACES-NEXT: :00000001FF
141 ## Check for various parsing errors.
142 ## 1. String too short.
143 # RUN: echo "01000000FF" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_LENGTH
145 # BAD_LENGTH: error: '{{.*}}': line 1: line is too short: 10 chars
148 # RUN: echo "0100000000FF" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=MISSING_COLON
150 # MISSING_COLON: error: '{{.*}}': line 1: missing ':' in the beginning of line
152 ## 3. Invalid charatcer.
153 # RUN: echo ":01000000xF" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_CHAR
155 # BAD_CHAR: error: '{{.*}}': line 1: invalid character at position 10
157 ## 4. Incorrect string length.
158 # RUN: echo ":010000000000000F" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_LENGTH2
160 # BAD_LENGTH2: error: '{{.*}}': line 1: invalid line length 17 (should be 13)
162 ## 5. Invalid type (06).
163 # RUN: echo ":00000006FA" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_TYPE
165 # BAD_TYPE: error: '{{.*}}': line 1: unknown record type: 6
167 ## 6. Invalid checksum.
168 # RUN: echo ":00000001FA" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_CKSUM
170 # BAD_CKSUM: error: '{{.*}}': line 1: incorrect checksum
172 ## 7. Zero data length.
173 # RUN: echo ":00010000FF" | not llvm-objcopy -I ihex - - 2>&1 | FileCheck %s --check-prefix=ZERO_DATA_LEN
175 # ZERO_DATA_LEN: error: '{{.*}}': line 1: zero data length is not allowed for data records
177 ## 8. Bad data length for '02' (SegmentAddr) record.
178 # RUN: echo ":03000002000000FB" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_SEGADDR_LEN
180 # BAD_SEGADDR_LEN: error: '{{.*}}': line 1: segment address data should be 2 bytes in size
182 ## 9. Bad data length for '03' (StartAddr80x86) record.
183 # RUN: echo ":03000003000000FA" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_STARTADDR_LEN
185 ## 10. Bad data length for '05' (StartAddr) record.
186 # RUN: echo ":03000005000000F8" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_STARTADDR_LEN
188 # BAD_STARTADDR_LEN: error: '{{.*}}': line 1: start address data should be 4 bytes in size
190 ## 11. Address value for 'StartAddr80x86' is greater then 0xFFFFFU.
191 # RUN: echo ":04000003FFFFFFFFFD" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_STARTADDR
193 # BAD_STARTADDR: error: '{{.*}}': line 1: start address exceeds 20 bit for 80x86
195 ## 12. Invalid extended address data size.
196 # RUN: echo ":04000004FFFFFFFFFC" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=BAD_EXTADDR_LEN
198 # BAD_EXTADDR_LEN: error: '{{.*}}': line 1: extended address data should be 2 bytes in size
200 ## 13. No sections in the hex file.
201 ## a) try empty file:
202 # RUN: echo "" | not llvm-objcopy -I ihex -O elf32-i386 - - 2>&1 | FileCheck %s --check-prefix=NO_SECTIONS
203 ## b) EOF record should cancel processing further records. Not having any section data
204 ## before EOF should trigger an error.
205 # RUN: echo ":00000001FF" > %t-bad14.hex
206 # RUN: echo ":0100000001FE" >> %t-bad14.hex
207 # RUN: not llvm-objcopy -I ihex %t-bad14.hex %t-none 2>&1 | FileCheck %s --check-prefix=NO_SECTIONS
209 # NO_SECTIONS: error: '{{.*}}': no sections