Debian Codegraph @

llvm/test/tools/llvm-objcopy/ELF/pad-to.test

raw
1 # RUN: yaml2obj %s -o %t
2
3 # RUN: not llvm-objcopy --pad-to=1 %t 2>&1 | FileCheck %s --check-prefix=NOT-BINARY
4 # NOT-BINARY: error: '--pad-to' is only supported for binary output
5
6 # RUN: not llvm-objcopy -O binary --pad-to= %t 2>&1 | FileCheck %s --check-prefix=BAD-FORMAT
7 # BAD-FORMAT: error: --pad-to: bad number:
8
9 # RUN: not llvm-objcopy -O binary --pad-to=x %t 2>&1 | FileCheck %s --check-prefix=BAD-INPUT
10 # BAD-INPUT: error: --pad-to: bad number: x
11
12 # RUN: not llvm-objcopy -O binary --pad-to=0x1G %t 2>&1 | FileCheck %s --check-prefix=BAD-INPUT2
13 # BAD-INPUT2: error: --pad-to: bad number: 0x1G
14
15 # RUN: not llvm-objcopy -O binary --pad-to=ff %t 2>&1 | FileCheck %s --check-prefix=BAD-INPUT3
16 # BAD-INPUT3: error: --pad-to: bad number: ff
17
18 # RUN: not llvm-objcopy -O binary --pad-to=0x112233445566778899 %t 2>&1 | FileCheck %s --check-prefix=BAD-NUMBER
19 # BAD-NUMBER: error: --pad-to: bad number: 0x112233445566778899
20
21 ## Save the baseline, not padded output.
22 # RUN: llvm-objcopy -O binary %t %t.bin
23
24 ## Pad to an address smaller than the binary size.
25 # RUN: llvm-objcopy -O binary --pad-to=0x20 %t %t-p1
26 # RUN: cmp %t.bin %t-p1
27 # RUN: llvm-objcopy -O binary --pad-to=0x200 %t %t-p2
28 # RUN: cmp %t.bin %t-p2
29
30 ## Pad all allocatable sections to a valid address.
31 # RUN: llvm-objcopy -O binary --pad-to=0x218 %t %t-pad-default
32 # RUN: od -v -Ax -t x1 %t-pad-default | FileCheck %s --check-prefix=DEFAULT --ignore-case --match-full-lines
33 # DEFAULT: {{0*}}00 11 22 33 44 55 66 00 00 00 00 00 00 00 00 00 00
34 # DEFAULT-NEXT: {{0*}}10 77 88 99 aa 00 00 00 00
35 # DEFAULT-NEXT: {{0*}}18
36
37 ## Use a decimal number for the padding address and verify it is not misunderstood.
38 # RUN: llvm-objcopy -O binary --pad-to=536 %t %t-pad-decimal
39 # RUN: od -v -Ax -t x1 %t-pad-decimal | FileCheck %s --check-prefix=DECIMAL --ignore-case --match-full-lines
40 # DECIMAL: {{0*}}00 11 22 33 44 55 66 00 00 00 00 00 00 00 00 00 00
41 # DECIMAL-NEXT: {{0*}}10 77 88 99 aa 00 00 00 00
42 # DECIMAL-NEXT: {{0*}}18
43
44 ## Pad all allocatable sections to a valid address, using --gap-fill.
45 # RUN: llvm-objcopy -O binary --pad-to=0x218 --gap-fill=0xe9 %t %t-pad-fill
46 # RUN: od -v -Ax -t x1 %t-pad-fill | FileCheck %s --check-prefix=FILL --ignore-case --match-full-lines
47 # FILL: {{0*}}00 11 22 33 44 55 66 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9
48 # FILL-NEXT: {{0*}}10 77 88 99 aa e9 e9 e9 e9
49 # FILL-NEXT: {{0*}}18
50
51 ## Remove the last section containing data and test that the padded space is gap filled.
52 # RUN: llvm-objcopy -O binary --pad-to=0x218 --gap-fill=0xe9 --remove-section=.section2 %t %t-filled
53 # RUN: od -v -Ax -t x1 %t-filled | FileCheck %s --check-prefix=REMOVE-SECTION --ignore-case --match-full-lines
54 # REMOVE-SECTION: {{0*}}00 11 22 33 44 55 66 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9
55 # REMOVE-SECTION-NEXT: {{0*}}10 e9 e9 e9 e9 e9 e9 e9 e9
56 # REMOVE-SECTION-NEXT: {{0*}}18
57
58 --- !ELF
59 FileHeader:
60 Class: ELFCLASS64
61 Data: ELFDATA2LSB
62 Type: ET_EXEC
63 Machine: EM_X86_64
64 Sections:
65 - Name: .section1
66 Type: SHT_PROGBITS
67 Flags: [ SHF_ALLOC ]
68 Address: 0x0200
69 Size: 0x6
70 Content: '112233445566'
71 - Name: .space
72 Type: Fill
73 Pattern: '01234567'
74 Size: 0x4
75 - Name: .section2
76 Type: SHT_PROGBITS
77 Flags: [ SHF_WRITE, SHF_ALLOC ]
78 Address: 0x0210
79 Content: '778899aa'
80 - Name: .bss
81 Type: SHT_NOBITS
82 Flags: [ SHF_WRITE, SHF_ALLOC ]
83 Address: 0x0220
84 Size: 0x0008
85 - Name: .comment
86 Type: SHT_PROGBITS
87 Flags: [ SHF_MERGE, SHF_STRINGS ]
88 EntSize: 0x0001
89 Content: ''
90 ...