182 lines · plain
1# RUN: yaml2obj --docnum=1 %s -o %t2 3# RUN: not llvm-objcopy --gap-fill 1 %t 2>&1 | FileCheck %s --check-prefix=NOT-BINARY4# NOT-BINARY: error: '--gap-fill' is only supported for binary output5 6# RUN: not llvm-objcopy -O binary --gap-fill= %t %t.bin 2>&1 | FileCheck %s --check-prefix=BAD-FORMAT7# 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-INPUT10# BAD-INPUT: error: --gap-fill: bad number: x11 12# RUN: not llvm-objcopy -O binary --gap-fill=0x %t %t.bin 2>&1 | FileCheck %s --check-prefix=BAD-INPUT213# BAD-INPUT2: error: --gap-fill: bad number: 0x14 15# RUN: not llvm-objcopy -O binary --gap-fill=0x1G %t %t.bin 2>&1 | FileCheck %s --check-prefix=BAD-INPUT316# BAD-INPUT3: error: --gap-fill: bad number: 0x1G17 18# RUN: not llvm-objcopy -O binary --gap-fill=ff %t %t.bin 2>&1 | FileCheck %s --check-prefix=BAD-INPUT419# BAD-INPUT4: error: --gap-fill: bad number: ff20 21# RUN: not llvm-objcopy -O binary --gap-fill=0x1122 %t %t-val16 2>&1 | FileCheck %s --check-prefix=TRUNCATED-ERR22# 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-default26# RUN: od -v -Ax -t x1 %t-default | FileCheck %s --check-prefix=DEFAULT --ignore-case --match-full-lines27# DEFAULT: {{0*}}00 ee ff 11 22 33 44 aa bb cc dd fe dc ba 00 a1 b228# DEFAULT-NEXT: {{0*}}10 c3 d4 00 00 00 00 00 00 00 00 00 00 00 00 00 0029# DEFAULT-NEXT: {{0*}}20 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0030# DEFAULT-NEXT: {{0*}}30 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0031# DEFAULT-NEXT: {{0*}}40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0032# DEFAULT-NEXT: {{0*}}50 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0033# DEFAULT-NEXT: {{0*}}60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0034# DEFAULT-NEXT: {{0*}}70 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 0035# DEFAULT-NEXT: {{0*}}80 00 00 89 ab cd ef36# DEFAULT-NEXT: {{0*}}8637 38## Test gap fill with all allocatable output sections.39# RUN: llvm-objcopy -O binary --gap-fill=0xe9 %t %t-filled40# RUN: od -v -Ax -t x1 %t-filled | FileCheck %s --check-prefix=FULL --ignore-case --match-full-lines41# FULL: {{0*}}00 ee ff 11 22 33 44 aa bb cc dd fe dc ba e9 a1 b242# FULL-NEXT: {{0*}}10 c3 d4 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e943# FULL-NEXT: {{0*}}20 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e944# FULL-NEXT: {{0*}}30 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e945# FULL-NEXT: {{0*}}40 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e946# FULL-NEXT: {{0*}}50 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e947# FULL-NEXT: {{0*}}60 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e948# FULL-NEXT: {{0*}}70 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e949# FULL-NEXT: {{0*}}80 e9 e9 89 ab cd ef50# FULL-NEXT: {{0*}}8651 52## Test gap fill with a decimal value.53# RUN: llvm-objcopy -O binary --gap-fill=99 %t %t-filled-decimal54# RUN: od -v -Ax -t x1 %t-filled-decimal | FileCheck %s --check-prefix=DEC --ignore-case --match-full-lines55# DEC: {{0*}}00 ee ff 11 22 33 44 aa bb cc dd fe dc ba 63 a1 b256# DEC-NEXT: {{0*}}10 c3 d4 63 63 63 63 63 63 63 63 63 63 63 63 63 6357# DEC-NEXT: {{0*}}20 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 6358# DEC-NEXT: {{0*}}30 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 6359# DEC-NEXT: {{0*}}40 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 6360# DEC-NEXT: {{0*}}50 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 6361# DEC-NEXT: {{0*}}60 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 6362# DEC-NEXT: {{0*}}70 63 63 63 63 63 63 63 63 63 63 63 63 63 63 63 6363# DEC-NEXT: {{0*}}80 63 63 89 ab cd ef64# DEC-NEXT: {{0*}}8665 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-filled68# RUN: od -v -Ax -t x1 %t-filled | FileCheck %s --check-prefix=REMOVE-LAST-SECTION --ignore-case --match-full-lines69# REMOVE-LAST-SECTION: {{0*}}00 ee ff 11 22 33 44 aa bb cc dd fe dc ba e9 a1 b270# REMOVE-LAST-SECTION-NEXT: {{0*}}10 c3 d471# REMOVE-LAST-SECTION-NEXT: {{0*}}1272 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-filled75# RUN: od -v -Ax -t x1 %t-filled | FileCheck %s --check-prefix=REMOVE-MIDDLE-SECTION --ignore-case --match-full-lines76# REMOVE-MIDDLE-SECTION: {{0*}}00 ee ff 11 22 33 44 aa bb cc dd fe dc ba e9 e9 e977# REMOVE-MIDDLE-SECTION-NEXT: {{0*}}10 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e978# REMOVE-MIDDLE-SECTION-NEXT: {{0*}}20 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e979# REMOVE-MIDDLE-SECTION-NEXT: {{0*}}30 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e980# REMOVE-MIDDLE-SECTION-NEXT: {{0*}}40 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e981# REMOVE-MIDDLE-SECTION-NEXT: {{0*}}50 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e982# REMOVE-MIDDLE-SECTION-NEXT: {{0*}}60 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e983# REMOVE-MIDDLE-SECTION-NEXT: {{0*}}70 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e9 e984# REMOVE-MIDDLE-SECTION-NEXT: {{0*}}80 e9 e9 89 ab cd ef85# REMOVE-MIDDLE-SECTION-NEXT: {{0*}}8686 87--- !ELF88FileHeader:89 Class: ELFCLASS6490 Data: ELFDATA2LSB91 Type: ET_EXEC92 Machine: EM_X86_6493Sections:94 - Name: .space195 Type: Fill96 Pattern: 'ABCD'97 Size: 0x298 - Name: .nogap99 Type: SHT_PROGBITS100 Flags: [ SHF_ALLOC ]101 Address: 0x0102102 Size: 0x6103 Content: 'EEFF11223344'104 - Name: .gap1105 Type: SHT_PROGBITS106 Flags: [ SHF_ALLOC, SHF_EXECINSTR ]107 Address: 0x0108108 Content: 'AABBCCDDFEDCBA'109 - Name: .zero_size110 Type: SHT_PROGBITS111 Flags: [ SHF_ALLOC ]112 Address: 0x0110113 Size: 0114 - Name: .space2115 Type: Fill116 Pattern: 'DC'117 Size: 1118 - Name: .gap2119 Type: SHT_PROGBITS120 Flags: [ SHF_ALLOC ]121 Address: 0x0110122 Content: 'A1B2C3D4'123 - Name: .space3124 Type: Fill125 Pattern: 'FE'126 Size: 0x1127 - Name: .nobit_tbss128 Type: SHT_NOBITS129 Flags: [ SHF_WRITE, SHF_ALLOC, SHF_TLS ]130 Address: 0x0180131 Size: 0x0018132 - Name: .space4133 Type: Fill134 Pattern: '01234567'135 Size: 0x4136 - Name: .foo137 Type: SHT_PROGBITS138 Flags: [ SHF_WRITE, SHF_ALLOC ]139 Address: 0x0184140 Content: '89ABCDEF'141 - Name: .nobit_bss142 Type: SHT_NOBITS143 Flags: [ SHF_WRITE, SHF_ALLOC ]144 Address: 0x018A145 Size: 0x0008146 - Name: .comment147 Type: SHT_PROGBITS148 Flags: [ SHF_MERGE, SHF_STRINGS ]149 EntSize: 0x0001150 Content: 4743433A151 152## In this test, output sections are defined out of order with respect to their153## load addresses. Verify that gaps are still correctly filled.154 155# RUN: yaml2obj --docnum=2 %s -o %t.2156# RUN: llvm-objcopy -O binary --gap-fill=0xe9 %t.2 %t.2.filled157# RUN: od -v -Ax -t x1 %t.2.filled | FileCheck --ignore-case --match-full-lines %s158# CHECK: {{0*}}00 aa bb cc dd e9 e9 e9 e9 11 22 33 44159 160--- !ELF161FileHeader:162 Class: ELFCLASS64163 Data: ELFDATA2LSB164 Type: ET_EXEC165 Machine: EM_X86_64166Sections:167 - Name: .bss168 Type: SHT_NOBITS169 Flags: [ SHF_ALLOC, SHF_WRITE ]170 Address: 0x0104171 Size: 4172 - Name: .section1173 Type: SHT_PROGBITS174 Flags: [ SHF_ALLOC, SHF_WRITE ]175 Address: 0x0108176 Content: '11223344'177 - Name: .section3178 Type: SHT_PROGBITS179 Flags: [ SHF_ALLOC, SHF_WRITE ]180 Address: 0x0100181 Content: 'AABBCCDD'182