1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
|
## Show that llvm-objcopy adds a new section into the object if
## --add-section is given.
# RUN: yaml2obj --docnum=1 %s -o %t.64bit
# RUN: yaml2obj --docnum=2 %s -o %t.32bit
# RUN: echo -n abcdefg > %t.data
## Error case 1: Nonexistent input file is specified by --add-section.
# RUN: not llvm-objcopy --add-section __TEXT,__text=%t.missing %t.64bit %t.nonexistent-file 2>&1 \
# RUN: | FileCheck %s -DINPUT=%t.64bit -DSECTION_DATA_FILE=%t.missing --check-prefix=NONEXSITENT-FILE
# NONEXSITENT-FILE: error: '[[INPUT]]': '[[SECTION_DATA_FILE]]': {{[Nn]}}o such file or directory
## Error case 2: Too long segment name.
# RUN: not llvm-objcopy --add-section __TOOOOOOOOO_LONG,__text=%t.data %t.64bit %t.too-long-seg-name 2>&1 \
# RUN: | FileCheck %s -DINPUT=%t.64bit --check-prefix=TOO-LONG-SEG-NAME
# TOO-LONG-SEG-NAME: error: '[[INPUT]]': too long segment name: '__TOOOOOOOOO_LONG'
## Case 1: Add a new section into an existing segment.
# RUN: llvm-objcopy --add-section __TEXT,__text=%t.data %t.64bit %t.out1.64bit
# RUN: llvm-objcopy --add-section __TEXT,__text=%t.data %t.32bit %t.out1.32bit
# RUN: llvm-readobj --sections --section-data %t.out1.64bit \
# RUN: | FileCheck %s --check-prefixes=64BIT,COMMON,CASE1
# RUN: llvm-readobj --sections --section-data %t.out1.32bit \
# RUN: | FileCheck %s --check-prefixes=32BIT,COMMON,CASE1
## Case 2: Add a new section into a nonexistent segment.
# RUN: llvm-objcopy --add-section __FOO,__bar=%t.data %t.64bit %t.out2.64bit
# RUN: llvm-objcopy --add-section __FOO,__bar=%t.data %t.32bit %t.out2.32bit
# RUN: llvm-readobj --sections --section-data --macho-segment %t.out2.64bit \
# RUN: | FileCheck %s --check-prefixes=64BIT,COMMON,CASE2,CASE2-64BIT
# RUN: llvm-readobj --sections --section-data --macho-segment %t.out2.32bit \
# RUN: | FileCheck %s --check-prefixes=32BIT,COMMON,CASE2,CASE2-32BIT
## Case 3: Add a new section with /dev/null.
# RUN: llvm-objcopy --add-section __TEXT,__text=/dev/null %t.64bit %t.devnull
# RUN: llvm-readobj --sections --section-data %t.devnull \
# RUN: | FileCheck %s --check-prefixes=64BIT,COMMON,DEVNULL
## 64-bit binary
--- !mach-o
FileHeader:
magic: 0xFEEDFACF
cputype: 0x01000007
cpusubtype: 0x00000003
filetype: 0x00000001
ncmds: 1
sizeofcmds: 152
flags: 0x00002000
reserved: 0x00000000
LoadCommands:
- cmd: LC_SEGMENT_64
cmdsize: 152
segname: ''
vmaddr: 0
vmsize: 4
fileoff: 184
filesize: 4
maxprot: 7
initprot: 7
nsects: 1
flags: 0
Sections:
- sectname: __text
segname: __TEXT
addr: 0x0000000000000000
content: 'AABBCCDD'
size: 4
offset: 184
align: 0
reloff: 0x00000000
nreloc: 0
flags: 0x80000400
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
## 32-bit binary
--- !mach-o
FileHeader:
magic: 0xFEEDFACE
cputype: 0x00000007
cpusubtype: 0x00000003
filetype: 0x00000001
ncmds: 1
sizeofcmds: 124
flags: 0x00002000
LoadCommands:
- cmd: LC_SEGMENT
cmdsize: 124
segname: ''
vmaddr: 0
vmsize: 4
fileoff: 184
filesize: 4
maxprot: 7
initprot: 7
nsects: 1
flags: 0
Sections:
- sectname: __text
segname: __TEXT
addr: 0x0000000000000000
content: 'AABBCCDD'
size: 4
offset: 184
align: 0
reloff: 0x00000000
nreloc: 0
flags: 0x80000400
reserved1: 0x00000000
reserved2: 0x00000000
reserved3: 0x00000000
# COMMON: Index: 0
# COMMON-NEXT: __text (5F 5F 74 65 78 74 00 00 00 00 00 00 00 00 00 00)
# COMMON-NEXT: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
# COMMON: Index: 1
# CASE1-NEXT: __text (5F 5F 74 65 78 74 00 00 00 00 00 00 00 00 00 00)
# CASE1-NEXT: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
# CASE2-NEXT: Name: __bar (5F 5F 62 61 72 00 00 00 00 00 00 00 00 00 00 00)
# CASE2-NEXT: Segment: __FOO (5F 5F 46 4F 4F 00 00 00 00 00 00 00 00 00 00 00)
# DEVNULL-NEXT: __text (5F 5F 74 65 78 74 00 00 00 00 00 00 00 00 00 00)
# DEVNULL-NEXT: Segment: __TEXT (5F 5F 54 45 58 54 00 00 00 00 00 00 00 00 00 00)
# COMMON-NEXT: Address: 0x0
# CASE1-NEXT: Size: 0x7
# CASE2-NEXT: Size: 0x7
# DEVNULL-NEXT: Size: 0x0
# 64BIT-NEXT: Offset: 340
# 32BIT-NEXT: Offset: 280
# COMMON-NEXT: Alignment: 0
# COMMON-NEXT: RelocationOffset: 0x0
# COMMON-NEXT: RelocationCount: 0
# COMMON-NEXT: Type: Regular (0x0)
# COMMON-NEXT: Attributes [ (0x0)
# COMMON-NEXT: ]
# COMMON-NEXT: Reserved1: 0x0
# COMMON-NEXT: Reserved2: 0x0
# 64BIT-NEXT: Reserved3: 0x0
# COMMON-NEXT: SectionData (
# CASE1-NEXT: 0000: 61626364 656667 |abcdefg|
# CASE2-NEXT: 0000: 61626364 656667 |abcdefg|
# COMMON-NEXT: )
# CASE2: Segment {
# CASE2-64BIT-NEXT: Cmd: LC_SEGMENT_64
# CASE2-32BIT-NEXT: Cmd: LC_SEGMENT{{$}}
# CASE2-NEXT: Name:
# CASE2-64BIT-NEXT: Size: 152
# CASE2-32BIT-NEXT: Size: 124
# CASE2-NEXT: vmaddr: 0x0
# CASE2-NEXT: vmsize: 0x4
# CASE2-64BIT-NEXT: fileoff: 336
# CASE2-32BIT-NEXT: fileoff: 276
# CASE2-NEXT: filesize: 4
# CASE2-NEXT: maxprot: rwx
# CASE2-NEXT: initprot: rwx
# CASE2-NEXT: nsects: 1
# CASE2-NEXT: flags: 0x0
# CASE2-NEXT: }
# CASE2-NEXT: Segment {
# CASE2-64BIT-NEXT: Cmd: LC_SEGMENT_64
# CASE2-32BIT-NEXT: Cmd: LC_SEGMENT{{$}}
# CASE2-NEXT: Name: __FOO
# CASE2-64BIT-NEXT: Size: 152
# CASE2-32BIT-NEXT: Size: 124
# CASE2-NEXT: vmaddr: 0x0
# CASE2-NEXT: vmsize: 0x7
# CASE2-64BIT-NEXT: fileoff: 340
# CASE2-32BIT-NEXT: fileoff: 280
# CASE2-NEXT: filesize: 7
# CASE2-NEXT: maxprot: ---
# CASE2-NEXT: initprot: ---
# CASE2-NEXT: nsects: 1
# CASE2-NEXT: flags: 0x0
# CASE2-NEXT: }
|