• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# RUN: yaml2obj %s -o %t
2
3## Test that llvm-objcopy adds a section to the given object with expected
4## contents.
5# RUN: echo DEADBEEF > %t.sec
6# RUN: llvm-objcopy --add-section=.test.section=%t.sec %t %t1
7# RUN: llvm-readobj --file-headers --sections --section-data %t1 | FileCheck %s --check-prefixes=CHECK-ADD
8
9# CHECK-ADD:      SectionCount: 2
10# CHECK-ADD:      Name: .text
11# CHECK-ADD:      Name: .test.section
12# CHECK-ADD:      Characteristics [
13# CHECK-ADD-NEXT:   IMAGE_SCN_ALIGN_1BYTES
14# CHECK-ADD-NEXT:   IMAGE_SCN_CNT_INITIALIZED_DATA
15# CHECK-ADD-NEXT: ]
16# CHECK-ADD:      SectionData (
17# CHECK-ADD-NEXT:  0000: {{.+}}|DEADBEEF{{.+}}|
18# CHECK-ADD-NEXT: )
19
20## Test that llvm-objcopy can add a section with an empty name.
21# RUN: llvm-objcopy --add-section==%t.sec %t %t1.empty.name
22# RUN: llvm-readobj --file-headers --sections --section-data %t1.empty.name | FileCheck %s --check-prefixes=CHECK-ADD-EMPTY-NAME
23
24# CHECK-ADD-EMPTY-NAME:      SectionCount: 2
25# CHECK-ADD-EMPTY-NAME:      Name: .text
26# CHECK-ADD-EMPTY-NAME:      Name: (00 00 00 00 00 00 00 00)
27# CHECK-ADD-EMPTY-NAME:      Characteristics [
28# CHECK-ADD-EMPTY-NAME-NEXT:   IMAGE_SCN_ALIGN_1BYTES
29# CHECK-ADD-EMPTY-NAME-NEXT:   IMAGE_SCN_CNT_INITIALIZED_DATA
30# CHECK-ADD-EMPTY-NAME-NEXT: ]
31# CHECK-ADD-EMPTY-NAME:      SectionData (
32# CHECK-ADD-EMPTY-NAME-NEXT:  0000: {{.+}}|DEADBEEF{{.+}}|
33# CHECK-ADD-EMPTY-NAME-NEXT: )
34
35## Test that llvm-objcopy can add a section to an object with extended
36## relocations.
37# RUN: %python %p/../Inputs/ungzip.py %p/Inputs/x86_64-obj-xrelocs.yaml.gz > %t.xrelocs.yaml
38# RUN: yaml2obj %t.xrelocs.yaml -o %t.xrelocs.obj
39# RUN: llvm-objcopy --add-section=.test.section=%t.sec %t.xrelocs.obj %t1.xrelocs.obj
40# RUN: llvm-readobj --file-headers --sections --section-data %t1.xrelocs.obj | FileCheck %s --check-prefixes=CHECK-EXTENDED-RELOCS
41
42# CHECK-EXTENDED-RELOCS:      SectionCount: 2
43# CHECK-EXTENDED-RELOCS:      Name: .data
44# CHECK-EXTENDED-RELOCS:      RelocationCount: 65535
45# CHECK-EXTENDED-RELOCS:      Characteristics [
46# CHECK-EXTENDED-RELOCS-NEXT:   IMAGE_SCN_ALIGN_16BYTES
47# CHECK-EXTENDED-RELOCS-NEXT:   IMAGE_SCN_CNT_INITIALIZED_DATA
48# CHECK-EXTENDED-RELOCS-NEXT:   IMAGE_SCN_LNK_NRELOC_OVFL
49# CHECK-EXTENDED-RELOCS-NEXT:   IMAGE_SCN_MEM_READ
50# CHECK-EXTENDED-RELOCS-NEXT: ]
51# CHECK-EXTENDED-RELOCS:      Name: .test.section
52# CHECK-EXTENDED-RELOCS:      Characteristics [
53# CHECK-EXTENDED-RELOCS-NEXT:   IMAGE_SCN_ALIGN_1BYTES
54# CHECK-EXTENDED-RELOCS-NEXT:   IMAGE_SCN_CNT_INITIALIZED_DATA
55# CHECK-EXTENDED-RELOCS-NEXT: ]
56# CHECK-EXTENDED-RELOCS:      SectionData (
57# CHECK-EXTENDED-RELOCS-NEXT:  0000: {{.+}}|DEADBEEF{{.+}}|
58# CHECK-EXTENDED-RELOCS-NEXT: )
59
60## Test that llvm-objcopy produces an error if the file with section contents
61## to be added does not exist.
62# RUN: not llvm-objcopy --add-section=.another.section=%t2 %t %t3 2>&1 | FileCheck -DFILE1=%t -DFILE2=%t2 %s --check-prefixes=ERR1
63
64# ERR1: error: '[[FILE1]]': '[[FILE2]]': {{[Nn]}}o such file or directory
65
66## Another negative test for invalid --add-sections command line argument.
67# RUN: not llvm-objcopy --add-section=.another.section %t %t3 2>&1 | FileCheck %s --check-prefixes=ERR2
68
69# ERR2: error: bad format for --add-section: missing '='
70
71## Negative test for invalid --add-sections argument - missing file name.
72# RUN: not llvm-objcopy --add-section=.section.name= %t %t3 2>&1 | FileCheck %s --check-prefixes=ERR3
73
74# ERR3: error: bad format for --add-section: missing file name
75
76--- !COFF
77header:
78  Machine:         IMAGE_FILE_MACHINE_AMD64
79  Characteristics: [  ]
80sections:
81  - Name:            .text
82    Characteristics: [  ]
83    Alignment:       4
84    SectionData:     488B0500000000C3
85symbols:
86...
87