|
| 1 | +# RUN: yaml2obj --docnum=1 %s -o %t |
| 2 | + |
| 3 | +# RUN: not llvm-objcopy --gap-fill 1 %t 2>&1 | FileCheck %s --check-prefix=NOT-BINARY |
| 4 | +# NOT-BINARY: error: '--gap-fill' is only supported for binary output |
| 5 | + |
| 6 | +# RUN: not llvm-objcopy -O binary --gap-fill= %t %t.bin 2>&1 | FileCheck %s --check-prefix=BAD-FORMAT |
| 7 | +# BAD-FORMAT: error: --gap-fill: bad number: |
| 8 | + |
| 9 | +# RUN: not llvm-objcopy -O binary --gap-fill=x %t %t.bin 2>&1 | FileCheck %s --check-prefix=BAD-INPUT |
| 10 | +# BAD-INPUT: error: --gap-fill: bad number: x |
| 11 | + |
| 12 | +# RUN: not llvm-objcopy -O binary --gap-fill=0x %t %t.bin 2>&1 | FileCheck %s --check-prefix=BAD-INPUT2 |
| 13 | +# BAD-INPUT2: error: --gap-fill: bad number: 0x |
| 14 | + |
| 15 | +# RUN: not llvm-objcopy -O binary --gap-fill=0x1G %t %t.bin 2>&1 | FileCheck %s --check-prefix=BAD-INPUT3 |
| 16 | +# BAD-INPUT3: error: --gap-fill: bad number: 0x1G |
| 17 | + |
| 18 | +# RUN: not llvm-objcopy -O binary --gap-fill=ff %t %t.bin 2>&1 | FileCheck %s --check-prefix=BAD-INPUT4 |
| 19 | +# BAD-INPUT4: error: --gap-fill: bad number: ff |
| 20 | + |
| 21 | +# RUN: not llvm-objcopy -O binary --gap-fill=0x1122 %t %t-val16 2>&1 | FileCheck %s --check-prefix=TRUNCATED-ERR |
| 22 | +# TRUNCATED-ERR: error: gap-fill value 0x1122 is out of range (0 to 0xff) |
| 23 | + |
| 24 | +## Test no gap fill with all allocatable output sections. |
| 25 | +# RUN: llvm-objcopy -O binary %t %t-default |
| 26 | +# RUN: od -v -Ax -t x1 %t-default | FileCheck %s --check-prefix=DEFAULT --match-full-lines |
| 27 | +# DEFAULT: 000000 ee ff 11 22 33 44 aa bb cc dd fe dc ba 00 a1 b2 |
| 28 | +# DEFAULT-NEXT: 000010 c3 d4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 29 | +# DEFAULT-NEXT: 000020 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 30 | +# DEFAULT-NEXT: 000030 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 31 | +# DEFAULT-NEXT: 000040 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 32 | +# DEFAULT-NEXT: 000050 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 33 | +# DEFAULT-NEXT: 000060 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 34 | +# DEFAULT-NEXT: 000070 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |
| 35 | +# DEFAULT-NEXT: 000080 00 00 89 ab cd ef |
| 36 | +# DEFAULT-NEXT: 000086 |
| 37 | + |
| 38 | +## Test gap fill with all allocatable output sections. |
| 39 | +# RUN: llvm-objcopy -O binary --gap-fill=0xe9 %t %t-filled |
| 40 | +# RUN: od -v -Ax -t x1 %t-filled | FileCheck %s --check-prefix=FULL --match-full-lines |
| 41 | +# FULL: 000000 ee ff 11 22 33 44 aa bb cc dd fe dc ba e9 a1 b2 |
| 42 | +# FULL-NEXT: 000010 c3 d4 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 |
| 43 | +# FULL-NEXT: 000020 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 |
| 44 | +# FULL-NEXT: 000030 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 |
| 45 | +# FULL-NEXT: 000040 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 |
| 46 | +# FULL-NEXT: 000050 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 |
| 47 | +# FULL-NEXT: 000060 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 |
| 48 | +# FULL-NEXT: 000070 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 |
| 49 | +# FULL-NEXT: 000080 e9 e9 89 ab cd ef |
| 50 | +# FULL-NEXT: 000086 |
| 51 | + |
| 52 | +## Test gap fill with a decimal value. |
| 53 | +# RUN: llvm-objcopy -O binary --gap-fill=99 %t %t-filled-decimal |
| 54 | +# RUN: od -v -Ax -t x1 %t-filled-decimal | FileCheck %s --check-prefix=DEC --match-full-lines |
| 55 | +# DEC: 000000 ee ff 11 22 33 44 aa bb cc dd fe dc ba 63 a1 b2 |
| 56 | +# DEC-NEXT: 000010 c3 d4 63 63 63 63 63 63 63 63 63 63 63 63 63 63 |
| 57 | +# DEC-NEXT: 000020 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 |
| 58 | +# DEC-NEXT: 000030 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 |
| 59 | +# DEC-NEXT: 000040 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 |
| 60 | +# DEC-NEXT: 000050 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 |
| 61 | +# DEC-NEXT: 000060 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 |
| 62 | +# DEC-NEXT: 000070 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 |
| 63 | +# DEC-NEXT: 000080 63 63 89 ab cd ef |
| 64 | +# DEC-NEXT: 000086 |
| 65 | + |
| 66 | +## Test gap fill with the last section removed, should be truncated. |
| 67 | +# RUN: llvm-objcopy -O binary --gap-fill=0xe9 --remove-section=.foo %t %t-filled |
| 68 | +# RUN: od -v -Ax -t x1 %t-filled | FileCheck %s --check-prefix=REMOVE-LAST-SECTION --match-full-lines |
| 69 | +# REMOVE-LAST-SECTION: 000000 ee ff 11 22 33 44 aa bb cc dd fe dc ba e9 a1 b2 |
| 70 | +# REMOVE-LAST-SECTION-NEXT: 000010 c3 d4 |
| 71 | +# REMOVE-LAST-SECTION-NEXT: 000012 |
| 72 | + |
| 73 | +## Test gap fill with the middle section removed, should be filled. |
| 74 | +# RUN: llvm-objcopy -O binary --gap-fill=0xe9 --remove-section=.gap2 %t %t-filled |
| 75 | +# RUN: od -v -Ax -t x1 %t-filled | FileCheck %s --check-prefix=REMOVE-MIDDLE-SECTION --match-full-lines |
| 76 | +# REMOVE-MIDDLE-SECTION: 000000 ee ff 11 22 33 44 aa bb cc dd fe dc ba e9 e9 e9 |
| 77 | +# REMOVE-MIDDLE-SECTION-NEXT: 000010 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 |
| 78 | +# REMOVE-MIDDLE-SECTION-NEXT: 000020 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 |
| 79 | +# REMOVE-MIDDLE-SECTION-NEXT: 000030 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 |
| 80 | +# REMOVE-MIDDLE-SECTION-NEXT: 000040 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 |
| 81 | +# REMOVE-MIDDLE-SECTION-NEXT: 000050 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 |
| 82 | +# REMOVE-MIDDLE-SECTION-NEXT: 000060 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 |
| 83 | +# REMOVE-MIDDLE-SECTION-NEXT: 000070 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 |
| 84 | +# REMOVE-MIDDLE-SECTION-NEXT: 000080 e9 e9 89 ab cd ef |
| 85 | +# REMOVE-MIDDLE-SECTION-NEXT: 000086 |
| 86 | + |
| 87 | +--- !ELF |
| 88 | +FileHeader: |
| 89 | + Class: ELFCLASS64 |
| 90 | + Data: ELFDATA2LSB |
| 91 | + Type: ET_EXEC |
| 92 | + Machine: EM_X86_64 |
| 93 | +Sections: |
| 94 | + - Name: .space1 |
| 95 | + Type: Fill |
| 96 | + Pattern: 'ABCD' |
| 97 | + Size: 0x2 |
| 98 | + - Name: .nogap |
| 99 | + Type: SHT_PROGBITS |
| 100 | + Flags: [ SHF_ALLOC ] |
| 101 | + Address: 0x0102 |
| 102 | + Size: 0x6 |
| 103 | + Content: 'EEFF11223344' |
| 104 | + - Name: .gap1 |
| 105 | + Type: SHT_PROGBITS |
| 106 | + Flags: [ SHF_ALLOC, SHF_EXECINSTR ] |
| 107 | + Address: 0x0108 |
| 108 | + Content: 'AABBCCDDFEDCBA' |
| 109 | + - Name: .space2 |
| 110 | + Type: Fill |
| 111 | + Pattern: 'DC' |
| 112 | + Size: 1 |
| 113 | + - Name: .gap2 |
| 114 | + Type: SHT_PROGBITS |
| 115 | + Flags: [ SHF_ALLOC ] |
| 116 | + Address: 0x0110 |
| 117 | + Content: 'A1B2C3D4' |
| 118 | + - Name: .space3 |
| 119 | + Type: Fill |
| 120 | + Pattern: 'FE' |
| 121 | + Size: 0x1 |
| 122 | + - Name: .nobit_tbss |
| 123 | + Type: SHT_NOBITS |
| 124 | + Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ] |
| 125 | + Address: 0x0180 |
| 126 | + Size: 0x0018 |
| 127 | + - Name: .space4 |
| 128 | + Type: Fill |
| 129 | + Pattern: '01234567' |
| 130 | + Size: 0x4 |
| 131 | + - Name: .foo |
| 132 | + Type: SHT_PROGBITS |
| 133 | + Flags: [ SHF_WRITE, SHF_ALLOC ] |
| 134 | + Address: 0x0184 |
| 135 | + Content: '89ABCDEF' |
| 136 | + - Name: .nobit_bss |
| 137 | + Type: SHT_NOBITS |
| 138 | + Flags: [ SHF_WRITE, SHF_ALLOC ] |
| 139 | + Address: 0x018A |
| 140 | + Size: 0x0008 |
| 141 | + - Name: .comment |
| 142 | + Type: SHT_PROGBITS |
| 143 | + Flags: [ SHF_MERGE, SHF_STRINGS ] |
| 144 | + EntSize: 0x0001 |
| 145 | + Content: 4743433A |
| 146 | + |
| 147 | +## In this test, output sections are defined out of order with respect to their |
| 148 | +## load addresses. Verify that gaps are still correctly filled. |
| 149 | + |
| 150 | +# RUN: yaml2obj --docnum=2 %s -o %t.2 |
| 151 | +# RUN: llvm-objcopy -O binary --gap-fill=0xe9 %t.2 %t.2.filled |
| 152 | +# RUN: od -v -Ax -t x1 %t.2.filled | FileCheck --match-full-lines %s |
| 153 | +# CHECK: 000000 aa bb cc dd e9 e9 e9 e9 11 22 33 44 |
| 154 | + |
| 155 | +--- !ELF |
| 156 | +FileHeader: |
| 157 | + Class: ELFCLASS64 |
| 158 | + Data: ELFDATA2LSB |
| 159 | + Type: ET_EXEC |
| 160 | + Machine: EM_X86_64 |
| 161 | +Sections: |
| 162 | + - Name: .bss |
| 163 | + Type: SHT_NOBITS |
| 164 | + Flags: [ SHF_ALLOC, SHF_WRITE ] |
| 165 | + Address: 0x0104 |
| 166 | + Size: 4 |
| 167 | + - Name: .section1 |
| 168 | + Type: SHT_PROGBITS |
| 169 | + Flags: [ SHF_ALLOC, SHF_WRITE ] |
| 170 | + Address: 0x0108 |
| 171 | + Content: '11223344' |
| 172 | + - Name: .section3 |
| 173 | + Type: SHT_PROGBITS |
| 174 | + Flags: [ SHF_ALLOC, SHF_WRITE ] |
| 175 | + Address: 0x0100 |
| 176 | + Content: 'AABBCCDD' |
0 commit comments