xref: /llvm-project/llvm/test/tools/llvm-objcopy/COFF/update-section.test (revision 85381e67a9571f6ba27fc7f448b523f6ec2eb312)
1# RUN: echo -n AAAB > %t.diff
2# RUN: echo -n AAA > %t.smaller
3# RUN: echo -n AAAAA > %t.larger
4
5# RUN: yaml2obj %s -o %t
6
7# RUN: llvm-objcopy --update-section=.text=%t.diff %t - | llvm-readobj -S -x .text - | FileCheck %s
8# CHECK:        Section {
9# CHECK-NEXT:     Number: 1
10# CHECK-NEXT:     Name: .text
11# CHECK-NOT:    }
12# CHECK:          RawDataSize: 4
13# CHECK:          Hex dump of section '.text':
14# CHECK-NEXT:     0x00000000 41414142 AAAB
15
16# RUN: llvm-objcopy --update-section=.text=%t.smaller %t - | llvm-readobj -S -x .text - | FileCheck %s --check-prefix=SMALLER
17# SMALLER:      Section {
18# SMALLER-NEXT:   Number: 1
19# SMALLER-NEXT:   Name: .text
20# SMALLER-NOT:  }
21# SMALLER:        RawDataSize: 3
22# SMALLER:        Hex dump of section '.text':
23# SMALLER-NEXT:   0x00000000 414141 AAA
24
25# RUN: llvm-objcopy --update-section=.text=%t.diff --update-section=.other=%t.diff %t - | \
26# RUN:   llvm-readobj -S -x .text -x .other - | FileCheck %s --check-prefix=MULTIPLE
27# MULTIPLE:     Section {
28# MULTIPLE-NEXT:  Number: 1
29# MULTIPLE-NEXT:  Name: .text
30# MULTIPLE-NOT: }
31# MULTIPLE:       RawDataSize: 4
32# MULTIPLE:     Section {
33# MULTIPLE-NEXT:  Number: 2
34# MULTIPLE-NEXT:  Name: .other
35# MULTIPLE-NOT: }
36# MULTIPLE:       RawDataSize: 4
37# MULTIPLE:       Hex dump of section '.text':
38# MULTIPLE-NEXT:  0x00000000 41414142 AAAB
39# MULTIPLE:       Hex dump of section '.other':
40# MULTIPLE-NEXT:  0x00000000 41414142 AAAB
41
42# RUN: not llvm-objcopy --update-section=.text=%t.larger %t /dev/null 2>&1 | FileCheck %s --check-prefix=TOO-LARGE
43# TOO-LARGE: error: {{.*}}new section cannot be larger than previous section
44
45# RUN: not llvm-objcopy --update-section=.bss=%t.diff %t /dev/null 2>&1 | FileCheck %s --check-prefix=NO-CONTENTS
46# NO-CONTENTS: error: {{.*}}section '.bss' cannot be updated because it does not have contents
47
48# RUN: not llvm-objcopy --update-section=.text=%t.noexist %t /dev/null 2>&1 | \
49# RUN:   FileCheck %s --check-prefix=NOENT -DENOENT=%errc_ENOENT
50# NOENT: error: {{.*}}: [[ENOENT]]
51
52# RUN: not llvm-objcopy --update-section=.noexist=%t.diff %t /dev/null 2>&1 | FileCheck %s --check-prefix=NO-SECTION
53# NO-SECTION: error: {{.*}}could not find section with name '.noexist'
54
55--- !COFF
56header:
57  Machine:           IMAGE_FILE_MACHINE_AMD64
58  Characteristics:   [  ]
59sections:
60  - Name:            .text
61    Characteristics: [  ]
62    Alignment:       4
63    SectionData:     '41414141'
64  - Name:            .other
65    Characteristics: [  ]
66    Alignment:       4
67    SectionData:     '42424242'
68  - Name:            .bss
69    Characteristics: [ IMAGE_SCN_CNT_UNINITIALIZED_DATA ]
70    SizeOfRawData:   0
71symbols:
72...
73